Skip to content

Commit

Permalink
Enable the namespace match functions test separately
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jul 8, 2024
1 parent 83ad6d2 commit 4834210
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
*/
public class XPathMatcher {

private static final Pattern XPATH_ELEMENT_SPLITTER = Pattern.compile("((?<=/)(?=/)|[^/\\[]|\\[[^]]*\\])+");
private static final Pattern XPATH_ELEMENT_SPLITTER = Pattern.compile("((?<=/)(?=/)|[^/\\[]|\\[[^]]*])+");
// Regular expression to support conditional tags like `plugin[artifactId='maven-compiler-plugin']` or foo[@bar='baz']
private static final Pattern ELEMENT_WITH_CONDITION_PATTERN = Pattern.compile("(@)?([-:\\w]+|\\*)(\\[.+\\])");
private static final Pattern CONDITION_PATTERN = Pattern.compile("(\\[.*?\\])+?");
private static final Pattern ELEMENT_WITH_CONDITION_PATTERN = Pattern.compile("(@)?([-:\\w]+|\\*)(\\[.+])");
private static final Pattern CONDITION_PATTERN = Pattern.compile("(\\[.*?])+?");
private static final Pattern CONDITION_CONJUNCTION_PATTERN = Pattern.compile("(((local-name|namespace-uri)\\(\\)|(@)?([-\\w:]+|\\*))='(.*?)'(\\h?(or|and)\\h?)?)+?");

private final String expression;
Expand Down
25 changes: 14 additions & 11 deletions rewrite-xml/src/test/java/org/openrewrite/xml/XPathMatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ void relativePathsWithConditions() {
}

@Test
@Disabled
@Issue("https://github.com/openrewrite/rewrite/issues/3919")
void matchFunctions() {
void namespaceMatchFunctions() {
assertThat(match("/root/element1", namespacedXml)).isTrue();
assertThat(match("/root/ns2:element2", namespacedXml)).isTrue();
assertThat(match("/root/dne", namespacedXml)).isFalse();
Expand All @@ -244,17 +243,21 @@ void matchFunctions() {
assertThat(match("/*[namespace-uri()='http://www.example.com/namespace2']", namespacedXml)).isFalse();
assertThat(match("//*[namespace-uri()='http://www.example.com/namespace2']", namespacedXml)).isTrue();
assertThat(match("//@*[namespace-uri()='http://www.example.com/namespace3']", namespacedXml)).isTrue();
}

@Test
@Disabled
void otherUncoveredXpathFunctions() {
// Other common XPath functions
assertThat(match("contains(/root/element1, 'content1')", namespacedXml)).isTrue();
assertThat(match("not(contains(/root/element1, 'content1'))", namespacedXml)).isFalse();
assertThat(match("string-length(/root/element1) > 2", namespacedXml)).isTrue();
assertThat(match("starts-with(/root/element1, 'content1')", namespacedXml)).isTrue();
assertThat(match("ends-with(/root/element1, 'content1')", namespacedXml)).isTrue();
assertThat(match("substring-before(/root/element1, '1') = 'content'", namespacedXml)).isTrue();
assertThat(match("substring-after(/root/element1, 'content') = '1'", namespacedXml)).isTrue();
assertThat(match("/root/element1/text()", namespacedXml)).isTrue();
assertThat(match("count(/root/*)", namespacedXml)).isTrue();
assertThat(match("contains(/root/element1, 'content1')", namespacedXml)).isTrue();
assertThat(match("not(contains(/root/element1, 'content1'))", namespacedXml)).isFalse();
assertThat(match("string-length(/root/element1) > 2", namespacedXml)).isTrue();
assertThat(match("starts-with(/root/element1, 'content1')", namespacedXml)).isTrue();
assertThat(match("ends-with(/root/element1, 'content1')", namespacedXml)).isTrue();
assertThat(match("substring-before(/root/element1, '1') = 'content'", namespacedXml)).isTrue();
assertThat(match("substring-after(/root/element1, 'content') = '1'", namespacedXml)).isTrue();
assertThat(match("/root/element1/text()", namespacedXml)).isTrue();
assertThat(match("count(/root/*)", namespacedXml)).isTrue();
}

@Test
Expand Down

0 comments on commit 4834210

Please sign in to comment.