def test_token1(self): matcher = TokenMatcher("aaa") self.assertEqual( matcher(tokens1), 1 ) self.assertEqual( matcher.catch, ["aaa"] ) self.assertEqual( matcher.output(), ["aaa"] ) matcher = TokenMatcher(["aaa", "bbb"]) self.assertEqual( matcher(tokens1), 2 ) self.assertEqual( matcher.catch, ["aaa", "bbb"] ) self.assertEqual( matcher.output(), ['aaa', 'bbb'] ) matcher = TokenMatcher(["aaa", "ccc"]) self.assertEqual( matcher(tokens1), -1 )
def test_unittoken(self): matcher = UnitTokenMatcher("aaa") self.assertEqual( matcher(tokens1), 1 ) self.assertEqual( matcher.catch, ["aaa"] ) self.assertEqual( matcher.output(), ["aaa"] ) matcher = UnitTokenMatcher("aaa") + UnitTokenMatcher("bbb") self.assertEqual( matcher(tokens1), 2 ) self.assertEqual( matcher.catch, ["aaa", "bbb"] ) self.assertEqual( matcher.output(), ['aaa', 'bbb'] ) matcher = UnitTokenMatcher("bbb") + UnitTokenMatcher("ccc") self.assertEqual(matcher.findMatching(tokens1),1) self.assertEqual( matcher.output(), ['bbb', 'ccc'] )
def test_regex(self): matcher = RegexMatcher("a*") self.assertEqual( matcher(tokens1), 1 ) self.assertEqual( matcher.catch, ["aaa"] ) self.assertEqual( matcher.output(), ["aaa"] ) matcher = RegexMatcher("aaa") + RegexMatcher("b+") self.assertEqual( matcher(tokens1), 2 ) self.assertEqual( matcher.catch, ["aaa", "bbb"] ) self.assertEqual( matcher.output(), ['aaa', 'bbb'] ) matcher = RegexMatcher("bbb") + RegexMatcher("ccc") self.assertEqual(matcher.findMatching(tokens1),1) self.assertEqual( matcher.output(), ['bbb', 'ccc'] )
def test_token1(self): matcher = TokenMatcher("aaa") self.assertEqual(matcher(tokens1), 1) self.assertEqual(matcher.catch, ["aaa"]) self.assertEqual(matcher.output(), ["aaa"]) matcher = TokenMatcher(["aaa", "bbb"]) self.assertEqual(matcher(tokens1), 2) self.assertEqual(matcher.catch, ["aaa", "bbb"]) self.assertEqual(matcher.output(), ['aaa', 'bbb']) matcher = TokenMatcher(["aaa", "ccc"]) self.assertEqual(matcher(tokens1), -1)
def test_unittoken(self): matcher = UnitTokenMatcher("aaa") self.assertEqual(matcher(tokens1), 1) self.assertEqual(matcher.catch, ["aaa"]) self.assertEqual(matcher.output(), ["aaa"]) matcher = UnitTokenMatcher("aaa") + UnitTokenMatcher("bbb") self.assertEqual(matcher(tokens1), 2) self.assertEqual(matcher.catch, ["aaa", "bbb"]) self.assertEqual(matcher.output(), ['aaa', 'bbb']) matcher = UnitTokenMatcher("bbb") + UnitTokenMatcher("ccc") self.assertEqual(matcher.findMatching(tokens1), 1) self.assertEqual(matcher.output(), ['bbb', 'ccc'])
def test_regex(self): matcher = RegexMatcher("a*") self.assertEqual(matcher(tokens1), 1) self.assertEqual(matcher.catch, ["aaa"]) self.assertEqual(matcher.output(), ["aaa"]) matcher = RegexMatcher("aaa") + RegexMatcher("b+") self.assertEqual(matcher(tokens1), 2) self.assertEqual(matcher.catch, ["aaa", "bbb"]) self.assertEqual(matcher.output(), ['aaa', 'bbb']) matcher = RegexMatcher("bbb") + RegexMatcher("ccc") self.assertEqual(matcher.findMatching(tokens1), 1) self.assertEqual(matcher.output(), ['bbb', 'ccc'])