|
2 | 2 |
|
3 | 3 | import unittest |
4 | 4 |
|
| 5 | +from typing import Dict |
| 6 | + |
5 | 7 | from src.arch.zx48k.peephole import pattern |
6 | 8 |
|
7 | 9 |
|
@@ -38,35 +40,38 @@ def test_parse_comma_correctly(self): |
38 | 40 |
|
39 | 41 |
|
40 | 42 | class TestLinePattern(unittest.TestCase): |
| 43 | + def setUp(self) -> None: |
| 44 | + self.vars: Dict[str, str] = {} |
| 45 | + |
41 | 46 | def test_matches_parsed(self): |
42 | 47 | patt = pattern.LinePattern('push $1') |
43 | | - match = patt.match('push af') |
44 | | - self.assertEqual(match, {'$1': 'af'}) |
| 48 | + self.assertTrue(patt.match('push af', self.vars)) |
| 49 | + self.assertEqual({'$1': 'af'}, self.vars) |
45 | 50 |
|
46 | 51 | def test_no_match(self): |
47 | 52 | patt = pattern.LinePattern('push $1') |
48 | | - match = patt.match('pop af') |
49 | | - self.assertIsNone(match) |
| 53 | + self.assertFalse(patt.match('pop af', self.vars)) |
| 54 | + self.assertEqual({}, self.vars) |
50 | 55 |
|
51 | 56 | def test_double_match(self): |
52 | 57 | patt = pattern.LinePattern('push $1 $1') # three spaces |
53 | | - match = patt.match('push af af') # only two spaces |
54 | | - self.assertEqual(match, {'$1': 'af'}) |
| 58 | + self.assertTrue(patt.match('push af af', self.vars)) # only two spaces |
| 59 | + self.assertEqual({'$1': 'af'}, self.vars) |
55 | 60 |
|
56 | 61 | def test_match_two_patterns(self): |
57 | 62 | patt = pattern.LinePattern('$2 $1') |
58 | | - match = patt.match('push af') |
59 | | - self.assertEqual(match, {'$1': 'af', '$2': 'push'}) |
| 63 | + self.assertTrue(patt.match('push af', self.vars)) |
| 64 | + self.assertEqual({'$1': 'af', '$2': 'push'}, self.vars) |
60 | 65 |
|
61 | 66 | def test_match_two_patterns_twice(self): |
62 | 67 | patt = pattern.LinePattern('$2 $1 $2 $1') |
63 | | - match = patt.match('push af push af') |
64 | | - self.assertEqual(match, {'$1': 'af', '$2': 'push'}) |
| 68 | + self.assertTrue(patt.match('push af push af', self.vars)) |
| 69 | + self.assertEqual({'$1': 'af', '$2': 'push'}, self.vars) |
65 | 70 |
|
66 | 71 | def test_matches_empty_novars(self): |
67 | 72 | patt = pattern.LinePattern('push af') |
68 | | - match = patt.match('push af') |
69 | | - self.assertEqual(match, {}) |
| 73 | + self.assertTrue(patt.match('push af', self.vars)) |
| 74 | + self.assertEqual({}, self.vars) |
70 | 75 |
|
71 | 76 |
|
72 | 77 | class TestBlockPattern(unittest.TestCase): |
|
0 commit comments