示例#1
0
    def test_backref_matcher(self):
        backRef = NdnRegexBackrefManager()
        cm = NdnRegexBackrefMatcher("(<a><b>)", backRef)
        backRef.pushRef(cm)
        cm.lateCompile()
        res = cm.match(Name("/a/b/c"), 0, 2)
        self.assertEqual(True, res)
        self.assertEqual(2, len(cm.getMatchResult()))
        self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())
        self.assertEqual("b", cm.getMatchResult()[1].toEscapedString())
        self.assertEqual(1, backRef.size())

        backRef = NdnRegexBackrefManager()
        cm = NdnRegexBackrefMatcher("(<a>(<b>))", backRef)
        backRef.pushRef(cm)
        cm.lateCompile()
        res = cm.match(Name("/a/b/c"), 0, 2)
        self.assertEqual(True, res)
        self.assertEqual(2, len(cm.getMatchResult()))
        self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())
        self.assertEqual("b", cm.getMatchResult()[1].toEscapedString())
        self.assertEqual(2, backRef.size())
        self.assertEqual("a",
          backRef.getBackref(0).getMatchResult()[0].toEscapedString())
        self.assertEqual("b",
          backRef.getBackref(0).getMatchResult()[1].toEscapedString())
        self.assertEqual("b",
          backRef.getBackref(1).getMatchResult()[0].toEscapedString())
示例#2
0
    def test_component_matcher(self):
        backRef = NdnRegexBackrefManager()
        cm = NdnRegexComponentMatcher("a", backRef)
        res = cm.match(Name("/a/b/"), 0, 1)
        self.assertEqual(True, res)
        self.assertEqual(1, len(cm.getMatchResult()))
        self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())

        backRef = NdnRegexBackrefManager()
        cm = NdnRegexComponentMatcher("a", backRef)
        res = cm.match(Name("/a/b/"), 1, 1)
        self.assertEqual(False, res)
        self.assertEqual(0, len(cm.getMatchResult()))

        backRef = NdnRegexBackrefManager()
        cm = NdnRegexComponentMatcher("(c+)\\.(cd)", backRef)
        res = cm.match(Name("/ccc.cd/b/"), 0, 1)
        self.assertEqual(True, res)
        self.assertEqual(1, len(cm.getMatchResult()))
        self.assertEqual("ccc.cd", cm.getMatchResult()[0].toEscapedString())

        self.assertEqual(2, backRef.size())
        self.assertEqual("ccc",
          backRef.getBackref(0).getMatchResult()[0].toEscapedString())
        self.assertEqual("cd",
          backRef.getBackref(1).getMatchResult()[0].toEscapedString())
示例#3
0
 def test_backref_matcher_advanced(self):
     backRef = NdnRegexBackrefManager()
     cm = NdnRegexRepeatMatcher("([<a><b>])+", backRef, 10)
     res = cm.match(Name("/a/b/c"), 0, 2)
     self.assertEqual(True, res)
     self.assertEqual(2, len(cm.getMatchResult()))
     self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())
     self.assertEqual("b", cm.getMatchResult()[1].toEscapedString())
     self.assertEqual(1, backRef.size())
     self.assertEqual("b",
       backRef.getBackref(0).getMatchResult()[0].toEscapedString())
示例#4
0
 def test_backref_matcher_advanced2(self):
     backRef = NdnRegexBackrefManager()
     cm = NdnRegexPatternListMatcher("(<a>(<b>))<c>", backRef)
     res = cm.match(Name("/a/b/c"), 0, 3)
     self.assertEqual(True, res)
     self.assertEqual(3, len(cm.getMatchResult()))
     self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())
     self.assertEqual("b", cm.getMatchResult()[1].toEscapedString())
     self.assertEqual("c", cm.getMatchResult()[2].toEscapedString())
     self.assertEqual(2, backRef.size())
     self.assertEqual("a",
       backRef.getBackref(0).getMatchResult()[0].toEscapedString())
     self.assertEqual("b",
       backRef.getBackref(0).getMatchResult()[1].toEscapedString())
     self.assertEqual("b",
       backRef.getBackref(1).getMatchResult()[0].toEscapedString())