예제 #1
0
    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)
예제 #2
0
    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))
예제 #3
0
    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))
예제 #4
0
    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))
예제 #5
0
 def test_LuthorREPattern__eq__2(self):
     rep1 = LuthorREPattern('testname', 'testpattern', CodeSegment(''))
     rep2 = LuthorREPattern('testname', 'testpattern', CodeSegment(''))
     self.assertEqual(rep1, rep2)