Пример #1
0
 def test_choice_will_backtrack_and_try_other_options(self):
     x, y = matcher.Var('x'), matcher.Var('y')
     self.assertDictEqual(
         matcher.match((matcher.Choice(x, y), x, y), (3, 2, 3)),
         dict(x=2, y=3))
Пример #2
0
 def test_choice_with_name_binds_value(self):
     pattern = matcher.Choice((1, 2), (2, 1), name='x')
     self.assertDictEqual(matcher.match(pattern, (1, 2)), {'x': (1, 2)})
     self.assertDictEqual(matcher.match(pattern, (2, 1)), {'x': (2, 1)})
Пример #3
0
 def test_choice_correctly_matches_multiple_options(self):
     pattern = matcher.Choice(1, 2)
     self.assertDictEqual(matcher.match(pattern, 1), {})
     self.assertDictEqual(matcher.match(pattern, 2), {})
     with self.assertRaises(matcher.MatchError):
         matcher.match(pattern, 3)