Example #1
0
        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());
        }
Example #2
0
        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());
        }