Skip to content

Commit

Permalink
Implemented Eq and PartialEq traits for Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Ivanov committed Mar 1, 2024
1 parent a82e90a commit 9f2ac07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,25 @@ where
}
}

#[derive(Yokeable)]
impl<S> PartialEq for Pattern<S> {
fn eq(&self, other: &Self) -> bool {
self.inner.get() == other.inner.get()
}
}
impl<S> Eq for Pattern<S> {}

#[derive(Yokeable, PartialEq, Eq)]
struct PatternInner<'a> {
elements: Vec<PatternElement<'a>>,
}

#[derive(PartialEq, Eq)]
enum PatternElement<'a> {
Substring(&'a str),
Wildcard(Wildcard),
}

#[derive(Copy, Clone, Default)]
#[derive(Copy, Clone, Default, Eq, PartialEq)]
struct Wildcard {
minimum: usize,
is_many: bool,
Expand Down
7 changes: 7 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ fn test_whitespace() {
assert!(!pattern(" ").matches("\t"));
}

#[test]
fn test_eq() {
assert!(pattern("??*ab") == pattern("??*ab"));
assert!(pattern("??*ab") == pattern("?*?ab"));
assert!(pattern("??*abc") != pattern("?*??abc"));
}

#[test]
fn test_issue_3() {
assert!(!pattern("??*?!?").matches("hello!"));
Expand Down

0 comments on commit 9f2ac07

Please sign in to comment.