def test_LuthorREPattern__eq__3(self): rep1 = LuthorREPattern( 'testname', 'testpattern', CodeSegment(''' for i in range(10): print(i) ''')) rep2 = LuthorREPattern( 'testname', 'testpattern', CodeSegment(''' for i in range(10): print(i)''')) self.assertEqual(rep1, rep2)
def test_luthorFile2_patterns1(self): lfile = LuthorFile(p2) lfile.parse() expected_patterns = [ LuthorREPattern( 'int_pattern', r'''\d+''', CodeSegment(''' RESULT = IntToken(MATCHED) tokens_matched += 1''')), LuthorREPattern( 'str_pattern', r'''([\"]|[^\"])+''', CodeSegment(''' RESULT = StrToken(MATCHED) tokens_matched += 1 ''')), LuthorREPattern('ws_pattern', r'''\s''', None) ] actual_patterns = lfile.patterns self.assertEqual(len(actual_patterns), len(expected_patterns))
def test_luthorFile1_patterns1(self): lfile = LuthorFile(p1) lfile.parse() expected_patterns = [ LuthorREPattern( 'int_pattern', r'''\d+''', CodeSegment(''' RESULT = IntToken(MATCHED) tokens_matched += 1''')) ] actual_patterns = lfile.patterns self.assertEqual(len(actual_patterns), len(expected_patterns))
def test_luthorFile2_patterns2(self): lfile = LuthorFile(p2) lfile.parse() expected_patterns = [ LuthorREPattern( 'int_pattern', r'''\d+''', CodeSegment(''' RESULT = IntToken(MATCHED) tokens_matched += 1''')) ] actual_patterns = lfile.patterns for exp, act in zip(expected_patterns, actual_patterns): self.assertEqual( act, exp, """ '{}' == '{}': {}, '{}' == '{}': {}, '{}' == '{}': {}""".format(act.name, exp.name, act.name == exp.name, act.pattern, exp.pattern, act.pattern == exp.pattern, act.code, exp.code, act.code == exp.code))
def test_LuthorREPattern__eq__2(self): rep1 = LuthorREPattern('testname', 'testpattern', CodeSegment('')) rep2 = LuthorREPattern('testname', 'testpattern', CodeSegment('')) self.assertEqual(rep1, rep2)