From 777e1f6ce6497788fd6c44d7ded26dbc8c19f7eb Mon Sep 17 00:00:00 2001 From: Aran Donohue Date: Thu, 16 May 2024 09:00:37 -0700 Subject: [PATCH] Implement PartialEq and Eq in Text --- autosurgeon/src/text.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/autosurgeon/src/text.rs b/autosurgeon/src/text.rs index dcf14c0..04232c5 100644 --- a/autosurgeon/src/text.rs +++ b/autosurgeon/src/text.rs @@ -206,6 +206,14 @@ impl> From for Text { } } +impl std::cmp::PartialEq for Text { + fn eq(&self, other: &Self) -> bool { + self.as_str() == other.as_str() + } +} + +impl std::cmp::Eq for Text {} + #[derive(Clone)] enum State { Fresh(String), @@ -297,4 +305,17 @@ mod tests { let result: Text = hydrate_prop(&doc1, &automerge::ROOT, "text").unwrap(); assert_eq!(result.as_str(), "all that glitters is not gold"); } + + #[test] + fn test_partial_eq() { + let text = Text::with_value("hello"); + assert_eq!(text, Text::with_value("hello")); + assert_ne!(text, Text::with_value("world")); + } + + #[test] + fn test_eq() { + let text: Text = Text::with_value("hello"); + assert_eq!(text, text); + } }