Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/stonegentool_test.py @ 485:772516adcbf6 bgo-commands-codegen
Ongoing work on code generation. Enums and structs OK in ts and cpp
author | bgo-osimis |
---|---|
date | Fri, 15 Feb 2019 12:07:09 +0100 |
parents | f58fe38c8c04 |
children | 8e40355a172b |
comparison
equal
deleted
inserted
replaced
482:f58fe38c8c04 | 485:772516adcbf6 |
---|---|
1 from stonegentool import \ | 1 from stonegentool import \ |
2 EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema,ProcessSchema | 2 EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema,ProcessSchema |
3 import unittest | 3 import unittest |
4 import os | 4 import os |
5 import re | |
6 | |
7 def RemoveDateTimeLine(s : str): | |
8 # regex are non-multiline by default, and $ does NOT match the end of the line | |
9 s2 = re.sub(r"^// autogenerated by stonegentool on .*\n","",s) | |
10 return s2 | |
5 | 11 |
6 class TestStonegentool(unittest.TestCase): | 12 class TestStonegentool(unittest.TestCase): |
7 def test_EatToken_empty(self): | 13 def test_EatToken_empty(self): |
8 c = r"" | 14 c = r"" |
9 a,b = EatToken(c) | 15 a,b = EatToken(c) |
87 self.assertRaises(Exception,CheckSchemaSchema,obj) | 93 self.assertRaises(Exception,CheckSchemaSchema,obj) |
88 | 94 |
89 def test_GenOrderQueue(self): | 95 def test_GenOrderQueue(self): |
90 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') | 96 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') |
91 obj = LoadSchema(fn) | 97 obj = LoadSchema(fn) |
92 genOrderQueue, outputStreams = ProcessSchema(obj) | 98 genOrderQueue:str |
99 _, _, genOrderQueue = ProcessSchema(obj) | |
93 self.assertEqual(3,len(genOrderQueue)) | 100 self.assertEqual(3,len(genOrderQueue)) |
94 self.assertEqual("A",genOrderQueue[0]) | 101 self.assertEqual("A",genOrderQueue[0]) |
95 self.assertEqual("B",genOrderQueue[0]) | 102 self.assertEqual("B",genOrderQueue[1]) |
96 self.assertEqual("C",genOrderQueue[0]) | 103 self.assertEqual("C",genOrderQueue[2]) |
97 #print(f"genOrderQueue = {genOrderQueue}") | |
98 #print("") | |
99 | 104 |
100 def test_GenerateTypeScriptEnumeration(self): | 105 def test_GenerateTypeScriptEnumeration(self): |
101 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') | 106 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') |
102 obj = LoadSchema(fn) | 107 obj = LoadSchema(fn) |
103 (rootName,outputStreams) = ProcessSchema(obj) | 108 (_,outputStreams,_) = ProcessSchema(obj) |
109 | |
110 tsRef = """// autogenerated by stonegentool on Fri Feb 15 07:36:51 2019 | |
111 enum MovieType | |
112 { | |
113 Romcom, | |
114 Horror, | |
115 ScienceFiction, | |
116 Vegetables | |
117 }; | |
118 | |
119 class A | |
120 { | |
121 public Array<string> someStrings; | |
122 public Array<number> someInts2; | |
123 }; | |
124 | |
125 class B | |
126 { | |
127 public Array<A> someAs; | |
128 public Array<number> someInts; | |
129 }; | |
130 | |
131 class C | |
132 { | |
133 public Array<B> someBs; | |
134 public Array<D> ddd; | |
135 }; | |
136 | |
137 """ | |
138 tsRef = RemoveDateTimeLine(tsRef) | |
139 tsActual = RemoveDateTimeLine(outputStreams['ts'].getvalue()) | |
140 | |
141 self.assertEqual(tsActual,tsRef) | |
142 | |
143 cppRef="""// autogenerated by stonegentool on Fri Feb 15 07:36:51 2019 | |
144 #include <cstdint> | |
145 #include <string> | |
146 #include <vector> | |
147 #include <map> | |
148 enum MovieType | |
149 { | |
150 Romcom, | |
151 Horror, | |
152 ScienceFiction, | |
153 Vegetables | |
154 }; | |
155 | |
156 struct A | |
157 { | |
158 std::vector<string> someStrings; | |
159 std::vector<int32_t> someInts2; | |
160 }; | |
161 | |
162 struct B | |
163 { | |
164 std::vector<A> someAs; | |
165 std::vector<int32_t> someInts; | |
166 }; | |
167 | |
168 struct C | |
169 { | |
170 std::vector<B> someBs; | |
171 std::vector<D> ddd; | |
172 }; | |
173 | |
174 """ | |
175 cppRef = RemoveDateTimeLine(cppRef) | |
176 cppActual = RemoveDateTimeLine(outputStreams['cpp'].getvalue()) | |
177 | |
178 self.assertEqual(cppActual,cppRef) | |
104 pass | 179 pass |
105 | 180 |
106 def test_GenerateCppEnumeration(self): | 181 def test_GenerateCppEnumeration(self): |
107 pass | 182 pass |
108 | 183 |
130 # # check that s.split fails when the separator is not a string | 205 # # check that s.split fails when the separator is not a string |
131 # with self.assertRaises(TypeError): | 206 # with self.assertRaises(TypeError): |
132 # s.split(2) | 207 # s.split(2) |
133 | 208 |
134 if __name__ == '__main__': | 209 if __name__ == '__main__': |
135 print("") | |
136 unittest.main() | 210 unittest.main() |