Mercurial > lcfOS
comparison test/testc3.py @ 306:b145f8e6050b
Start on c3 rewrite
author | Windel Bouwman |
---|---|
date | Mon, 09 Dec 2013 19:00:21 +0100 |
parents | be7f60545368 |
children | e609d5296ee9 |
comparison
equal
deleted
inserted
replaced
305:0615b5308710 | 306:b145f8e6050b |
---|---|
43 def setUp(self): | 43 def setUp(self): |
44 self.diag = ppci.DiagnosticsManager() | 44 self.diag = ppci.DiagnosticsManager() |
45 self.builder = Builder(self.diag, SimpleTarget()) | 45 self.builder = Builder(self.diag, SimpleTarget()) |
46 self.diag.clear() | 46 self.diag.clear() |
47 | 47 |
48 def makeFileList(self, snippet): | |
49 """ Try to make a list with opened files """ | |
50 if type(snippet) is list: | |
51 l2 = [] | |
52 for s in snippet: | |
53 if type(s) is str: | |
54 l2.append(io.StringIO(s)) | |
55 else: | |
56 l2.append(s) | |
57 return l2 | |
58 else: | |
59 return [io.StringIO(snippet)] | |
60 | |
48 def expectErrors(self, snippet, rows): | 61 def expectErrors(self, snippet, rows): |
49 """ Helper to test for expected errors on rows """ | 62 """ Helper to test for expected errors on rows """ |
50 ircode = list(self.builder.build([io.StringIO(snippet)])) | 63 ircode = list(self.builder.build([io.StringIO(snippet)])) |
51 actualErrors = [err.row for err in self.diag.diags] | 64 actualErrors = [err.row for err in self.diag.diags] |
52 if rows != actualErrors: | 65 if rows != actualErrors: |
53 self.diag.printErrors(snippet) | 66 self.diag.printErrors() |
54 self.assertSequenceEqual(rows, actualErrors) | 67 self.assertSequenceEqual(rows, actualErrors) |
55 # self.assertFalse(all(ircode)) | 68 # self.assertFalse(all(ircode)) |
56 | 69 |
57 def expectOK(self, snippet): | 70 def expectOK(self, snippet): |
58 if type(snippet) is list: | 71 """ Expect a snippet to be OK """ |
59 ircode = self.builder.build(snippet) | 72 ircode = list(self.builder.build(self.makeFileList(snippet))) |
60 else: | 73 if len(self.diag.diags) > 0: |
61 ircode = self.builder.build([io.StringIO(snippet)]) | 74 self.diag.printErrors() |
62 if not ircode: | |
63 self.diag.printErrors(snippet) | |
64 self.assertTrue(all(ircode)) | 75 self.assertTrue(all(ircode)) |
76 self.assertEqual(0, len(self.diag.diags)) | |
65 return ircode | 77 return ircode |
66 | 78 |
67 def testPackage(self): | 79 def testPackage(self): |
68 p1 = """module p1; | 80 p1 = """module p1; |
69 type int A; | 81 type int A; |
70 """ | 82 """ |
71 p2 = """module p2; | 83 p2 = """module p2; |
72 import p1; | 84 import p1; |
73 var A b; | 85 var p1.A b; |
74 """ | 86 """ |
75 self.expectOK([io.StringIO(s) for s in (p1, p2)]) | 87 self.expectOK([p1, p2]) |
76 | 88 |
77 def testPackageMutual(self): | 89 def testPackageMutual(self): |
78 p1 = """module p1; | 90 p1 = """module p1; |
79 import p2; | 91 import p2; |
80 type int A; | 92 type int A; |
82 """ | 94 """ |
83 p2 = """module p2; | 95 p2 = """module p2; |
84 import p1; | 96 import p1; |
85 var p1.A a; | 97 var p1.A a; |
86 """ | 98 """ |
87 self.expectOK([io.StringIO(s) for s in (p1, p2)]) | 99 self.expectOK([p1, p2]) |
88 | 100 |
89 def testPackageNotExists(self): | 101 def testPackageNotExists(self): |
90 p1 = """module p1; | 102 p1 = """module p1; |
91 import p23; | 103 import p23; |
92 """ | 104 """ |
93 self.expectOK([io.StringIO(p1)]) | 105 self.expectErrors(p1, [0]) |
94 | 106 |
95 def testFunctArgs(self): | 107 def testFunctArgs(self): |
96 snippet = """ | 108 snippet = """ |
97 module testargs; | 109 module testargs; |
98 function void t2(int a, double b) | 110 function void t2(int a, double b) |
175 snippet = """ | 187 snippet = """ |
176 module tstwhile; | 188 module tstwhile; |
177 var int a; | 189 var int a; |
178 function void t() | 190 function void t() |
179 { | 191 { |
180 var int i = 0; | 192 var int i; |
193 i = 0; | |
181 while (i < 1054) | 194 while (i < 1054) |
182 { | 195 { |
183 i = i + 3; | 196 i = i + 3; |
184 a = a + i; | 197 a = a + i; |
185 } | 198 } |