예제 #1
0
 def test_string(self):
     self.assertEqual(
         base_matchers.HasItem(1, base_matchers.Bind('a')).match(
             _FAKE_CONTEXT, 'xy'),
         matcher.MatchInfo(
             match.StringMatch('xy'),
             {'a': matcher.BoundValue(match.StringMatch('y'))}))
예제 #2
0
 def test_negative_index(self):
     container = ['xyz']
     self.assertEqual(
         base_matchers.HasItem(-1, base_matchers.Bind('a')).match(
             _FAKE_CONTEXT, container),
         matcher.MatchInfo(
             match.ObjectMatch(container),
             {'a': matcher.BoundValue(match.StringMatch('xyz'))}))
예제 #3
0
 def test_simple(self):
     for nonempty_container in (('x', 'y'), ['x', 'y'], {1: 'y'}):
         with self.subTest(nonempty_container=nonempty_container):
             self.assertEqual(
                 base_matchers.HasItem(1, base_matchers.Bind('a')).match(
                     _FAKE_CONTEXT, nonempty_container),
                 matcher.MatchInfo(
                     match.ObjectMatch(nonempty_container),
                     {'a': matcher.BoundValue(match.StringMatch('y'))}))
예제 #4
0
 def test_wrongtype(self):
     m = base_matchers.HasItem(0, base_matchers.Anything())
     self.assertIsNone(m.match(_FAKE_CONTEXT, object()))
예제 #5
0
 def test_submatch_rejects(self):
     self.assertIsNone(
         base_matchers.HasItem(
             -1, base_matchers.Unless(base_matchers.Anything())).match(
                 _FAKE_CONTEXT, ['xyz']))
예제 #6
0
 def test_has_no_item(self):
     for empty_container in ((), [], {}, ''):
         with self.subTest(empty_container=empty_container):
             self.assertIsNone(
                 base_matchers.HasItem(0).match(_FAKE_CONTEXT,
                                                empty_container))