Skip to content

Commit

Permalink
updated with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev authored and pchampin committed Jul 30, 2024
1 parent 112b8fb commit 05ff337
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 15 additions & 0 deletions api/src/term/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ mod test {
is_graph_name_matcher([Some(T1), Some(T2), None]);
is_graph_name_matcher(&[Some(T1), Some(T2), None][..]);
is_graph_name_matcher(|t: Option<SimpleTerm>| t.is_some());
is_graph_name_matcher(Not(|t: Option<SimpleTerm>| t.is_some()));
is_graph_name_matcher([T1, T2].gn());
is_graph_name_matcher(Some(TermKind::Iri));
is_graph_name_matcher(Some(([T1], [T2], [T3])));
is_graph_name_matcher([Some(T1)].matcher_ref());
is_graph_name_matcher(Not([Some(T1)].matcher_ref()));
}

#[test]
Expand Down Expand Up @@ -177,6 +179,12 @@ mod test {
assert!(TermMatcher::constant(&Any).is_none());
}

#[test]
fn not() {
assert!(Not(TermKind::BlankNode).matches(&T1));
assert!(Not([T1, T2]).matches(&T3));
}

#[test]
fn datatype_matcher() {
let m1 = Any * xsd::string; // testing Mul<NsTerm>
Expand Down Expand Up @@ -332,6 +340,13 @@ mod test {
assert!(GraphNameMatcher::constant(&Any).is_none());
}

#[test]
fn graph_name_not() {
assert!(GraphNameMatcher::matches(&Not([DEFAULT]), Some(&T1)));
assert!(!GraphNameMatcher::matches(&Not([T1, T2].gn()), Some(&T2)));
assert!(GraphNameMatcher::matches(&Not([T1, T2].gn()), Some(&T3)));
}

#[test]
fn graph_name_term_matcher_gn() {
let a1 = [T1].gn();
Expand Down
8 changes: 0 additions & 8 deletions api/src/term/matcher/_graph_name_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,3 @@ impl<M: GraphNameMatcher> GraphNameMatcher for Not<M> {
!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))
}
}

0 comments on commit 05ff337

Please sign in to comment.