Mercurial > lcfOS
comparison test/testc3.py @ 396:fb3c1f029b30
Added baselexer into c3 lexer
author | Windel Bouwman |
---|---|
date | Tue, 27 May 2014 22:19:32 +0200 |
parents | 6ae782a085e0 |
children |
comparison
equal
deleted
inserted
replaced
395:3b0c495e3008 | 396:fb3c1f029b30 |
---|---|
12 self.l = Lexer(diag) | 12 self.l = Lexer(diag) |
13 | 13 |
14 def testUnexpectedCharacter(self): | 14 def testUnexpectedCharacter(self): |
15 snippet = io.StringIO(""" var s \u6c34 """) | 15 snippet = io.StringIO(""" var s \u6c34 """) |
16 with self.assertRaises(ppci.CompilerError): | 16 with self.assertRaises(ppci.CompilerError): |
17 list(self.l.tokenize(snippet)) | 17 list(self.l.lex(snippet)) |
18 | 18 |
19 def check(self, snippet, toks): | 19 def check(self, snippet, toks): |
20 toks2 = list(tok.typ for tok in self.l.tokenize(io.StringIO(snippet))) | 20 toks2 = list(tok.typ for tok in self.l.lex(io.StringIO(snippet))) |
21 self.assertSequenceEqual(toks, toks2) | 21 self.assertSequenceEqual(toks, toks2) |
22 | 22 |
23 def testBlockComment(self): | 23 def testBlockComment(self): |
24 snippet = """ | 24 snippet = """ |
25 /* Demo */ | 25 /* Demo */ |
26 var int x = 0; | 26 var int x = 0; |
27 """ | 27 """ |
28 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END'] | 28 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'EOF'] |
29 self.check(snippet, toks) | 29 self.check(snippet, toks) |
30 | 30 |
31 def testBlockCommentMultiLine(self): | 31 def testBlockCommentMultiLine(self): |
32 snippet = """ | 32 snippet = """ |
33 /* Demo | 33 /* Demo |
34 bla1 | 34 bla1 |
35 bla2 | 35 bla2 |
36 */ | 36 */ |
37 var int x = 0; | 37 var int x = 0; |
38 """ | 38 """ |
39 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END'] | 39 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'EOF'] |
40 self.check(snippet, toks) | 40 self.check(snippet, toks) |
41 | 41 |
42 | 42 |
43 class testBuilder(unittest.TestCase): | 43 class testBuilder(unittest.TestCase): |
44 def setUp(self): | 44 def setUp(self): |
67 list(self.builder.build([io.StringIO(snippet)])) | 67 list(self.builder.build([io.StringIO(snippet)])) |
68 actualErrors = [err.row for err in self.diag.diags] | 68 actualErrors = [err.row for err in self.diag.diags] |
69 if rows != actualErrors: | 69 if rows != actualErrors: |
70 self.diag.printErrors() | 70 self.diag.printErrors() |
71 self.assertSequenceEqual(rows, actualErrors) | 71 self.assertSequenceEqual(rows, actualErrors) |
72 # self.assertFalse(all(ircode)) | |
73 | 72 |
74 def expectOK(self, snippet): | 73 def expectOK(self, snippet): |
75 """ Expect a snippet to be OK """ | 74 """ Expect a snippet to be OK """ |
76 ircode = list(self.builder.build(self.makeFileList(snippet))) | 75 ircode = list(self.builder.build(self.makeFileList(snippet))) |
77 if len(self.diag.diags) > 0: | 76 if len(self.diag.diags) > 0: |