Skip to content

Commit

Permalink
Update javadoc, add more complex condition tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evie-lau committed Jul 5, 2024
1 parent 8eada43 commit 83ad6d2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**
* Supports a limited set of XPath expressions, specifically those documented on <a
* href="https://www.w3schools.com/xml/xpath_syntax.asp">this page</a>.
* Additionally, supports `local-name()` and `namespace-uri()` conditions, `and`/`or` operators, and chained conditions.
* <p>
* Used for checking whether a visitor's cursor meets a certain XPath expression.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,21 @@ void matchConditionsWithConjunctions() {
assertThat(match("//*[local-name()='dne' or local-name()='dne2']", namespacedXml)).isFalse();

assertThat(match("//@*[namespace-uri()='dne' or namespace-uri()='http://www.example.com/namespace3']", namespacedXml)).isTrue();

// T&T&T = T
assertThat(match("//*[local-name()='element4' and namespace-uri()='http://www.example.com/namespace2' and @ns3:attr='test2']", namespacedXml)).isTrue();
// T&T&F = F
assertThat(match("//*[local-name()='element4' and namespace-uri()='http://www.example.com/namespace2' and @ns3:attr='dne']", namespacedXml)).isFalse();
// T&T|F = T
assertThat(match("//*[local-name()='element4' and namespace-uri()='http://www.example.com/namespace2' or @ns3:attr='dne']", namespacedXml)).isTrue();
// T&F|T = T
assertThat(match("//*[local-name()='element4' and @ns3:attr='dne' or namespace-uri()='http://www.example.com/namespace2']", namespacedXml)).isTrue();
// T&F|F = F
assertThat(match("//*[local-name()='element4' and @ns3:attr='dne' or namespace-uri()='http://www.example.com/namespaceX']", namespacedXml)).isFalse();

// F|F|T = T
assertThat(match("//*[local-name()='dne' or local-name()='dne2' or local-name()='element2']", namespacedXml)).isTrue();

// [T&T][T] = T
assertThat(match("//*[local-name()='element4' and namespace-uri()='http://www.example.com/namespace2'][@ns3:attr='test2']", namespacedXml)).isTrue();
// [T&T][F] = F
Expand All @@ -375,6 +390,18 @@ void matchConditionsWithConjunctions() {
assertThat(match("//*[local-name()='dne' or local-name()='element4'][namespace-uri()='http://www.example.com/namespace2']", namespacedXml)).isTrue();
// [F|T][F] = F
assertThat(match("//*[local-name()='dne' or local-name()='element4'][namespace-uri()='http://www.example.com/namespaceX']", namespacedXml)).isFalse();

// F|T&T = T
assertThat(match("//*[local-name()='dne' or local-name()='element4' and namespace-uri()='http://www.example.com/namespace2']", namespacedXml)).isTrue();
// F|T&F = F
assertThat(match("//*[local-name()='dne' or local-name()='element4' and namespace-uri()='http://www.example.com/namespaceX']", namespacedXml)).isFalse();
// F|F&T = F
assertThat(match("//*[local-name()='dne' or namespace-uri()='http://www.example.com/namespaceX' and local-name()='element4']", namespacedXml)).isFalse();

// T|F & T = T
assertThat(match("//*[local-name()='element4' or local-name()='dne' and namespace-uri()='http://www.example.com/namespace2']", namespacedXml)).isTrue();
// T|F & F = T
assertThat(match("//*[local-name()='element4' or local-name()='dne' and namespace-uri()='http://www.example.com/namespaceX']", namespacedXml)).isTrue();
}

private boolean match(String xpath, SourceFile x) {
Expand Down

0 comments on commit 83ad6d2

Please sign in to comment.