comparison python/testc3.py @ 169:ee0d30533dae

Added more tests and improved the diagnostic update
author Windel Bouwman
date Sat, 23 Mar 2013 18:34:41 +0100
parents 49f1ab80d040
children 4348da5ca307
comparison
equal deleted inserted replaced
168:49f1ab80d040 169:ee0d30533dae
79 79
80 class testA(unittest.TestCase): 80 class testA(unittest.TestCase):
81 def setUp(self): 81 def setUp(self):
82 self.diag = ppci.DiagnosticsManager() 82 self.diag = ppci.DiagnosticsManager()
83 self.builder = c3.Builder(self.diag) 83 self.builder = c3.Builder(self.diag)
84 def testSrc(self):
85 self.builder.build(testsrc)
84 def testFunctArgs(self): 86 def testFunctArgs(self):
85 snippet = """ 87 snippet = """
86 package testargs; 88 package testargs;
87 function void t2(int a, double b) 89 function void t2(int a, double b)
88 { 90 {
115 assert len(self.diag.diags) == 3 117 assert len(self.diag.diags) == 3
116 assert self.diag.diags[0].loc.row == 8 118 assert self.diag.diags[0].loc.row == 8
117 assert self.diag.diags[1].loc.row == 9 119 assert self.diag.diags[1].loc.row == 9
118 assert self.diag.diags[2].loc.row == 10 120 assert self.diag.diags[2].loc.row == 10
119 assert ir == None 121 assert ir == None
122 def testEmpty(self):
123 snippet = """
124 package A
125 """
126 self.builder.build(snippet)
127 def testEmpty2(self):
128 snippet = ""
129 self.builder.build(snippet)
130 def testRedefine(self):
131 snippet = """
132 package test;
133 var int a;
134 var int b;
135 var int a;
136 """
137 self.diag.clear()
138 self.builder.build(snippet)
139 assert len(self.diag.diags) == 1
140 assert self.diag.diags[0].loc.row == 5
141 def testWhile(self):
142 snippet = """
143 package tstwhile;
144 var int a;
145 function void t()
146 {
147 var int i = 0;
148 while (i < 1054)
149 {
150 i = i + 3;
151 a = a + i
152 }
153 }
154 """
155 self.builder.build(snippet)
156 def testIf(self):
157 snippet = """
158 package tstIFF;
159 var int a;
160 function void t(int b)
161 {
162 a = 2;
163 if (a > b)
164 {
165 if (a > 1337)
166 {
167 b = 2;
168 }
169 }
170 else
171 {
172 b = 1;
173 }
174
175 return b;
176 }
177 """
178 self.builder.build(snippet)
120 179
121 if __name__ == '__main__': 180 if __name__ == '__main__':
122 do() 181 do()
123 unittest.main() 182 unittest.main()
124 183