Esempio n. 1
0
    def test_luthorFile1_teardown(self):
        lfile = LuthorFile(p1)
        lfile.parse()

        expected_teardown = CodeSegment('')
        actual_teardown = lfile.teardown

        self.assertEqual(actual_teardown, expected_teardown)
Esempio n. 2
0
    def test_luthorFile1_setup(self):
        lfile = LuthorFile(p1)
        lfile.parse()

        expected_setup = CodeSegment('''tokens_matched = 0''')
        actual_setup = lfile.setup

        self.assertEqual(actual_setup, expected_setup)
Esempio n. 3
0
    def test_luthorFile2_teardown(self):
        lfile = LuthorFile(p2)
        lfile.parse()

        expected_teardown = CodeSegment('''
            # Program Suffix
            print( "Total tokens matched: {}".format(tokens_matched))''')
        actual_teardown = lfile.teardown

        self.assertEqual(actual_teardown, expected_teardown)
Esempio n. 4
0
    def test_luthorFile2_setup(self):
        lfile = LuthorFile(p2)
        lfile.parse()

        expected_setup = CodeSegment('''
            # GLOBAL CONFIGURATION 
            tokens_matched  = 0    # A normal python variable
            ''')

        actual_setup = lfile.setup

        self.assertEqual(actual_setup, expected_setup)
Esempio n. 5
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))
Esempio n. 6
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))
Esempio n. 7
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))