aboutsummaryrefslogtreecommitdiff
path: root/antlr-3.4/runtime/Python/tests/t020fuzzy.py
blob: 773aa2e8c33534e71cf734a4f374e80342df91d8 (plain)
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()