tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import sys
import antlr3
import testbase
import unittest
from cStringIO import StringIO
import difflib
 
class t020fuzzy(testbase.ANTLRTest):
    def setUp(self):
        self.compileGrammar('t020fuzzyLexer.g')
        
 
    def testValid(self):
        inputPath = os.path.splitext(__file__)[0] + '.input'
        stream = antlr3.StringStream(open(inputPath).read())
        lexer = self.getLexer(stream)
 
        while True:
            token = lexer.nextToken()
            if token.type == antlr3.EOF:
                break
 
 
        output = lexer.output.getvalue()
 
        outputPath = os.path.splitext(__file__)[0] + '.output'
        testOutput = open(outputPath).read()
 
        success = (output == testOutput)
        if not success:
            d = difflib.Differ()
            r = d.compare(output.splitlines(1), testOutput.splitlines(1))
            self.fail(
                ''.join([l.encode('ascii', 'backslashreplace') for l in r])
                )
 
 
if __name__ == '__main__':
    unittest.main()