public void testPatternListMatcher() { NdnRegexBackrefManager backRef = new NdnRegexBackrefManager(); NdnRegexPatternListMatcher cm = new NdnRegexPatternListMatcher( "<a>[<a><b>]", backRef); bool res = cm.match(new Name("/a/b/c"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexPatternListMatcher("<>*<a>", backRef); res = cm.match(new Name("/a/b/c"), 0, 1); Assert.AssertEquals(true, res); Assert.AssertEquals(1, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexPatternListMatcher("<>*<a>", backRef); res = cm.match(new Name("/a/b/c"), 0, 2); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexPatternListMatcher("<>*<a><>*", backRef); res = cm.match(new Name("/a/b/c"), 0, 3); Assert.AssertEquals(true, res); Assert.AssertEquals(3, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals("c", cm.getMatchResult()[2].toEscapedString()); }
public void testBackRefMatcher() { NdnRegexBackrefManager backRef = new NdnRegexBackrefManager(); NdnRegexBackrefMatcher cm = new NdnRegexBackrefMatcher("(<a><b>)", backRef); backRef.pushRef(cm); cm.lateCompile(); bool res = cm.match(new Name("/a/b/c"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals(1, backRef.size()); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexBackrefMatcher("(<a>(<b>))", backRef); backRef.pushRef(cm); cm.lateCompile(); res = cm.match(new Name("/a/b/c"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals(2, backRef.size()); Assert.AssertEquals("a", backRef.getBackref(0).getMatchResult()[0] .toEscapedString()); Assert.AssertEquals("b", backRef.getBackref(0).getMatchResult()[1] .toEscapedString()); Assert.AssertEquals("b", backRef.getBackref(1).getMatchResult()[0] .toEscapedString()); }
public void testComponentMatcher() { NdnRegexBackrefManager backRef = new NdnRegexBackrefManager(); NdnRegexComponentMatcher cm = new NdnRegexComponentMatcher("a", backRef); bool res = cm.match(new Name("/a/b/"), 0, 1); Assert.AssertEquals(true, res); Assert.AssertEquals(1, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexComponentMatcher("a", backRef); res = cm.match(new Name("/a/b/"), 1, 1); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexComponentMatcher("(c+)\\.(cd)", backRef); res = cm.match(new Name("/ccc.cd/b/"), 0, 1); Assert.AssertEquals(true, res); Assert.AssertEquals(1, cm.getMatchResult().Count); Assert.AssertEquals("ccc.cd", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals(2, backRef.size()); Assert.AssertEquals("ccc", backRef.getBackref(0).getMatchResult()[0] .toEscapedString()); Assert.AssertEquals("cd", backRef.getBackref(1).getMatchResult()[0] .toEscapedString()); }
public void testBackRefMatcherAdvanced() { NdnRegexBackrefManager backRef = new NdnRegexBackrefManager(); NdnRegexRepeatMatcher cm = new NdnRegexRepeatMatcher("([<a><b>])+", backRef, 10); bool res = cm.match(new Name("/a/b/c"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals(1, backRef.size()); Assert.AssertEquals("b", backRef.getBackref(0).getMatchResult()[0] .toEscapedString()); }
public void testComponentSetMatcher() { NdnRegexBackrefManager backRef = new NdnRegexBackrefManager(); NdnRegexComponentSetMatcher cm = new NdnRegexComponentSetMatcher("<a>", backRef); bool res = cm.match(new Name("/a/b/"), 0, 1); Assert.AssertEquals(true, res); Assert.AssertEquals(1, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); res = cm.match(new Name("/a/b/"), 1, 1); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); res = cm.match(new Name("/a/b/"), 0, 2); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexComponentSetMatcher("[<a><b><c>]", backRef); res = cm.match(new Name("/a/b/d"), 1, 1); Assert.AssertEquals(true, res); Assert.AssertEquals(1, cm.getMatchResult().Count); Assert.AssertEquals("b", cm.getMatchResult()[0].toEscapedString()); res = cm.match(new Name("/a/b/d"), 2, 1); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexComponentSetMatcher("[^<a><b><c>]", backRef); res = cm.match(new Name("/b/d"), 1, 1); Assert.AssertEquals(true, res); Assert.AssertEquals(1, cm.getMatchResult().Count); Assert.AssertEquals("d", cm.getMatchResult()[0].toEscapedString()); backRef = new NdnRegexBackrefManager(); try { new NdnRegexComponentSetMatcher("[<a]", backRef); Assert.Fail("Did not throw the expected exception"); } catch (NdnRegexMatcherBase.Error ex) { } catch (Exception ex_0) { Assert.Fail("Did not throw the expected exception"); } }
public void testBackRefMatcherAdvanced2() { NdnRegexBackrefManager backRef = new NdnRegexBackrefManager(); NdnRegexPatternListMatcher cm = new NdnRegexPatternListMatcher( "(<a>(<b>))<c>", backRef); bool res = cm.match(new Name("/a/b/c"), 0, 3); Assert.AssertEquals(true, res); Assert.AssertEquals(3, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals("c", cm.getMatchResult()[2].toEscapedString()); Assert.AssertEquals(2, backRef.size()); Assert.AssertEquals("a", backRef.getBackref(0).getMatchResult()[0] .toEscapedString()); Assert.AssertEquals("b", backRef.getBackref(0).getMatchResult()[1] .toEscapedString()); Assert.AssertEquals("b", backRef.getBackref(1).getMatchResult()[0] .toEscapedString()); }
public void testRepeatMatcher() { NdnRegexBackrefManager backRef = new NdnRegexBackrefManager(); NdnRegexRepeatMatcher cm = new NdnRegexRepeatMatcher("[<a><b>]*", backRef, 8); bool res = cm.match(new Name("/a/b/c"), 0, 0); Assert.AssertEquals(true, res); Assert.AssertEquals(0, cm.getMatchResult().Count); res = cm.match(new Name("/a/b/c"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexRepeatMatcher("[<a><b>]+", backRef, 8); res = cm.match(new Name("/a/b/c"), 0, 0); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); res = cm.match(new Name("/a/b/c"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexRepeatMatcher("<.*>*", backRef, 4); res = cm.match(new Name("/a/b/c/d/e/f/"), 0, 6); Assert.AssertEquals(true, res); Assert.AssertEquals(6, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals("c", cm.getMatchResult()[2].toEscapedString()); Assert.AssertEquals("d", cm.getMatchResult()[3].toEscapedString()); Assert.AssertEquals("e", cm.getMatchResult()[4].toEscapedString()); Assert.AssertEquals("f", cm.getMatchResult()[5].toEscapedString()); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexRepeatMatcher("<>*", backRef, 2); res = cm.match(new Name("/a/b/c/d/e/f/"), 0, 6); Assert.AssertEquals(true, res); Assert.AssertEquals(6, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals("c", cm.getMatchResult()[2].toEscapedString()); Assert.AssertEquals("d", cm.getMatchResult()[3].toEscapedString()); Assert.AssertEquals("e", cm.getMatchResult()[4].toEscapedString()); Assert.AssertEquals("f", cm.getMatchResult()[5].toEscapedString()); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexRepeatMatcher("<a>?", backRef, 3); res = cm.match(new Name("/a/b/c"), 0, 0); Assert.AssertEquals(true, res); Assert.AssertEquals(0, cm.getMatchResult().Count); cm = new NdnRegexRepeatMatcher("<a>?", backRef, 3); res = cm.match(new Name("/a/b/c"), 0, 1); Assert.AssertEquals(true, res); Assert.AssertEquals(1, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); cm = new NdnRegexRepeatMatcher("<a>?", backRef, 3); res = cm.match(new Name("/a/b/c"), 0, 2); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexRepeatMatcher("[<a><b>]{3}", backRef, 8); res = cm.match(new Name("/a/b/a/d/"), 0, 2); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); res = cm.match(new Name("/a/b/a/d/"), 0, 3); Assert.AssertEquals(true, res); Assert.AssertEquals(3, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals("a", cm.getMatchResult()[2].toEscapedString()); res = cm.match(new Name("/a/b/a/d/"), 0, 4); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexRepeatMatcher("[<a><b>]{2,3}", backRef, 8); res = cm.match(new Name("/a/b/a/d/e/"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); res = cm.match(new Name("/a/b/a/d/e/"), 0, 3); Assert.AssertEquals(true, res); Assert.AssertEquals(3, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals("a", cm.getMatchResult()[2].toEscapedString()); res = cm.match(new Name("/a/b/a/b/e/"), 0, 4); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); res = cm.match(new Name("/a/b/a/d/e/"), 0, 1); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexRepeatMatcher("[<a><b>]{2,}", backRef, 8); res = cm.match(new Name("/a/b/a/d/e/"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); res = cm.match(new Name("/a/b/a/b/e/"), 0, 4); Assert.AssertEquals(true, res); Assert.AssertEquals(4, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); Assert.AssertEquals("a", cm.getMatchResult()[2].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[3].toEscapedString()); res = cm.match(new Name("/a/b/a/d/e/"), 0, 1); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); backRef = new NdnRegexBackrefManager(); cm = new NdnRegexRepeatMatcher("[<a><b>]{,2}", backRef, 8); res = cm.match(new Name("/a/b/a/b/e/"), 0, 3); Assert.AssertEquals(false, res); Assert.AssertEquals(0, cm.getMatchResult().Count); res = cm.match(new Name("/a/b/a/b/e/"), 0, 2); Assert.AssertEquals(true, res); Assert.AssertEquals(2, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); Assert.AssertEquals("b", cm.getMatchResult()[1].toEscapedString()); res = cm.match(new Name("/a/b/a/d/e/"), 0, 1); Assert.AssertEquals(true, res); Assert.AssertEquals(1, cm.getMatchResult().Count); Assert.AssertEquals("a", cm.getMatchResult()[0].toEscapedString()); res = cm.match(new Name("/a/b/a/d/e/"), 0, 0); Assert.AssertEquals(true, res); Assert.AssertEquals(0, cm.getMatchResult().Count); }