Mercurial > hg > orthanc-stone
annotate Resources/CodeGeneration/stonegentool_test.py @ 494:fc17251477d6 bgo-commands-codegen
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
author | bgo-osimis |
---|---|
date | Sat, 23 Feb 2019 10:18:13 +0100 |
parents | 6fbf2eae7c88 |
children | 1dbf2d9ed1e4 |
rev | line source |
---|---|
491 | 1 # |
2 # 1 2 3 4 5 6 7 8 | |
3 # 345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
4 # | |
5 | |
474 | 6 from stonegentool import \ |
491 | 7 EatToken,SplitListOfTypes,ParseTemplateType,ProcessSchema, \ |
8 CheckSchemaSchema,LoadSchema,trim,ComputeRequiredDeclarationOrder, \ | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
493
diff
changeset
|
9 GetTemplatingDictFromSchemaFilename,MakeTemplate,MakeTemplateFromFile |
471 | 10 import unittest |
473 | 11 import os |
485
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
12 import re |
491 | 13 import pprint |
14 from jinja2 import Template | |
15 | |
485
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
16 def RemoveDateTimeLine(s : str): |
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
17 # regex are non-multiline by default, and $ does NOT match the end of the line |
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
18 s2 = re.sub(r"^// autogenerated by stonegentool on .*\n","",s) |
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
19 return s2 |
471 | 20 |
21 class TestStonegentool(unittest.TestCase): | |
22 def test_EatToken_empty(self): | |
23 c = r"" | |
24 a,b = EatToken(c) | |
25 self.assertEqual(a,r"") | |
26 self.assertEqual(b,r"") | |
27 | |
28 def test_EatToken_simpleNonTemplate(self): | |
29 c = r"int32" | |
30 a,b = EatToken(c) | |
31 self.assertEqual(a,r"int32") | |
32 self.assertEqual(b,r"") | |
33 | |
34 def test_EatToken_simpleTemplate(self): | |
35 c = r"vector<string>" | |
36 a,b = EatToken(c) | |
37 self.assertEqual(a,r"vector<string>") | |
38 self.assertEqual(b,r"") | |
39 | |
40 def test_EatToken_complexTemplate(self): | |
41 c = r"vector<map<int64,string>>,vector<map<int32,string>>" | |
42 a,b = EatToken(c) | |
43 self.assertEqual(a,r"vector<map<int64,string>>") | |
44 self.assertEqual(b,r"vector<map<int32,string>>") | |
45 | |
472 | 46 def test_EatToken_complexTemplates(self): |
471 | 47 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>" |
48 a,b = EatToken(c) | |
49 self.assertEqual(a,r"vector<map<vector<string>,map<int32,string>>>") | |
50 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>") | |
51 a,b = EatToken(b) | |
52 self.assertEqual(a,r"map<int32,string>") | |
53 self.assertEqual(b,r"map<map<int32,string>,string>") | |
54 | |
473 | 55 def test_SplitListOfTypes(self): |
56 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>" | |
57 lot = SplitListOfTypes(c) | |
58 self.assertEqual(3,len(lot)) | |
59 self.assertEqual("vector<map<vector<string>,map<int32,string>>>",lot[0]) | |
60 self.assertEqual("map<int32,string>",lot[1]) | |
61 self.assertEqual("map<map<int32,string>,string>",lot[2]) | |
62 | |
63 def test_SplitListOfTypes_bogus(self): | |
64 c = r"vector<map<vector<string>,map<int32,string>>,map<int32,string>,map<map<int32,string>,string" | |
65 self.assertRaises(Exception,SplitListOfTypes,c) # the argument c must be passed to assertRaises, not as a normal call of SplitListOfTypes | |
66 | |
67 def test_ParseTemplateType_true(self): | |
68 c = "map<vector<map<int,vector<string>>>,map<vector<int>,vector<string>>>" | |
69 (ok,a,b) = ParseTemplateType(c) | |
70 self.assertEqual(ok,True) | |
71 self.assertEqual(a,"map") | |
72 self.assertEqual(b,["vector<map<int,vector<string>>>","map<vector<int>,vector<string>>"]) | |
73 | |
74 (ok2,a2,b2) = ParseTemplateType(b[0]) | |
75 self.assertEqual(ok2,True) | |
76 self.assertEqual(a2,"vector") | |
77 self.assertEqual(b2,["map<int,vector<string>>"]) | |
78 | |
79 (ok3,a3,b3) = ParseTemplateType(b[1]) | |
80 self.assertEqual(ok3,True) | |
81 self.assertEqual(a3,"map") | |
82 self.assertEqual(b3,["vector<int>","vector<string>"]) | |
83 | |
84 (ok4,a4,b4) = ParseTemplateType(b2[0]) | |
85 self.assertEqual(ok4,True) | |
86 self.assertEqual(a4,"map") | |
87 self.assertEqual(b4,["int","vector<string>"]) | |
88 | |
89 def test_ParseSchema(self): | |
491 | 90 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') |
473 | 91 obj = LoadSchema(fn) |
491 | 92 # we're happy if it does not crash :) |
473 | 93 CheckSchemaSchema(obj) |
94 | |
491 | 95 def test_ComputeRequiredDeclarationOrder(self): |
96 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') | |
473 | 97 obj = LoadSchema(fn) |
491 | 98 genOrder: str = ComputeRequiredDeclarationOrder(obj) |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
99 self.assertEqual(5,len(genOrder)) |
491 | 100 self.assertEqual("A",genOrder[0]) |
101 self.assertEqual("B",genOrder[1]) | |
102 self.assertEqual("C",genOrder[2]) | |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
103 self.assertEqual("Message1",genOrder[3]) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
104 self.assertEqual("Message2",genOrder[4]) |
473 | 105 |
491 | 106 # def test_GeneratePreambleEnumerationAndStructs(self): |
107 # fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') | |
108 # obj = LoadSchema(fn) | |
109 # (_,genc,_) = ProcessSchema(obj) | |
110 | |
111 def test_genEnums(self): | |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
112 self.maxDiff = None |
491 | 113 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') |
474 | 114 obj = LoadSchema(fn) |
491 | 115 genOrder: str = ComputeRequiredDeclarationOrder(obj) |
116 processedSchema = ProcessSchema(obj, genOrder) | |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
117 self.assertTrue('rootName' in processedSchema) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
118 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
119 structs = {} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
120 for v in processedSchema['structs']: |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
121 structs[v['name']] = v |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
122 enums = {} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
123 for v in processedSchema['enums']: |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
124 enums[v['name']] = v |
473 | 125 |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
126 self.assertTrue('C' in structs) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
127 self.assertTrue('someBs' in structs['C']['fields']) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
128 self.assertTrue('CrispType' in enums) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
129 self.assertTrue('Message1' in structs) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
130 message1Struct = structs['Message1'] |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
131 self.assertDictEqual(message1Struct, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
132 { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
133 'name':'Message1', |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
134 'fields': { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
135 'a': 'int32', |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
136 'b': 'string', |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
137 'c': 'EnumMonth0', |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
138 'd': 'bool' |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
139 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
140 }) |
485
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
141 |
491 | 142 def test_GenerateTypeScriptEnums(self): |
143 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') | |
144 tdico = GetTemplatingDictFromSchemaFilename(fn) | |
145 template = Template(""" // end of generic methods | |
146 {% for enum in enums%} export enum {{enum['name']}} { | |
147 {% for key in enum['fields']%} {{key}}, | |
148 {%endfor%} }; | |
149 | |
150 {%endfor%}""") | |
151 renderedCode = template.render(**tdico) | |
152 renderedCodeRef = """ // end of generic methods | |
153 export enum MovieType { | |
154 RomCom, | |
485
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
155 Horror, |
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
156 ScienceFiction, |
491 | 157 Vegetables, |
158 }; | |
485
772516adcbf6
Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents:
482
diff
changeset
|
159 |
491 | 160 export enum CrispType { |
486
8e40355a172b
Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents:
485
diff
changeset
|
161 SaltAndPepper, |
8e40355a172b
Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents:
485
diff
changeset
|
162 CreamAndChives, |
8e40355a172b
Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents:
485
diff
changeset
|
163 Paprika, |
491 | 164 Barbecue, |
165 }; | |
486
8e40355a172b
Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents:
485
diff
changeset
|
166 |
8e40355a172b
Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents:
485
diff
changeset
|
167 """ |
491 | 168 self.assertEqual(renderedCodeRef,renderedCode) |
486
8e40355a172b
Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents:
485
diff
changeset
|
169 |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
170 def test_GenerateCplusplusEnums(self): |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
171 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
172 tdico = GetTemplatingDictFromSchemaFilename(fn) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
173 template = Template(""" // end of generic methods |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
174 {% for enum in enums%} enum {{enum['name']}} { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
175 {% for key in enum['fields']%} {{key}}, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
176 {%endfor%} }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
177 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
178 {%endfor%}""") |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
179 renderedCode = template.render(**tdico) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
180 renderedCodeRef = """ // end of generic methods |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
181 enum MovieType { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
182 RomCom, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
183 Horror, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
184 ScienceFiction, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
185 Vegetables, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
186 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
187 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
188 enum CrispType { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
189 SaltAndPepper, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
190 CreamAndChives, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
191 Paprika, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
192 Barbecue, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
193 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
194 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
195 """ |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
196 self.assertEqual(renderedCodeRef,renderedCode) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
197 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
198 def test_generateTsStructType(self): |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
199 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
200 tdico = GetTemplatingDictFromSchemaFilename(fn) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
201 ref = """ export class Message1 { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
202 a: number; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
203 b: string; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
204 c: EnumMonth0; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
205 d: boolean; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
206 public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
207 let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
208 container['type'] = 'VsolStuff.Message1'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
209 container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
210 return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
211 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
212 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
213 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
214 export class Message2 { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
215 toto: string; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
216 tata: Message1[]; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
217 tutu: string[]; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
218 titi: Map<string, string>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
219 lulu: Map<string, Message1>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
220 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
221 constructor() |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
222 { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
223 this.tata = new Array<Message1>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
224 this.tutu = new Array<string>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
225 this.titi = new Map<string, string>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
226 this.lulu = new Map<string, Message1>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
227 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
228 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
229 public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
230 let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
231 container['type'] = 'VsolStuff.Message2'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
232 container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
233 return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
234 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
235 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
236 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
237 """ |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
238 # template = MakeTemplate(""" // end of generic methods |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
239 # {% for struct in struct%} export class {{struct['name']}} { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
240 # {% for key in struct['fields']%} {{key}}:{{struct['fields'][key]}}, |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
241 # {% endfor %} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
242 # constructor() { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
243 # {% for key in struct['fields']%} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
244 # {% if NeedsConstruction(struct['fields']['key'])} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
245 # {{key}} = new {{CanonToTs(struct['fields']['key'])}}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
246 # {% end if %} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
247 # {% endfor %} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
248 # } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
249 # {% endfor %} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
250 # public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
251 # let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
252 # container['type'] = '{{rootName}}.{{struct['name']}}'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
253 # container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
254 # return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
255 # } };""") |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
256 template = MakeTemplate(""" // end of generic methods |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
257 {% for struct in structs%} export class {{struct['name']}} { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
258 {% for key in struct['fields']%} {{key}}:{{CanonToTs(struct['fields'][key])}}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
259 {% endfor %} |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
260 constructor() { |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
493
diff
changeset
|
261 {% for key in struct['fields']%} this.{{key}} = new {{CanonToTs(struct['fields'][key])}}(); |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
262 {% endfor %} } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
263 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
264 public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
265 let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
266 container['type'] = '{{rootName}}.{{struct['name']}}'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
267 container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
268 return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
269 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
270 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
271 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
272 {% endfor %}""") |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
273 renderedCode = template.render(**tdico) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
274 renderedCodeRef = """ // end of generic methods |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
275 export class A { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
276 someStrings:Array<string>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
277 someInts2:Array<number>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
278 movies:Array<MovieType>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
279 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
280 constructor() { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
281 someStrings = new Array<string>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
282 someInts2 = new Array<number>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
283 movies = new Array<MovieType>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
284 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
285 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
286 public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
287 let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
288 container['type'] = 'VsolMessages.A'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
289 container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
290 return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
291 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
292 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
293 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
294 export class B { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
295 someAs:Array<A>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
296 someInts:Array<number>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
297 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
298 constructor() { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
299 someAs = new Array<A>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
300 someInts = new Array<number>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
301 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
302 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
303 public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
304 let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
305 container['type'] = 'VsolMessages.B'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
306 container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
307 return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
308 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
309 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
310 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
311 export class C { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
312 someBs:Array<B>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
313 ddd:Array<string>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
314 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
315 constructor() { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
316 someBs = new Array<B>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
317 ddd = new Array<string>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
318 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
319 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
320 public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
321 let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
322 container['type'] = 'VsolMessages.C'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
323 container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
324 return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
325 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
326 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
327 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
328 export class Message1 { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
329 a:number; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
330 b:string; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
331 c:EnumMonth0; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
332 d:boolean; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
333 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
334 constructor() { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
335 a = new number(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
336 b = new string(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
337 c = new EnumMonth0(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
338 d = new boolean(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
339 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
340 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
341 public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
342 let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
343 container['type'] = 'VsolMessages.Message1'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
344 container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
345 return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
346 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
347 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
348 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
349 export class Message2 { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
350 toto:string; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
351 tata:Array<Message1>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
352 tutu:Array<string>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
353 titi:Map<string, string>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
354 lulu:Map<string, Message1>; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
355 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
356 constructor() { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
357 toto = new string(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
358 tata = new Array<Message1>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
359 tutu = new Array<string>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
360 titi = new Map<string, string>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
361 lulu = new Map<string, Message1>(); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
362 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
363 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
364 public StoneSerialize(): string { |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
365 let container: object = {}; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
366 container['type'] = 'VsolMessages.Message2'; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
367 container['value'] = this; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
368 return JSON.stringify(container); |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
369 } |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
370 }; |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
371 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
372 """ |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
373 # print(renderedCode) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
374 self.maxDiff = None |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
375 self.assertEqual(renderedCodeRef, renderedCode) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
376 |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
377 def test_generateWholeTsFile(self): |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
493
diff
changeset
|
378 schemaFile = \ |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
493
diff
changeset
|
379 os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
380 tdico = GetTemplatingDictFromSchemaFilename(schemaFile) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
493
diff
changeset
|
381 tsTemplateFile = \ |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
493
diff
changeset
|
382 os.path.join(os.path.dirname(__file__), 'template.in.ts') |
493
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
383 template = MakeTemplateFromFile(tsTemplateFile) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
384 renderedCode = template.render(**tdico) |
6fbf2eae7c88
All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents:
491
diff
changeset
|
385 print(renderedCode) |
473 | 386 |
474 | 387 def test_GenerateTypeScriptHandlerInterface(self): |
388 pass | |
389 | |
390 def test_GenerateCppHandlerInterface(self): | |
391 pass | |
392 | |
393 def test_GenerateTypeScriptDispatcher(self): | |
394 pass | |
395 | |
396 def test_GenerateCppDispatcher(self): | |
397 pass | |
473 | 398 |
472 | 399 # def test(self): |
471 | 400 # s = 'hello world' |
401 # self.assertEqual(s.split(), ['hello', 'world']) | |
402 # # check that s.split fails when the separator is not a string | |
403 # with self.assertRaises(TypeError): | |
404 # s.split(2) | |
405 | |
406 if __name__ == '__main__': | |
474 | 407 unittest.main() |
486
8e40355a172b
Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents:
485
diff
changeset
|
408 |