Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Not for GraphNameMatcher and TermMatcher #174

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/src/term/matcher/_any.rs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If unit tests are needed, I'd like to know what module they should go under.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all tests for (GraphName|Term)Matcher are currently in api/src/term/matcher.rs. Having tests for Not would indeed be nice.

Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ impl TermMatcher for Any {
true
}
}

/// Matches on the inverse of the inner [`Term`] or [`GraphName`]
pub struct Not<M>(pub M);

impl<M: TermMatcher> TermMatcher for Not<M> {
type Term = SimpleTerm<'static>; // not actually used

fn matches<T2: Term + ?Sized>(&self, term: &T2) -> bool {
!self.0.matches(term)
}
}
mkatychev marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions api/src/term/matcher/_graph_name_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,19 @@ impl GraphNameMatcher for Any {
true
}
}

impl<M: GraphNameMatcher> GraphNameMatcher for Not<M> {
type Term = SimpleTerm<'static>; // not actually used

fn matches<T2: Term + ?Sized>(&self, graph_name: GraphName<&T2>) -> bool {
!self.0.matches(graph_name)
}
}

impl GraphNameMatcher for Option<SimpleTerm<'static>> {
type Term = SimpleTerm<'static>;

fn matches<T2: Term + ?Sized>(&self, graph_name: GraphName<&T2>) -> bool {
graph_name_eq(self.as_ref(), graph_name.map(Term::as_simple))
}
}
mkatychev marked this conversation as resolved.
Show resolved Hide resolved