Mercurial > lcfOS
comparison test/testc3.py @ 293:6aa721e7b10b
Try to improve build sequence
author | Windel Bouwman |
---|---|
date | Thu, 28 Nov 2013 20:39:37 +0100 |
parents | 534b94b40aa8 |
children | 917eab04b8b7 |
comparison
equal
deleted
inserted
replaced
292:534b94b40aa8 | 293:6aa721e7b10b |
---|---|
64 | 64 |
65 | 65 |
66 """ | 66 """ |
67 | 67 |
68 class testLexer(unittest.TestCase): | 68 class testLexer(unittest.TestCase): |
69 def setUp(self): | |
70 diag = ppci.DiagnosticsManager() | |
71 self.l = c3.Lexer(diag) | |
72 | |
69 def testUnexpectedCharacter(self): | 73 def testUnexpectedCharacter(self): |
70 snippet = io.StringIO(""" var s \u6c34 """) | 74 snippet = io.StringIO(""" var s \u6c34 """) |
71 with self.assertRaises(ppci.CompilerError): | 75 with self.assertRaises(ppci.CompilerError): |
72 list(c3.lexer.tokenize(snippet)) | 76 list(self.l.tokenize(snippet)) |
77 | |
78 def check(self, snippet, toks): | |
79 toks2 = list(tok.typ for tok in self.l.tokenize(io.StringIO(snippet))) | |
80 self.assertSequenceEqual(toks, toks2) | |
73 | 81 |
74 def testBlockComment(self): | 82 def testBlockComment(self): |
75 snippet = io.StringIO(""" | 83 snippet = """ |
76 /* Demo */ | 84 /* Demo */ |
77 var int x = 0; | 85 var int x = 0; |
78 """) | 86 """ |
79 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END'] | 87 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END'] |
80 self.assertSequenceEqual([tok.typ for tok in c3.lexer.tokenize(snippet)], toks) | 88 self.check(snippet, toks) |
81 | 89 |
82 def testBlockCommentMultiLine(self): | 90 def testBlockCommentMultiLine(self): |
83 snippet = io.StringIO(""" | 91 snippet = """ |
84 /* Demo | 92 /* Demo |
85 bla1 | 93 bla1 |
86 bla2 | 94 bla2 |
87 */ | 95 */ |
88 var int x = 0; | 96 var int x = 0; |
89 """) | 97 """ |
90 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END'] | 98 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END'] |
91 self.assertSequenceEqual([tok.typ for tok in c3.lexer.tokenize(snippet)], toks) | 99 self.check(snippet, toks) |
92 | 100 |
93 | 101 |
94 class testBuilder(unittest.TestCase): | 102 class testBuilder(unittest.TestCase): |
95 def setUp(self): | 103 def setUp(self): |
96 self.diag = ppci.DiagnosticsManager() | 104 self.diag = ppci.DiagnosticsManager() |
139 import p1; | 147 import p1; |
140 var p1.A a; | 148 var p1.A a; |
141 """ | 149 """ |
142 self.expectOK([io.StringIO(s) for s in (p1, p2)]) | 150 self.expectOK([io.StringIO(s) for s in (p1, p2)]) |
143 | 151 |
152 def testPackageNotExists(self): | |
153 p1 = """module p1; | |
154 import p23; | |
155 """ | |
156 self.expectOK([io.StringIO(p1)]) | |
157 | |
144 def testFunctArgs(self): | 158 def testFunctArgs(self): |
145 snippet = """ | 159 snippet = """ |
146 module testargs; | 160 module testargs; |
147 function void t2(int a, double b) | 161 function void t2(int a, double b) |
148 { | 162 { |
289 function void t() | 303 function void t() |
290 { | 304 { |
291 var struct {int x, y;} a; | 305 var struct {int x, y;} a; |
292 a.x = 2; | 306 a.x = 2; |
293 a.y = a.x + 2; | 307 a.y = a.x + 2; |
308 } | |
309 """ | |
310 self.expectOK(snippet) | |
311 | |
312 def testStructCall(self): | |
313 snippet = """ | |
314 module teststruct1; | |
315 function void t() | |
316 { | |
317 var struct {int x, y;} a; | |
318 a.b.c(9); | |
294 } | 319 } |
295 """ | 320 """ |
296 self.expectOK(snippet) | 321 self.expectOK(snippet) |
297 | 322 |
298 def testPointerType1(self): | 323 def testPointerType1(self): |