Mercurial > lcfOS
comparison python/testc3.py @ 167:0b5b2ee6b435
Added 2 unit tests
author | Windel Bouwman |
---|---|
date | Fri, 22 Mar 2013 17:40:13 +0100 |
parents | da0087b82fbe |
children | 49f1ab80d040 |
comparison
equal
deleted
inserted
replaced
166:da0087b82fbe | 167:0b5b2ee6b435 |
---|---|
1 import c3 | 1 import c3 |
2 import time, ppci, x86, ir | 2 import time, ppci, x86, ir |
3 import unittest | |
3 | 4 |
4 testsrc = """package test; | 5 testsrc = """package test; |
5 | 6 |
6 var u32 c, d; | 7 var u32 c, d; |
7 var double e; | 8 var double e; |
8 var int f; | 9 var int f; |
9 | 10 |
10 const int A = 1337.; | 11 const int A = 1337; |
11 | 12 |
12 function void test1() | 13 function void test1() |
13 { | 14 { |
14 var u32 bdd; | 15 var u32 bdd; |
15 var int a = 10; | 16 var int a = 10; |
32 | 33 |
33 function int t2(u32 a, u32 b) | 34 function int t2(u32 a, u32 b) |
34 { | 35 { |
35 if (a > 0) | 36 if (a > 0) |
36 { | 37 { |
37 a = 2 + t2(a - 1); | 38 a = 2 + t2(a - 1, 1.0); |
38 } | 39 } |
39 | 40 |
40 return a + b; | 41 return a + b; |
41 } | 42 } |
42 | 43 |
75 | 76 |
76 def do(): | 77 def do(): |
77 diag = ppci.DiagnosticsManager() | 78 diag = ppci.DiagnosticsManager() |
78 c3compile(testsrc, diag) | 79 c3compile(testsrc, diag) |
79 | 80 |
80 do() | 81 class testA(unittest.TestCase): |
82 def setUp(self): | |
83 self.diag = ppci.DiagnosticsManager() | |
84 self.builder = c3.Builder(self.diag) | |
85 def testFunctArgs(self): | |
86 snippet = """ | |
87 package testargs; | |
88 function void t2(int a, double b) | |
89 { | |
90 t2(2, 2); | |
91 t2(2); | |
92 t2(1, 1.2); | |
93 } | |
94 """ | |
95 self.diag.clear() | |
96 ir = self.builder.build(snippet) | |
97 print(self.diag.diags) | |
81 | 98 |
99 def testExpressions(self): | |
100 snippet = """ | |
101 package test; | |
102 function void t(int a, double b) | |
103 { | |
104 var int a2; | |
105 var bool c; | |
106 | |
107 a2 = b * a; | |
108 c = a; | |
109 c = b > 1; | |
110 } | |
111 """ | |
112 self.diag.clear() | |
113 ir = self.builder.build(snippet) | |
114 print(self.diag.diags) | |
115 | |
116 if __name__ == '__main__': | |
117 do() | |
118 unittest.main() | |
119 | |
120 |