Example #1
0
    def test_code_matcher_anna(self):
        """Number calcs in the middle."""
        matcher = matching.MatchCode()
        for mtype in 'any number number any'.split():
            matcher.append(mtype)
        
        result = matcher("abc123fun321", start_pos=3, end_pos=None, minimal=False)
        self.assertEqual(result, (3,11))
        result = matcher("abc123fun321", start_pos=4, end_pos=None, minimal=False)
        self.assertEqual(result, (4,11))
        result = matcher("abc123fun321", start_pos=2, end_pos=5, minimal=False)
        self.assertEqual(result, (2,5))
        result = matcher("abc123fun321", start_pos=3, end_pos=9, minimal=False)
        self.assertEqual(result, (3,9))
        result = matcher("abc123fun321", start_pos=4, end_pos=9, minimal=False)
        self.assertEqual(result, None)
        result = matcher("abc123fun321", start_pos=0, end_pos=None, minimal=True)
        self.assertEqual(result, (0,5))

        result = matcher.match_one_more("abc123fun321", start_pos=0, end_pos=5)
        self.assertTrue(result)
        result = matcher.match_one_more("abc123fun321", start_pos=4, end_pos=7)
        self.assertTrue(result)

        return
Example #2
0
    def test_code_matcher_naan(self):
        """Number calcs on the ends."""
        matcher = matching.MatchCode()
        for mtype in 'number any any number'.split():
            matcher.append(mtype)
        
        result = matcher("abc123fun321", start_pos=4, end_pos=None, minimal=False)
        self.assertEqual(result, (4,11))
        result = matcher("abc123fun321", start_pos=5, end_pos=None, minimal=False)
        self.assertEqual(result, (5,11))
        result = matcher("abc123fun321", start_pos=6, end_pos=None, minimal=False)
        self.assertEqual(result, None)
        result = matcher("abc123fun321", start_pos=5, end_pos=9, minimal=False)
        self.assertEqual(result, (5,9))
        result = matcher("abc123fun321", start_pos=5, end_pos=8, minimal=False)
        self.assertEqual(result, None)
        result = matcher("abc123fun321", start_pos=4, end_pos=None, minimal=True)
        self.assertEqual(result, (4,9))
        
        result = matcher.match_one_more("abc123fun321", start_pos=0, end_pos=5)
        self.assertFalse(result)
        result = matcher.match_one_more("abc123fun321", start_pos=5, end_pos=9)
        self.assertTrue(result)

        return
Example #3
0
    def test_code_matcher_a(self):
        """Single any calc."""
        matcher = matching.MatchCode()
        matcher.append('any')

        result = matcher("aaa.b2b.c-c", start_pos=4, end_pos=None, minimal=False)
        self.assertEqual(result, (4,10))
        result = matcher("aaa.b2b.c-c", start_pos=5, end_pos=None, minimal=False)
        self.assertEqual(result, (5,10))

        return
Example #4
0
 def test_code_matcher_n(self):
     """Single numeric calc."""
     matcher = matching.MatchCode()
     matcher.append('number')
     
     result = matcher("aaa.b2b.c-c", start_pos=4, end_pos=None, minimal=False)
     self.assertEqual(result, None)
     result = matcher("aaa.b2b.c-c", start_pos=5, end_pos=None, minimal=False)
     self.assertEqual(result, (5,5))
     
     return