Skip to content

Commit

Permalink
Implement PartialEq and Eq in Text
Browse files Browse the repository at this point in the history
  • Loading branch information
aran authored and alexjg committed Jun 26, 2024
1 parent 842e910 commit 777e1f6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions autosurgeon/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ impl<S: AsRef<str>> From<S> 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),
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 777e1f6

Please sign in to comment.