Issue: SPR-14544
This commit is contained in:
Brian Clozel
2017-02-08 13:58:23 +01:00
parent f786feb5e1
commit a4da313a0a
19 changed files with 600 additions and 465 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.util.patterns;
import java.util.ArrayList;
@@ -31,7 +32,7 @@ import static org.junit.Assert.*;
/**
* Exercise matching of {@link PathPattern} objects.
*
*
* @author Andy Clement
*/
public class PathPatternMatcherTests {
@@ -58,7 +59,7 @@ public class PathPatternMatcherTests {
checkMatches("/foo/bar", "/foo/bar");
checkNoMatch("/foo/bar", "/foo/baz");
// TODO Need more tests for escaped separators in path patterns and paths?
checkMatches("/foo\\/bar","/foo\\/bar"); // chain string is Separator(/) Literal(foo\) Separator(/) Literal(bar)
checkMatches("/foo\\/bar", "/foo\\/bar"); // chain string is Separator(/) Literal(foo\) Separator(/) Literal(bar)
}
@Test
@@ -97,27 +98,27 @@ public class PathPatternMatcherTests {
@Test
public void multipleSelectorsInPattern() {
checkMatches("///abc","/abc");
checkMatches("//","/");
checkMatches("abc","abc");
checkMatches("///abc//d/e","/abc/d/e");
checkMatches("///abc//{def}//////xyz","/abc/foo/xyz");
checkMatches("///abc", "/abc");
checkMatches("//", "/");
checkMatches("abc", "abc");
checkMatches("///abc//d/e", "/abc/d/e");
checkMatches("///abc//{def}//////xyz", "/abc/foo/xyz");
}
@Test
public void multipleSelectorsInPath() {
checkMatches("/abc","////abc");
checkMatches("/","//");
checkMatches("/abc//def///ghi","/abc/def/ghi");
checkMatches("/abc", "////abc");
checkMatches("/", "//");
checkMatches("/abc//def///ghi", "/abc/def/ghi");
}
@Test
public void multipleSelectorsInPatternAndPath() {
checkMatches("///one///two///three","//one/////two///////three");
checkMatches("//one//two//three","/one/////two/three");
checkCapture("///{foo}///bar","/one/bar","foo","one");
checkMatches("///one///two///three", "//one/////two///////three");
checkMatches("//one//two//three", "/one/////two/three");
checkCapture("///{foo}///bar", "/one/bar", "foo", "one");
}
@Test
public void wildcards() {
checkMatches("/*/bar", "/foo/bar");
@@ -126,10 +127,10 @@ public class PathPatternMatcherTests {
checkMatches("/*/bar", "/foo/bar");
checkMatches("/a*b*c*d/bar", "/abcd/bar");
checkMatches("*a*", "testa");
checkMatches("a/*","a/");
checkMatches("a/*","a/a");
checkNoMatch("a/*","a/a/");
checkMatches("a/*", "a/");
checkMatches("a/*", "a/a");
checkNoMatch("a/*", "a/a/");
checkMatches("/resource/**", "/resource");
checkNoMatch("/resource/**", "/resourceX");
checkNoMatch("/resource/**", "/resourceX/foobar");
@@ -140,19 +141,19 @@ public class PathPatternMatcherTests {
public void trailingSeparators() {
checkNoMatch("aaa/", "aaa");
}
@Test
public void constrainedMatches() {
checkCapture("{foo:[0-9]*}", "123", "foo", "123");
checkNoMatch("{foo:[0-9]*}", "abc");
checkNoMatch("/{foo:[0-9]*}", "abc");
checkCapture("/*/{foo:....}/**","/foo/barg/foo","foo","barg");
checkCapture("/*/{foo:....}/**","/foo/barg/abc/def/ghi","foo","barg");
checkCapture("/*/{foo:....}/**", "/foo/barg/foo", "foo", "barg");
checkCapture("/*/{foo:....}/**", "/foo/barg/abc/def/ghi", "foo", "barg");
checkNoMatch("{foo:....}", "99");
checkMatches("{foo:..}", "99");
checkCapture("/{abc:\\{\\}}","/{}","abc","{}");
checkCapture("/{abc:\\[\\]}","/[]","abc","[]");
checkCapture("/{abc:\\\\\\\\}","/\\\\"); // this is fun...
checkCapture("/{abc:\\{\\}}", "/{}", "abc", "{}");
checkCapture("/{abc:\\[\\]}", "/[]", "abc", "[]");
checkCapture("/{abc:\\\\\\\\}", "/\\\\"); // this is fun...
}
@Test
@@ -301,20 +302,20 @@ public class PathPatternMatcherTests {
checkStartNoMatch("/????", "/bala/bla");
checkStartMatches("/*bla*/*/bla/**",
"/XXXblaXXXX/testing/bla/testing/testing/");
"/XXXblaXXXX/testing/bla/testing/testing/");
checkStartMatches("/*bla*/*/bla/*",
"/XXXblaXXXX/testing/bla/testing");
"/XXXblaXXXX/testing/bla/testing");
checkStartMatches("/*bla*/*/bla/**",
"/XXXblaXXXX/testing/bla/testing/testing");
"/XXXblaXXXX/testing/bla/testing/testing");
checkStartMatches("/*bla*/*/bla/**",
"/XXXblaXXXX/testing/bla/testing/testing.jpg");
"/XXXblaXXXX/testing/bla/testing/testing.jpg");
checkStartMatches("/abc/{foo}", "/abc/def");
checkStartNoMatch("/abc/{foo}", "/abc/def/");
checkStartMatches("/abc/{foo}/", "/abc/def/");
checkStartNoMatch("/abc/{foo}/", "/abc/def/ghi");
checkStartMatches("/abc/{foo}/", "/abc/def");
checkStartMatches("/abc/{foo}","/abc/def");
checkStartNoMatch("/abc/{foo}","/abc/def/");
checkStartMatches("/abc/{foo}/","/abc/def/");
checkStartNoMatch("/abc/{foo}/","/abc/def/ghi");
checkStartMatches("/abc/{foo}/","/abc/def");
checkStartMatches("", "");
checkStartMatches("", null);
checkStartMatches("/abc", null);
@@ -465,29 +466,29 @@ public class PathPatternMatcherTests {
separator = PathPatternParser.DEFAULT_SEPARATOR;
}
}
@Test
public void extractPathWithinPattern() throws Exception {
checkExtractPathWithinPattern("/welcome*/", "/welcome/","welcome");
checkExtractPathWithinPattern("/docs/commit.html","/docs/commit.html","");
checkExtractPathWithinPattern("/docs/*","/docs/cvs/commit","cvs/commit");
checkExtractPathWithinPattern("/docs/cvs/*.html","/docs/cvs/commit.html","commit.html");
checkExtractPathWithinPattern("/docs/**","/docs/cvs/commit","cvs/commit");
checkExtractPathWithinPattern("/doo/{*foobar}","/doo/customer.html","customer.html");
checkExtractPathWithinPattern("/doo/{*foobar}","/doo/daa/customer.html","daa/customer.html");
checkExtractPathWithinPattern("/*.html","/commit.html","commit.html");
checkExtractPathWithinPattern("/docs/*/*/*/*","/docs/cvs/other/commit.html","cvs/other/commit.html");
checkExtractPathWithinPattern("/d?cs/**","/docs/cvs/commit","docs/cvs/commit");
checkExtractPathWithinPattern("/docs/c?s/*.html","/docs/cvs/commit.html","cvs/commit.html");
checkExtractPathWithinPattern("/d?cs/*/*.html","/docs/cvs/commit.html","docs/cvs/commit.html");
checkExtractPathWithinPattern("/a/b/c*d*/*.html","/a/b/cod/foo.html","cod/foo.html");
checkExtractPathWithinPattern("a/{foo}/b/{bar}","a/c/b/d","c/b/d");
checkExtractPathWithinPattern("a/{foo}_{bar}/d/e","a/b_c/d/e","b_c/d/e");
checkExtractPathWithinPattern("aaa//*///ccc///ddd","aaa/bbb/ccc/ddd","bbb/ccc/ddd");
checkExtractPathWithinPattern("aaa/*/ccc/ddd","aaa//bbb//ccc/ddd","bbb/ccc/ddd");
checkExtractPathWithinPattern("aaa//*///ccc///ddd","aaa//bbb//ccc/ddd","bbb/ccc/ddd");
checkExtractPathWithinPattern("aaa//*///ccc///ddd","aaa/////bbb//ccc/ddd","bbb/ccc/ddd");
checkExtractPathWithinPattern("aaa/c*/ddd/","aaa/ccc///ddd///","ccc/ddd");
checkExtractPathWithinPattern("/welcome*/", "/welcome/", "welcome");
checkExtractPathWithinPattern("/docs/commit.html", "/docs/commit.html", "");
checkExtractPathWithinPattern("/docs/*", "/docs/cvs/commit", "cvs/commit");
checkExtractPathWithinPattern("/docs/cvs/*.html", "/docs/cvs/commit.html", "commit.html");
checkExtractPathWithinPattern("/docs/**", "/docs/cvs/commit", "cvs/commit");
checkExtractPathWithinPattern("/doo/{*foobar}", "/doo/customer.html", "customer.html");
checkExtractPathWithinPattern("/doo/{*foobar}", "/doo/daa/customer.html", "daa/customer.html");
checkExtractPathWithinPattern("/*.html", "/commit.html", "commit.html");
checkExtractPathWithinPattern("/docs/*/*/*/*", "/docs/cvs/other/commit.html", "cvs/other/commit.html");
checkExtractPathWithinPattern("/d?cs/**", "/docs/cvs/commit", "docs/cvs/commit");
checkExtractPathWithinPattern("/docs/c?s/*.html", "/docs/cvs/commit.html", "cvs/commit.html");
checkExtractPathWithinPattern("/d?cs/*/*.html", "/docs/cvs/commit.html", "docs/cvs/commit.html");
checkExtractPathWithinPattern("/a/b/c*d*/*.html", "/a/b/cod/foo.html", "cod/foo.html");
checkExtractPathWithinPattern("a/{foo}/b/{bar}", "a/c/b/d", "c/b/d");
checkExtractPathWithinPattern("a/{foo}_{bar}/d/e", "a/b_c/d/e", "b_c/d/e");
checkExtractPathWithinPattern("aaa//*///ccc///ddd", "aaa/bbb/ccc/ddd", "bbb/ccc/ddd");
checkExtractPathWithinPattern("aaa/*/ccc/ddd", "aaa//bbb//ccc/ddd", "bbb/ccc/ddd");
checkExtractPathWithinPattern("aaa//*///ccc///ddd", "aaa//bbb//ccc/ddd", "bbb/ccc/ddd");
checkExtractPathWithinPattern("aaa//*///ccc///ddd", "aaa/////bbb//ccc/ddd", "bbb/ccc/ddd");
checkExtractPathWithinPattern("aaa/c*/ddd/", "aaa/ccc///ddd///", "ccc/ddd");
checkExtractPathWithinPattern("", "", "");
checkExtractPathWithinPattern("/", "", "");
checkExtractPathWithinPattern("", "/", "");
@@ -500,27 +501,29 @@ public class PathPatternMatcherTests {
@Test
public void extractUriTemplateVariables() throws Exception {
checkCapture("/hotels/{hotel}", "/hotels/1", "hotel","1");
checkCapture("/h?tels/{hotel}","/hotels/1","hotel","1");
checkCapture("/hotels/{hotel}/bookings/{booking}","/hotels/1/bookings/2","hotel","1","booking","2");
checkCapture("/*/hotels/*/{hotel}","/foo/hotels/bar/1","hotel","1");
checkCapture("/{page}.html","/42.html","page","42");
checkCapture("/{page}.*","/42.html","page","42");
checkCapture("/A-{B}-C","/A-b-C","B","b");
checkCapture("/{name}.{extension}","/test.html","name","test","extension","html");
checkCapture("/hotels/{hotel}", "/hotels/1", "hotel", "1");
checkCapture("/h?tels/{hotel}", "/hotels/1", "hotel", "1");
checkCapture("/hotels/{hotel}/bookings/{booking}", "/hotels/1/bookings/2", "hotel", "1", "booking", "2");
checkCapture("/*/hotels/*/{hotel}", "/foo/hotels/bar/1", "hotel", "1");
checkCapture("/{page}.html", "/42.html", "page", "42");
checkCapture("/{page}.*", "/42.html", "page", "42");
checkCapture("/A-{B}-C", "/A-b-C", "B", "b");
checkCapture("/{name}.{extension}", "/test.html", "name", "test", "extension", "html");
try {
checkCapture("/{one}/", "//", "one", "");
fail("Expected exception");
} catch (IllegalStateException e) {
assertEquals("Pattern \"/{one}/\" is not a match for \"//\"",e.getMessage());
}
catch (IllegalStateException e) {
assertEquals("Pattern \"/{one}/\" is not a match for \"//\"", e.getMessage());
}
try {
checkCapture("", "/abc");
fail("Expected exception");
} catch (IllegalStateException e) {
assertEquals("Pattern \"\" is not a match for \"/abc\"",e.getMessage());
}
assertEquals(0,checkCapture("", "").size());
catch (IllegalStateException e) {
assertEquals("Pattern \"\" is not a match for \"/abc\"", e.getMessage());
}
assertEquals(0, checkCapture("", "").size());
checkCapture("{id}", "99", "id", "99");
checkCapture("/customer/{customerId}", "/customer/78", "customerId", "78");
checkCapture("/customer/{customerId}/banana", "/customer/42/banana", "customerId",
@@ -529,8 +532,8 @@ public class PathPatternMatcherTests {
checkCapture("/foo/{bar}/boo/{baz}", "/foo/plum/boo/apple", "bar", "plum", "baz",
"apple");
checkCapture("/{bla}.*", "/testing.html", "bla", "testing");
Map<String,String> extracted = checkCapture("/abc","/abc");
assertEquals(0,extracted.size());
Map<String, String> extracted = checkCapture("/abc", "/abc");
assertEquals(0, extracted.size());
}
@Test
@@ -565,7 +568,7 @@ public class PathPatternMatcherTests {
assertEquals("2010", result.get("year"));
assertEquals("02", result.get("month"));
assertEquals("20", result.get("day"));
p = pp.parse("{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.\\{\\}]+}.jar");
result = p.matchAndExtract("com.example-sources-1.0.0.{12}.jar");
assertEquals("com.example", result.get("symbolicName"));
@@ -580,7 +583,7 @@ public class PathPatternMatcherTests {
exception.expectMessage(containsString("The number of capturing groups in the pattern"));
pathMatcher.matchAndExtract("/web/foobar_goo");
}
@Rule
public final ExpectedException exception = ExpectedException.none();
@@ -619,14 +622,14 @@ public class PathPatternMatcherTests {
// SPR-10554
assertEquals("/hotel", pathMatcher.combine("/", "/hotel")); // SPR-12975
assertEquals("/hotel/booking", pathMatcher.combine("/hotel/", "/booking")); // SPR-12975
assertEquals("",pathMatcher.combine(null, null));
assertEquals("",pathMatcher.combine(null, ""));
assertEquals("",pathMatcher.combine("",null));
assertEquals("",pathMatcher.combine(null, null));
assertEquals("",pathMatcher.combine("", ""));
assertEquals("/hotel",pathMatcher.combine("", "/hotel"));
assertEquals("/hotel",pathMatcher.combine("/hotel", null));
assertEquals("/hotel",pathMatcher.combine("/hotel", ""));
assertEquals("", pathMatcher.combine(null, null));
assertEquals("", pathMatcher.combine(null, ""));
assertEquals("", pathMatcher.combine("", null));
assertEquals("", pathMatcher.combine(null, null));
assertEquals("", pathMatcher.combine("", ""));
assertEquals("/hotel", pathMatcher.combine("", "/hotel"));
assertEquals("/hotel", pathMatcher.combine("/hotel", null));
assertEquals("/hotel", pathMatcher.combine("/hotel", ""));
// TODO Do we need special handling when patterns contain multiple dots?
}
@@ -703,21 +706,21 @@ public class PathPatternMatcherTests {
assertEquals(-1, comparator.compare(parse("*"), parse("*/**")));
assertEquals(1, comparator.compare(parse("*/**"), parse("*")));
}
@Test
public void pathPatternComparator() {
PathPatternComparator ppc = new PathPatternComparator();
assertEquals(0,ppc.compare(null, null));
assertEquals(1,ppc.compare(null, parse("")));
assertEquals(-1,ppc.compare(parse(""), null));
assertEquals(0,ppc.compare(parse(""), parse("")));
assertEquals(0, ppc.compare(null, null));
assertEquals(1, ppc.compare(null, parse("")));
assertEquals(-1, ppc.compare(parse(""), null));
assertEquals(0, ppc.compare(parse(""), parse("")));
}
@Test
public void patternCompareTo() {
PathPatternParser p = new PathPatternParser();
PathPattern pp = p.parse("/abc");
assertEquals(-1,pp.compareTo(null));
assertEquals(-1, pp.compareTo(null));
}
@Test
@@ -816,7 +819,7 @@ public class PathPatternMatcherTests {
assertEquals("/*/login.*", paths.get(1).getPatternString());
paths.clear();
}
@Test // SPR-13286
public void caseInsensitive() {
PathPatternParser pp = new PathPatternParser();
@@ -831,12 +834,12 @@ public class PathPatternMatcherTests {
public void patternmessage() {
PatternMessage[] values = PatternMessage.values();
assertNotNull(values);
for (PatternMessage pm: values) {
for (PatternMessage pm : values) {
String name = pm.toString();
assertEquals(pm.ordinal(),PatternMessage.valueOf(name).ordinal());
assertEquals(pm.ordinal(), PatternMessage.valueOf(name).ordinal());
}
}
private PathPattern parse(String path) {
PathPatternParser pp = new PathPatternParser();
return pp.parse(path);
@@ -869,7 +872,7 @@ public class PathPatternMatcherTests {
assertFalse(pattern.matches(path));
}
private Map<String,String> checkCapture(String uriTemplate, String path, String... keyValues) {
private Map<String, String> checkCapture(String uriTemplate, String path, String... keyValues) {
PathPatternParser parser = new PathPatternParser();
PathPattern pattern = parser.parse(uriTemplate);
Map<String, String> matchResults = pattern.matchAndExtract(path);
@@ -898,7 +901,7 @@ public class PathPatternMatcherTests {
PathPatternParser ppp = new PathPatternParser();
PathPattern pp = ppp.parse(pattern);
String s = pp.extractPathWithinPattern(path);
assertEquals(expected,s);
assertEquals(expected, s);
}
static class TestPathCombiner {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.util.patterns;
import java.util.ArrayList;
@@ -26,13 +27,13 @@ import static org.junit.Assert.*;
/**
* Exercise the {@link PathPatternParser}.
*
*
* @author Andy Clement
*/
public class PathPatternParserTests {
private PathPattern p;
@Test
public void basicPatterns() {
checkStructure("/");
@@ -42,23 +43,23 @@ public class PathPatternParserTests {
checkStructure("/foo/");
checkStructure("//");
}
@Test
public void singleCharWildcardPatterns() {
p = checkStructure("?");
assertPathElements(p , SingleCharWildcardedPathElement.class);
assertPathElements(p, SingleCharWildcardedPathElement.class);
checkStructure("/?/");
checkStructure("//?abc?/");
}
@Test
public void multiwildcardPattern() {
p = checkStructure("/**");
assertPathElements(p,WildcardTheRestPathElement.class);
assertPathElements(p, WildcardTheRestPathElement.class);
p = checkStructure("/**acb"); // this is not double wildcard use, it is / then **acb (an odd, unnecessary use of double *)
assertPathElements(p,SeparatorPathElement.class, RegexPathElement.class);
assertPathElements(p, SeparatorPathElement.class, RegexPathElement.class);
}
@Test
public void toStringTests() {
assertEquals("CaptureTheRest(/{*foobar})", checkStructure("/{*foobar}").toChainString());
@@ -70,7 +71,7 @@ public class PathPatternParserTests {
assertEquals("Wildcard(*)", checkStructure("*").toChainString());
assertEquals("WildcardTheRest(/**)", checkStructure("/**").toChainString());
}
@Test
public void captureTheRestPatterns() {
checkError("/{*foobar}x{abc}", 10, PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
@@ -81,13 +82,13 @@ public class PathPatternParserTests {
checkError("/{*foobar}/", 10, PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
checkError("/{*foobar}abc", 10, PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
checkError("/{*f%obar}", 4, PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR);
checkError("/{*foobar}abc",10,PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
checkError("/{f*oobar}",3,PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR);
checkError("/{*foobar}/abc",10,PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
checkError("/{abc}{*foobar}",1,PatternMessage.CAPTURE_ALL_IS_STANDALONE_CONSTRUCT);
checkError("/{abc}{*foobar}{foo}",15,PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
checkError("/{*foobar}abc", 10, PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
checkError("/{f*oobar}", 3, PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR);
checkError("/{*foobar}/abc", 10, PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
checkError("/{abc}{*foobar}", 1, PatternMessage.CAPTURE_ALL_IS_STANDALONE_CONSTRUCT);
checkError("/{abc}{*foobar}{foo}", 15, PatternMessage.NO_MORE_DATA_EXPECTED_AFTER_CAPTURE_THE_REST);
}
@Test
public void equalsAndHashcode() {
PathPatternParser caseInsensitiveParser = new PathPatternParser();
@@ -96,23 +97,23 @@ public class PathPatternParserTests {
PathPattern pp1 = caseInsensitiveParser.parse("/abc");
PathPattern pp2 = caseInsensitiveParser.parse("/abc");
PathPattern pp3 = caseInsensitiveParser.parse("/def");
assertEquals(pp1,pp2);
assertEquals(pp1.hashCode(),pp2.hashCode());
assertEquals(pp1, pp2);
assertEquals(pp1.hashCode(), pp2.hashCode());
assertNotEquals(pp1, pp3);
assertFalse(pp1.equals("abc"));
pp1 = caseInsensitiveParser.parse("/abc");
pp2 = caseSensitiveParser.parse("/abc");
assertFalse(pp1.equals(pp2));
assertNotEquals(pp1.hashCode(),pp2.hashCode());
assertNotEquals(pp1.hashCode(), pp2.hashCode());
PathPatternParser alternateSeparatorParser = new PathPatternParser(':');
pp1 = caseInsensitiveParser.parse("abc");
pp2 = alternateSeparatorParser.parse("abc");
assertFalse(pp1.equals(pp2));
assertNotEquals(pp1.hashCode(),pp2.hashCode());
assertNotEquals(pp1.hashCode(), pp2.hashCode());
}
@Test
public void regexPathElementPatterns() {
checkError("/{var:[^/]*}", 8, PatternMessage.MISSING_CLOSE_CAPTURE);
@@ -120,78 +121,77 @@ public class PathPatternParserTests {
checkError("/{var:a{{1,2}}}", 6, PatternMessage.JDK_PATTERN_SYNTAX_EXCEPTION);
p = checkStructure("/{var:\\\\}");
assertEquals(CaptureVariablePathElement.class.getName(),p.getHeadSection().next.getClass().getName());
assertEquals(CaptureVariablePathElement.class.getName(), p.getHeadSection().next.getClass().getName());
assertTrue(p.matches("/\\"));
p = checkStructure("/{var:\\/}");
assertEquals(CaptureVariablePathElement.class.getName(),p.getHeadSection().next.getClass().getName());
assertFalse(p.matches("/aaa"));
p = checkStructure("/{var:a{1,2}}",1);
assertEquals(CaptureVariablePathElement.class.getName(),p.getHeadSection().next.getClass().getName());
p = checkStructure("/{var:[^\\/]*}",1);
assertEquals(CaptureVariablePathElement.class.getName(),p.getHeadSection().next.getClass().getName());
assertEquals(CaptureVariablePathElement.class.getName(), p.getHeadSection().next.getClass().getName());
assertFalse(p.matches("/aaa"));
p = checkStructure("/{var:a{1,2}}", 1);
assertEquals(CaptureVariablePathElement.class.getName(), p.getHeadSection().next.getClass().getName());
p = checkStructure("/{var:[^\\/]*}", 1);
assertEquals(CaptureVariablePathElement.class.getName(), p.getHeadSection().next.getClass().getName());
Map<String, String> result = p.matchAndExtract("/foo");
assertEquals("foo",result.get("var"));
assertEquals("foo", result.get("var"));
p = checkStructure("/{var:\\[*}",1);
assertEquals(CaptureVariablePathElement.class.getName(),p.getHeadSection().next.getClass().getName());
p = checkStructure("/{var:\\[*}", 1);
assertEquals(CaptureVariablePathElement.class.getName(), p.getHeadSection().next.getClass().getName());
result = p.matchAndExtract("/[[[");
assertEquals("[[[",result.get("var"));
assertEquals("[[[", result.get("var"));
p = checkStructure("/{var:[\\{]*}",1);
assertEquals(CaptureVariablePathElement.class.getName(),p.getHeadSection().next.getClass().getName());
p = checkStructure("/{var:[\\{]*}", 1);
assertEquals(CaptureVariablePathElement.class.getName(), p.getHeadSection().next.getClass().getName());
result = p.matchAndExtract("/{{{");
assertEquals("{{{",result.get("var"));
assertEquals("{{{", result.get("var"));
p = checkStructure("/{var:[\\}]*}",1);
assertEquals(CaptureVariablePathElement.class.getName(),p.getHeadSection().next.getClass().getName());
p = checkStructure("/{var:[\\}]*}", 1);
assertEquals(CaptureVariablePathElement.class.getName(), p.getHeadSection().next.getClass().getName());
result = p.matchAndExtract("/}}}");
assertEquals("}}}",result.get("var"));
assertEquals("}}}", result.get("var"));
p = checkStructure("*");
assertEquals(WildcardPathElement.class.getName(),p.getHeadSection().getClass().getName());
assertEquals(WildcardPathElement.class.getName(), p.getHeadSection().getClass().getName());
checkStructure("/*");
checkStructure("/*/");
checkStructure("*/");
checkStructure("/*/");
p = checkStructure("/*a*/");
assertEquals(RegexPathElement.class.getName(),p.getHeadSection().next.getClass().getName());
assertEquals(RegexPathElement.class.getName(), p.getHeadSection().next.getClass().getName());
p = checkStructure("*/");
assertEquals(WildcardPathElement.class.getName(),p.getHeadSection().getClass().getName());
assertEquals(WildcardPathElement.class.getName(), p.getHeadSection().getClass().getName());
checkError("{foo}_{foo}", 0, PatternMessage.ILLEGAL_DOUBLE_CAPTURE, "foo");
checkError("/{bar}/{bar}", 7, PatternMessage.ILLEGAL_DOUBLE_CAPTURE, "bar");
checkError("/{bar}/{bar}_{foo}", 7, PatternMessage.ILLEGAL_DOUBLE_CAPTURE, "bar");
p = checkStructure("{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar");
assertEquals(RegexPathElement.class.getName(),p.getHeadSection().getClass().getName());
assertEquals(RegexPathElement.class.getName(), p.getHeadSection().getClass().getName());
}
@Test
public void completeCapturingPatterns() {
p = checkStructure("{foo}");
assertEquals(CaptureVariablePathElement.class.getName(),p.getHeadSection().getClass().getName());
assertEquals(CaptureVariablePathElement.class.getName(), p.getHeadSection().getClass().getName());
checkStructure("/{foo}");
checkStructure("//{f}/");
checkStructure("/{foo}/{bar}/{wibble}");
}
@Test
public void completeCaptureWithConstraints() {
p = checkStructure("{foo:...}");
assertPathElements(p, CaptureVariablePathElement.class);
p = checkStructure("{foo:[0-9]*}");
assertPathElements(p, CaptureVariablePathElement.class);
checkError("{foo:}",5,PatternMessage.MISSING_REGEX_CONSTRAINT);
checkError("{foo:}", 5, PatternMessage.MISSING_REGEX_CONSTRAINT);
}
@Test
public void partialCapturingPatterns() {
p = checkStructure("{foo}abc");
assertEquals(RegexPathElement.class.getName(),p.getHeadSection().getClass().getName());
assertEquals(RegexPathElement.class.getName(), p.getHeadSection().getClass().getName());
checkStructure("abc{foo}");
checkStructure("/abc{foo}");
checkStructure("{foo}def/");
@@ -203,177 +203,179 @@ public class PathPatternParserTests {
@Test
public void illegalCapturePatterns() {
checkError("{abc/",4,PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("{abc:}/",5,PatternMessage.MISSING_REGEX_CONSTRAINT);
checkError("{",1,PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("{abc",4,PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("{/}",1,PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("//{",3,PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("}",0,PatternMessage.MISSING_OPEN_CAPTURE);
checkError("/}",1,PatternMessage.MISSING_OPEN_CAPTURE);
checkError("def}",3,PatternMessage.MISSING_OPEN_CAPTURE);
checkError("//{/}",3,PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("//{{/}",3,PatternMessage.ILLEGAL_NESTED_CAPTURE);
checkError("//{abc{/}",6,PatternMessage.ILLEGAL_NESTED_CAPTURE);
checkError("/{0abc}/abc",2,PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR);
checkError("/{a?bc}/abc",3,PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR);
checkError("/{abc}_{abc}",1,PatternMessage.ILLEGAL_DOUBLE_CAPTURE);
checkError("/foobar/{abc}_{abc}",8,PatternMessage.ILLEGAL_DOUBLE_CAPTURE);
checkError("/foobar/{abc:..}_{abc:..}",8,PatternMessage.ILLEGAL_DOUBLE_CAPTURE);
checkError("{abc/", 4, PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("{abc:}/", 5, PatternMessage.MISSING_REGEX_CONSTRAINT);
checkError("{", 1, PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("{abc", 4, PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("{/}", 1, PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("//{", 3, PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("}", 0, PatternMessage.MISSING_OPEN_CAPTURE);
checkError("/}", 1, PatternMessage.MISSING_OPEN_CAPTURE);
checkError("def}", 3, PatternMessage.MISSING_OPEN_CAPTURE);
checkError("//{/}", 3, PatternMessage.MISSING_CLOSE_CAPTURE);
checkError("//{{/}", 3, PatternMessage.ILLEGAL_NESTED_CAPTURE);
checkError("//{abc{/}", 6, PatternMessage.ILLEGAL_NESTED_CAPTURE);
checkError("/{0abc}/abc", 2, PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR);
checkError("/{a?bc}/abc", 3, PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR);
checkError("/{abc}_{abc}", 1, PatternMessage.ILLEGAL_DOUBLE_CAPTURE);
checkError("/foobar/{abc}_{abc}", 8, PatternMessage.ILLEGAL_DOUBLE_CAPTURE);
checkError("/foobar/{abc:..}_{abc:..}", 8, PatternMessage.ILLEGAL_DOUBLE_CAPTURE);
PathPattern pp = parse("/{abc:foo(bar)}");
try {
pp.matchAndExtract("/foo");
fail("Should have raised exception");
} catch (IllegalArgumentException iae) {
assertEquals("No capture groups allowed in the constraint regex: foo(bar)",iae.getMessage());
}
catch (IllegalArgumentException iae) {
assertEquals("No capture groups allowed in the constraint regex: foo(bar)", iae.getMessage());
}
try {
pp.matchAndExtract("/foobar");
fail("Should have raised exception");
} catch (IllegalArgumentException iae) {
assertEquals("No capture groups allowed in the constraint regex: foo(bar)",iae.getMessage());
}
catch (IllegalArgumentException iae) {
assertEquals("No capture groups allowed in the constraint regex: foo(bar)", iae.getMessage());
}
}
@Test
public void badPatterns() {
// checkError("/{foo}{bar}/",6,PatternMessage.CANNOT_HAVE_ADJACENT_CAPTURES);
checkError("/{?}/",2,PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR,"?");
checkError("/{a?b}/",3,PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR,"?");
checkError("/{%%$}",2,PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR,"%");
checkError("/{ }",2,PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR," ");
checkError("/{%:[0-9]*}",2,PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR,"%");
checkError("/{?}/", 2, PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR, "?");
checkError("/{a?b}/", 3, PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR, "?");
checkError("/{%%$}", 2, PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR, "%");
checkError("/{ }", 2, PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR, " ");
checkError("/{%:[0-9]*}", 2, PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR, "%");
}
@Test
public void patternPropertyGetCaptureCountTests() {
// Test all basic section types
assertEquals(1,parse("{foo}").getCapturedVariableCount());
assertEquals(0,parse("foo").getCapturedVariableCount());
assertEquals(1,parse("{*foobar}").getCapturedVariableCount());
assertEquals(1,parse("/{*foobar}").getCapturedVariableCount());
assertEquals(0,parse("/**").getCapturedVariableCount());
assertEquals(1,parse("{abc}asdf").getCapturedVariableCount());
assertEquals(1,parse("{abc}_*").getCapturedVariableCount());
assertEquals(2,parse("{abc}_{def}").getCapturedVariableCount());
assertEquals(0,parse("/").getCapturedVariableCount());
assertEquals(0,parse("a?b").getCapturedVariableCount());
assertEquals(0,parse("*").getCapturedVariableCount());
assertEquals(1, parse("{foo}").getCapturedVariableCount());
assertEquals(0, parse("foo").getCapturedVariableCount());
assertEquals(1, parse("{*foobar}").getCapturedVariableCount());
assertEquals(1, parse("/{*foobar}").getCapturedVariableCount());
assertEquals(0, parse("/**").getCapturedVariableCount());
assertEquals(1, parse("{abc}asdf").getCapturedVariableCount());
assertEquals(1, parse("{abc}_*").getCapturedVariableCount());
assertEquals(2, parse("{abc}_{def}").getCapturedVariableCount());
assertEquals(0, parse("/").getCapturedVariableCount());
assertEquals(0, parse("a?b").getCapturedVariableCount());
assertEquals(0, parse("*").getCapturedVariableCount());
// Test on full templates
assertEquals(0,parse("/foo/bar").getCapturedVariableCount());
assertEquals(1,parse("/{foo}").getCapturedVariableCount());
assertEquals(2,parse("/{foo}/{bar}").getCapturedVariableCount());
assertEquals(4,parse("/{foo}/{bar}_{goo}_{wibble}/abc/bar").getCapturedVariableCount());
assertEquals(0, parse("/foo/bar").getCapturedVariableCount());
assertEquals(1, parse("/{foo}").getCapturedVariableCount());
assertEquals(2, parse("/{foo}/{bar}").getCapturedVariableCount());
assertEquals(4, parse("/{foo}/{bar}_{goo}_{wibble}/abc/bar").getCapturedVariableCount());
}
@Test
public void patternPropertyGetWildcardCountTests() {
// Test all basic section types
assertEquals(computeScore(1,0),parse("{foo}").getScore());
assertEquals(computeScore(0,0),parse("foo").getScore());
assertEquals(computeScore(0,0),parse("{*foobar}").getScore());
assertEquals(computeScore(1, 0), parse("{foo}").getScore());
assertEquals(computeScore(0, 0), parse("foo").getScore());
assertEquals(computeScore(0, 0), parse("{*foobar}").getScore());
// assertEquals(1,parse("/**").getScore());
assertEquals(computeScore(1,0),parse("{abc}asdf").getScore());
assertEquals(computeScore(1,1),parse("{abc}_*").getScore());
assertEquals(computeScore(2,0),parse("{abc}_{def}").getScore());
assertEquals(computeScore(0,0),parse("/").getScore());
assertEquals(computeScore(0,0),parse("a?b").getScore()); // currently deliberate
assertEquals(computeScore(0,1),parse("*").getScore());
assertEquals(computeScore(1, 0), parse("{abc}asdf").getScore());
assertEquals(computeScore(1, 1), parse("{abc}_*").getScore());
assertEquals(computeScore(2, 0), parse("{abc}_{def}").getScore());
assertEquals(computeScore(0, 0), parse("/").getScore());
assertEquals(computeScore(0, 0), parse("a?b").getScore()); // currently deliberate
assertEquals(computeScore(0, 1), parse("*").getScore());
// Test on full templates
assertEquals(computeScore(0,0),parse("/foo/bar").getScore());
assertEquals(computeScore(1,0),parse("/{foo}").getScore());
assertEquals(computeScore(2,0),parse("/{foo}/{bar}").getScore());
assertEquals(computeScore(4,0),parse("/{foo}/{bar}_{goo}_{wibble}/abc/bar").getScore());
assertEquals(computeScore(4,3),parse("/{foo}/*/*_*/{bar}_{goo}_{wibble}/abc/bar").getScore());
assertEquals(computeScore(0, 0), parse("/foo/bar").getScore());
assertEquals(computeScore(1, 0), parse("/{foo}").getScore());
assertEquals(computeScore(2, 0), parse("/{foo}/{bar}").getScore());
assertEquals(computeScore(4, 0), parse("/{foo}/{bar}_{goo}_{wibble}/abc/bar").getScore());
assertEquals(computeScore(4, 3), parse("/{foo}/*/*_*/{bar}_{goo}_{wibble}/abc/bar").getScore());
}
@Test
public void multipleSeparatorPatterns() {
p = checkStructure("///aaa");
assertEquals(4,p.getNormalizedLength());
assertPathElements(p,SeparatorPathElement.class,LiteralPathElement.class);
assertEquals(4, p.getNormalizedLength());
assertPathElements(p, SeparatorPathElement.class, LiteralPathElement.class);
p = checkStructure("///aaa////aaa/b");
assertEquals(10,p.getNormalizedLength());
assertPathElements(p,SeparatorPathElement.class, LiteralPathElement.class,
assertEquals(10, p.getNormalizedLength());
assertPathElements(p, SeparatorPathElement.class, LiteralPathElement.class,
SeparatorPathElement.class, LiteralPathElement.class, SeparatorPathElement.class, LiteralPathElement.class);
p = checkStructure("/////**");
assertEquals(1,p.getNormalizedLength());
assertPathElements(p,WildcardTheRestPathElement.class);
assertEquals(1, p.getNormalizedLength());
assertPathElements(p, WildcardTheRestPathElement.class);
}
@Test
public void patternPropertyGetLengthTests() {
// Test all basic section types
assertEquals(1,parse("{foo}").getNormalizedLength());
assertEquals(3,parse("foo").getNormalizedLength());
assertEquals(1,parse("{*foobar}").getNormalizedLength());
assertEquals(1,parse("/{*foobar}").getNormalizedLength());
assertEquals(1,parse("/**").getNormalizedLength());
assertEquals(5,parse("{abc}asdf").getNormalizedLength());
assertEquals(3,parse("{abc}_*").getNormalizedLength());
assertEquals(3,parse("{abc}_{def}").getNormalizedLength());
assertEquals(1,parse("/").getNormalizedLength());
assertEquals(3,parse("a?b").getNormalizedLength());
assertEquals(1,parse("*").getNormalizedLength());
assertEquals(1, parse("{foo}").getNormalizedLength());
assertEquals(3, parse("foo").getNormalizedLength());
assertEquals(1, parse("{*foobar}").getNormalizedLength());
assertEquals(1, parse("/{*foobar}").getNormalizedLength());
assertEquals(1, parse("/**").getNormalizedLength());
assertEquals(5, parse("{abc}asdf").getNormalizedLength());
assertEquals(3, parse("{abc}_*").getNormalizedLength());
assertEquals(3, parse("{abc}_{def}").getNormalizedLength());
assertEquals(1, parse("/").getNormalizedLength());
assertEquals(3, parse("a?b").getNormalizedLength());
assertEquals(1, parse("*").getNormalizedLength());
// Test on full templates
assertEquals(8,parse("/foo/bar").getNormalizedLength());
assertEquals(2,parse("/{foo}").getNormalizedLength());
assertEquals(4,parse("/{foo}/{bar}").getNormalizedLength());
assertEquals(16,parse("/{foo}/{bar}_{goo}_{wibble}/abc/bar").getNormalizedLength());
assertEquals(8, parse("/foo/bar").getNormalizedLength());
assertEquals(2, parse("/{foo}").getNormalizedLength());
assertEquals(4, parse("/{foo}/{bar}").getNormalizedLength());
assertEquals(16, parse("/{foo}/{bar}_{goo}_{wibble}/abc/bar").getNormalizedLength());
}
@Test
public void compareTests() {
PathPattern p1,p2,p3;
PathPattern p1, p2, p3;
// Based purely on number of captures
p1 = parse("{a}");
p2 = parse("{a}/{b}");
p3 = parse("{a}/{b}/{c}");
assertEquals(-1,p1.compareTo(p2)); // Based on number of captures
assertEquals(-1, p1.compareTo(p2)); // Based on number of captures
List<PathPattern> patterns = new ArrayList<>();
patterns.add(p2);
patterns.add(p3);
patterns.add(p1);
Collections.sort(patterns,new PathPatternComparator());
assertEquals(p1,patterns.get(0));
Collections.sort(patterns, new PathPatternComparator());
assertEquals(p1, patterns.get(0));
// Based purely on length
p1 = parse("/a/b/c");
p2 = parse("/a/boo/c/doo");
p3 = parse("/asdjflaksjdfjasdf");
assertEquals(1,p1.compareTo(p2));
assertEquals(1, p1.compareTo(p2));
patterns = new ArrayList<>();
patterns.add(p2);
patterns.add(p3);
patterns.add(p1);
Collections.sort(patterns,new PathPatternComparator());
assertEquals(p3,patterns.get(0));
Collections.sort(patterns, new PathPatternComparator());
assertEquals(p3, patterns.get(0));
// Based purely on 'wildness'
p1 = parse("/*");
p2 = parse("/*/*");
p3 = parse("/*/*/*_*");
assertEquals(-1,p1.compareTo(p2));
assertEquals(-1, p1.compareTo(p2));
patterns = new ArrayList<>();
patterns.add(p2);
patterns.add(p3);
patterns.add(p1);
Collections.sort(patterns,new PathPatternComparator());
assertEquals(p1,patterns.get(0));
Collections.sort(patterns, new PathPatternComparator());
assertEquals(p1, patterns.get(0));
// Based purely on catchAll
p1 = parse("{*foobar}");
p2 = parse("{*goo}");
assertEquals(0,p1.compareTo(p2));
assertEquals(0, p1.compareTo(p2));
p1 = parse("/{*foobar}");
p2 = parse("/abc/{*ww}");
assertEquals(+1,p1.compareTo(p2));
assertEquals(-1,p2.compareTo(p1));
assertEquals(+1, p1.compareTo(p2));
assertEquals(-1, p2.compareTo(p1));
p3 = parse("/this/that/theother");
assertTrue(p1.isCatchAll());
@@ -383,20 +385,20 @@ public class PathPatternParserTests {
patterns.add(p2);
patterns.add(p3);
patterns.add(p1);
Collections.sort(patterns,new PathPatternComparator());
assertEquals(p3,patterns.get(0));
assertEquals(p2,patterns.get(1));
Collections.sort(patterns, new PathPatternComparator());
assertEquals(p3, patterns.get(0));
assertEquals(p2, patterns.get(1));
patterns = new ArrayList<>();
patterns.add(parse("/abc"));
patterns.add(null);
patterns.add(parse("/def"));
Collections.sort(patterns,new PathPatternComparator());
Collections.sort(patterns, new PathPatternComparator());
assertNull(patterns.get(2));
}
// ---
private PathPattern parse(String pattern) {
PathPatternParser patternParser = new PathPatternParser();
return patternParser.parse(pattern);
@@ -408,22 +410,22 @@ public class PathPatternParserTests {
*/
private PathPattern checkStructure(String pattern) {
int count = 0;
for (int i=0;i<pattern.length();i++) {
if (pattern.charAt(i)=='/') {
for (int i = 0; i < pattern.length(); i++) {
if (pattern.charAt(i) == '/') {
// if (peekDoubleWildcard(pattern,i)) {
// // it is /**
// i+=2;
// } else {
count++;
count++;
// }
}
}
return checkStructure(pattern,count);
return checkStructure(pattern, count);
}
private PathPattern checkStructure(String pattern, int expectedSeparatorCount) {
p = parse(pattern);
assertEquals(pattern,p.getPatternString());
assertEquals(pattern, p.getPatternString());
// assertEquals(expectedSeparatorCount,p.getSeparatorCount());
return p;
}
@@ -432,14 +434,15 @@ public class PathPatternParserTests {
try {
p = parse(pattern);
fail("Expected to fail");
} catch (PatternParseException ppe) {
}
catch (PatternParseException ppe) {
// System.out.println(ppe.toDetailedString());
assertEquals(ppe.toDetailedString(), expectedPos, ppe.getPosition());
assertEquals(ppe.toDetailedString(), expectedMessage, ppe.getMessageType());
if (expectedInserts.length!=0) {
assertEquals(ppe.getInserts().length,expectedInserts.length);
for (int i=0;i<expectedInserts.length;i++) {
assertEquals("Insert at position "+i+" is wrong",expectedInserts[i],ppe.getInserts()[i]);
if (expectedInserts.length != 0) {
assertEquals(ppe.getInserts().length, expectedInserts.length);
for (int i = 0; i < expectedInserts.length; i++) {
assertEquals("Insert at position " + i + " is wrong", expectedInserts[i], ppe.getInserts()[i]);
}
}
}
@@ -448,18 +451,18 @@ public class PathPatternParserTests {
@SafeVarargs
private final void assertPathElements(PathPattern p, Class<? extends PathElement>... sectionClasses) {
PathElement head = p.getHeadSection();
for (int i=0;i<sectionClasses.length;i++) {
for (int i = 0; i < sectionClasses.length; i++) {
if (head == null) {
fail("Ran out of data in parsed pattern. Pattern is: "+p.toChainString());
fail("Ran out of data in parsed pattern. Pattern is: " + p.toChainString());
}
assertEquals("Not expected section type. Pattern is: "+p.toChainString(),sectionClasses[i].getSimpleName(),head.getClass().getSimpleName());
assertEquals("Not expected section type. Pattern is: " + p.toChainString(), sectionClasses[i].getSimpleName(), head.getClass().getSimpleName());
head = head.next;
}
}
// Mirrors the score computation logic in PathPattern
private int computeScore(int capturedVariableCount, int wildcardCount) {
return capturedVariableCount+wildcardCount*100;
return capturedVariableCount + wildcardCount * 100;
}
}