def test_not_matchable(self): self.nt = Terminal('X', matchable=False) path = map_path('X') matches = self.nt.match_path(path) expected_result = [] self.assertListEqual(matches, expected_result)
def setUp(self): # Graph = # 9 # / | \ # 6 7 8 # \ / \ / # 4 5 # / \ / \ # 1 2 3 self.g1 = InmemoryGraph() edges = [(1, 4), (2, 4), (2, 5), (3, 5), (4, 6), (4, 7), (5, 7), (5, 8), (6, 9), (7, 9), (8, 9)] for edge in edges: self.g1.add_edge(*edge) self.g1.add_node_label(1, 'A') self.g1.add_node_label(3, 'A') self.g1.add_node_label(7, 'B') self.g1.add_node_label(9, 'C') g1 = Sequence( [Terminal('A'), Terminal('B'), Terminal('C')], 'sequence') self.matcher1 = StatelessMatcher(g1) self.apt_diagnoser = APTDiagnoser(self.g1, self.matcher1)
def test_nested(self): s2 = Sequence( [Terminal('A'), self.s, Terminal('C')], 'sequence2', matchable='False') path = map_path('AABCC') matches = s2.match_path(path) expected_result = \ [MatcherResult(path, [(0, 'A'), (1, 'A'), (2, 'B'), (3, 'C'), (4, 'C')], counter=4)] self.assertListEqual(matches, expected_result)
class TerminalMatcherTest(unittest.TestCase): def setUp(self): self.nt = Terminal('X') def test_label(self): self.assertEqual('X', self.nt.get_label()) def test_simple_path(self): path = map_path('abcXdeX') matches = self.nt.match_path(path) expected_result = [ MatcherResult(path, [(3, 'X')], counter=3), MatcherResult(path, [(6, 'X')], counter=6) ] self.assertListEqual(matches, expected_result) def test_multiple_symbols(self): path = [['a'], ['b', 'X'], ['X', 'c']] matches = self.nt.match_path(path) expected_result = [ MatcherResult(path, [(1, 'X')], counter=1), MatcherResult(path, [(2, 'X')], counter=2) ] self.assertListEqual(matches, expected_result) def test_empty_path(self): path = [] matches = self.nt.match_path(path) expected_result = [] self.assertListEqual(matches, expected_result) def test_mid_match(self): path = map_path('wXyXyz') matches = self.nt.match(MatcherResult(path, [(1, 'X')], counter=2)) expected_result = [ MatcherResult(path, [(1, 'X'), (3, 'X')], counter=3) ] self.assertListEqual(matches, expected_result) def test_not_matchable(self): self.nt = Terminal('X', matchable=False) path = map_path('X') matches = self.nt.match_path(path) expected_result = [] self.assertListEqual(matches, expected_result) def test_reverse(self): path = map_path('abcXdeX') matches = self.nt.match_reverse_path(path) expected_result = [ MatcherResult(path, [(6, 'X')], counter=6, reverse=True), MatcherResult(path, [(3, 'X')], counter=3, reverse=True) ] self.assertListEqual(matches, expected_result)
def setUp(self): self.s = Sequence( [Terminal('A'), Terminal('B'), Terminal('C')], 'sequence')
def test_cardinality(self): with self.assertRaises(RuleException): Sequence('s') with self.assertRaises(RuleException): Sequence('s', Terminal('A'))
def setUp(self): self.nt = Terminal('X')
def setUp(self): g1 = Sequence( [Terminal('A'), Terminal('B'), Terminal('C')], 'sequence') self.matcher1 = StatelessMatcher(g1, CrispStrategy())
def setUp(self): self.ot = Optional([Terminal('A')]) self.os = Optional([Sequence([Terminal('B'), Terminal('C')])])
def setUp(self): self.c = Choice( [Terminal('A'), Terminal('B'), Terminal('C')], 'choice')
def test_cardinality(self): with self.assertRaises(RuleException): Choice([Terminal('A')]) with self.assertRaises(RuleException): Choice([])