annotate Resources/CodeGeneration/stonegentool_test.py @ 486:8e40355a172b bgo-commands-codegen

Unit tests OK for preambles, enums and structs in both TS and C++
author bgo-osimis
date Fri, 15 Feb 2019 14:30:26 +0100
parents 772516adcbf6
children f6b7f113cf27
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
1 from stonegentool import \
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
2 EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema,ProcessSchema
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
3 import unittest
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
4 import os
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
5 import re
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
6
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
7 def RemoveDateTimeLine(s : str):
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
8 # 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
9 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
10 return s2
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
11
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
12 class TestStonegentool(unittest.TestCase):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
13 def test_EatToken_empty(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
14 c = r""
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
15 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
16 self.assertEqual(a,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
17 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
18
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
19 def test_EatToken_simpleNonTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
20 c = r"int32"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
21 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
22 self.assertEqual(a,r"int32")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
23 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
24
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
25 def test_EatToken_simpleTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
26 c = r"vector<string>"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
27 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
28 self.assertEqual(a,r"vector<string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
29 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
30
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
31 def test_EatToken_complexTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
32 c = r"vector<map<int64,string>>,vector<map<int32,string>>"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
33 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
34 self.assertEqual(a,r"vector<map<int64,string>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
35 self.assertEqual(b,r"vector<map<int32,string>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
36
472
3db3289e1c25 Ongoing codegen work
bgo-osimis
parents: 471
diff changeset
37 def test_EatToken_complexTemplates(self):
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
38 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
39 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
40 self.assertEqual(a,r"vector<map<vector<string>,map<int32,string>>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
41 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
42 a,b = EatToken(b)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
43 self.assertEqual(a,r"map<int32,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
44 self.assertEqual(b,r"map<map<int32,string>,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
45
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
46 def test_SplitListOfTypes(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
47 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
48 lot = SplitListOfTypes(c)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
49 self.assertEqual(3,len(lot))
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
50 self.assertEqual("vector<map<vector<string>,map<int32,string>>>",lot[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
51 self.assertEqual("map<int32,string>",lot[1])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
52 self.assertEqual("map<map<int32,string>,string>",lot[2])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
53
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
54 def test_SplitListOfTypes_bogus(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
55 c = r"vector<map<vector<string>,map<int32,string>>,map<int32,string>,map<map<int32,string>,string"
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
56 self.assertRaises(Exception,SplitListOfTypes,c) # the argument c must be passed to assertRaises, not as a normal call of SplitListOfTypes
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
57
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
58 def test_ParseTemplateType_true(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
59 c = "map<vector<map<int,vector<string>>>,map<vector<int>,vector<string>>>"
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
60 (ok,a,b) = ParseTemplateType(c)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
61 self.assertEqual(ok,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
62 self.assertEqual(a,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
63 self.assertEqual(b,["vector<map<int,vector<string>>>","map<vector<int>,vector<string>>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
64
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
65 (ok2,a2,b2) = ParseTemplateType(b[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
66 self.assertEqual(ok2,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
67 self.assertEqual(a2,"vector")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
68 self.assertEqual(b2,["map<int,vector<string>>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
69
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
70 (ok3,a3,b3) = ParseTemplateType(b[1])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
71 self.assertEqual(ok3,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
72 self.assertEqual(a3,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
73 self.assertEqual(b3,["vector<int>","vector<string>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
74
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
75 (ok4,a4,b4) = ParseTemplateType(b2[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
76 self.assertEqual(ok4,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
77 self.assertEqual(a4,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
78 self.assertEqual(b4,["int","vector<string>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
79
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
80 def test_ParseSchema(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
81 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
82 obj = LoadSchema(fn)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
83 # we're happy if it does not crash
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
84 CheckSchemaSchema(obj)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
85
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
86 def test_ParseSchema_bogus_json(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
87 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_json.jsonc')
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
88 self.assertRaises(Exception,LoadSchema,fn)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
89
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
90 def test_ParseSchema_bogus_schema(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
91 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_schema.jsonc')
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
92 obj = LoadSchema(fn)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
93 self.assertRaises(Exception,CheckSchemaSchema,obj)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
94
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
95 def test_GenOrderQueue(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
96 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
97 obj = LoadSchema(fn)
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
98 genOrderQueue:str
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
99 _, _, genOrderQueue = ProcessSchema(obj)
482
f58fe38c8c04 Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents: 474
diff changeset
100 self.assertEqual(3,len(genOrderQueue))
f58fe38c8c04 Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents: 474
diff changeset
101 self.assertEqual("A",genOrderQueue[0])
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
102 self.assertEqual("B",genOrderQueue[1])
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
103 self.assertEqual("C",genOrderQueue[2])
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
104
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
105 def test_GenerateTypeScriptEnumeration(self):
482
f58fe38c8c04 Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents: 474
diff changeset
106 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
f58fe38c8c04 Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents: 474
diff changeset
107 obj = LoadSchema(fn)
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
108 (_,outputStreams,_) = ProcessSchema(obj)
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
109
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
110 tsPreambleRef: str = "// autogenerated by stonegentool on Fri Feb 15 07:36:51 2019\n"
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
111 tsEnumsRef: str = """enum MovieType
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
112 {
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
113 Romcom,
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
114 Horror,
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
115 ScienceFiction,
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
116 Vegetables
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
117 };
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
118
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
119 enum CrispType
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
120 {
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
121 SaltAndPepper,
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
122 CreamAndChives,
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
123 Paprika,
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
124 Barbecue
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
125 };
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
126
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
127 """
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
128
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
129 tsStructsRef: str = """class A
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
130 {
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
131 public Array<string> someStrings;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
132 public Array<number> someInts2;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
133 };
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
134
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
135 class B
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
136 {
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
137 public Array<A> someAs;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
138 public Array<number> someInts;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
139 };
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
140
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
141 class C
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
142 {
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
143 public Array<B> someBs;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
144 public Array<D> ddd;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
145 };
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
146
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
147 """
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
148
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
149 tsPreambleRefCastrated: str = RemoveDateTimeLine(tsPreambleRef)
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
150 tsPreambleCastrated: str = RemoveDateTimeLine(outputStreams.tsPreamble.getvalue())
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
151 self.assertEqual(tsPreambleRefCastrated,tsPreambleCastrated)
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
152 self.assertEqual(tsEnumsRef,outputStreams.tsEnums.getvalue())
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
153 self.assertEqual(tsStructsRef,outputStreams.tsStructs.getvalue())
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
154
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
155 cppPreambleRef: str = """// autogenerated by stonegentool on Fri Feb 15 07:36:51 2019
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
156 #include <cstdint>
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
157 #include <string>
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
158 #include <vector>
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
159 #include <map>
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
160
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
161 """
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
162
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
163 cppEnumsRef: str = """enum MovieType
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
164 {
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
165 Romcom,
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
166 Horror,
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
167 ScienceFiction,
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
168 Vegetables
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
169 };
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
170
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
171 enum CrispType
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
172 {
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
173 SaltAndPepper,
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
174 CreamAndChives,
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
175 Paprika,
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
176 Barbecue
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
177 };
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
178
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
179 """
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
180 cppStructsRef: str = """struct A
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
181 {
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
182 std::vector<string> someStrings;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
183 std::vector<int32_t> someInts2;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
184 };
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
185
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
186 struct B
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
187 {
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
188 std::vector<A> someAs;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
189 std::vector<int32_t> someInts;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
190 };
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
191
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
192 struct C
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
193 {
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
194 std::vector<B> someBs;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
195 std::vector<D> ddd;
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
196 };
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
197
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
198 """
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
199 cppPreambleRefCastrated: str = RemoveDateTimeLine(cppPreambleRef)
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
200 cppPreambleCastrated: str = RemoveDateTimeLine(outputStreams.cppPreamble.getvalue())
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
201 self.assertEqual(cppPreambleRefCastrated,cppPreambleCastrated)
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
202 self.assertEqual(cppEnumsRef,outputStreams.cppEnums.getvalue())
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
203 self.assertEqual(cppStructsRef,outputStreams.cppStructs.getvalue())
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
204
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
205 def test_GenerateCppEnumeration(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
206 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
207
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
208 def test_GenerateTypeScriptClasses(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
209 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
210
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
211 def test_GenerateCppClasses(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
212 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
213
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
214 def test_GenerateTypeScriptHandlerInterface(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
215 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
216
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
217 def test_GenerateCppHandlerInterface(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
218 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
219
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
220 def test_GenerateTypeScriptDispatcher(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
221 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
222
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
223 def test_GenerateCppDispatcher(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
224 pass
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
225
472
3db3289e1c25 Ongoing codegen work
bgo-osimis
parents: 471
diff changeset
226 # def test(self):
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
227 # s = 'hello world'
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
228 # self.assertEqual(s.split(), ['hello', 'world'])
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
229 # # check that s.split fails when the separator is not a string
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
230 # with self.assertRaises(TypeError):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
231 # s.split(2)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
232
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
233 if __name__ == '__main__':
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
234 unittest.main()
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
235