def test_match_messages_non_recursive_rules(self):
     rules, messages = main.parse_rules_messages(self.rules_messages_rec)
     main.link_rules(rules)
     rule = rules[0]
     messages = main.init_messages_remainders(messages)
     matched_messages = rule.match_messages(messages)
     actual = main.discard_messages_with_remainders(matched_messages)
     self.assertIn('bbabbbbaabaabba', actual.keys())
     self.assertIn('ababaaaaaabaaab', actual.keys())
     self.assertIn('ababaaaaabbbaba', actual.keys())
     self.assertEqual(len(actual.keys()), 3)
 def test_match_messages_matched_combined_rules(self):
     rules, messages = main.parse_rules_messages(self.rules_messages)
     main.link_rules(rules)
     rule = rules[0]
     messages = main.init_messages_remainders(messages)
     matched_messages = rule.match_messages(messages)
     actual = main.discard_messages_with_remainders(matched_messages)
     self.assertIn('ababbb', actual.keys())
     self.assertIn('abbbab', actual.keys())
     self.assertNotIn('bababa', actual.keys())
     self.assertNotIn('aaabbb', actual.keys())
     self.assertNotIn('aaaabbb', actual.keys())
 def test_match_messages_matches_trunk_rule(self):
     rules_messages = [
         '0: 1 3', '1: 2', '2: "a"', '3: "b"', '', 'ab', 'a', 'b', 'ba',
         'aba', 'abb'
     ]
     rules, messages = main.parse_rules_messages(rules_messages)
     main.link_rules(rules)
     rule = rules[0]
     messages = main.init_messages_remainders(messages)
     actual = rule.match_messages(messages)
     self.assertIn('ab', actual.keys())
     self.assertIn('aba', actual.keys())
     self.assertIn('abb', actual.keys())
     self.assertNotIn('a', actual.keys())
     self.assertNotIn('b', actual.keys())
     self.assertNotIn('ba', actual.keys())
     self.assertIn('', actual['ab'])
     self.assertIn('a', actual['aba'])
 def test_match_messages_recursive_rules(self):
     rules, messages = main.parse_rules_messages(self.rules_messages_rec)
     rules[8] = main.Rule(8, 'branch', [[42], [42, 8]])
     rules[11] = main.Rule(11, 'branch', [[42, 31], [42, 11, 31]])
     main.link_rules(rules)
     rule = rules[0]
     messages = main.init_messages_remainders(messages)
     matched_messages = rule.match_messages(messages)
     actual = main.discard_messages_with_remainders(matched_messages)
     self.assertIn('bbabbbbaabaabba', actual.keys())
     self.assertIn('babbbbaabbbbbabbbbbbaabaaabaaa', actual.keys())
     self.assertIn('aaabbbbbbaaaabaababaabababbabaaabbababababaaa',
                   actual.keys())
     self.assertIn('bbbbbbbaaaabbbbaaabbabaaa', actual.keys())
     self.assertIn('bbbababbbbaaaaaaaabbababaaababaabab', actual.keys())
     self.assertIn('ababaaaaaabaaab', actual.keys())
     self.assertIn('ababaaaaabbbaba', actual.keys())
     self.assertIn('baabbaaaabbaaaababbaababb', actual.keys())
     self.assertIn('abbbbabbbbaaaababbbbbbaaaababb', actual.keys())
     self.assertIn('aaaaabbaabaaaaababaa', actual.keys())
     self.assertIn('aaaabbaabbaaaaaaabbbabbbaaabbaabaaa', actual.keys())
     self.assertIn('aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba',
                   actual.keys())