annotate Resources/CodeGeneration/stonegentool_test.py @ 491:8e7e151ef472 bgo-commands-codegen

Unit tests pass for enum generation
author bgo-osimis
date Wed, 20 Feb 2019 20:51:30 +0100
parents f6b7f113cf27
children 6fbf2eae7c88
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
1 #
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
2 # 1 2 3 4 5 6 7 8
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
3 # 345678901234567890123456789012345678901234567890123456789012345678901234567890
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
4 #
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
5
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
6 from stonegentool import \
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
7 EatToken,SplitListOfTypes,ParseTemplateType,ProcessSchema, \
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
8 CheckSchemaSchema,LoadSchema,trim,ComputeRequiredDeclarationOrder, \
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
9 GetTemplatingDictFromSchemaFilename
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
10 import unittest
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
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
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
13 import pprint
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
14 from jinja2 import Template
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
15
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
16 ymlSchema = trim("""rootName: VsolMessages
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
17
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
18 struct B:
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
19 someAs: vector<A>
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
20 someInts: vector<int32>
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
21
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
22 struct C:
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
23 someBs: vector<B>
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
24 ddd: vector<string>
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
25
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
26 struct A:
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
27 someStrings: vector<string>
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
28 someInts2: vector<int32>
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
29 movies: vector<MovieType>
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
30
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
31 enum MovieType:
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
32 - RomCom
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
33 - Horror
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
34 - ScienceFiction
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
35 - Vegetables
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
36
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
37 enum CrispType:
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
38 - SaltAndPepper
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
39 - CreamAndChives
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
40 - Paprika
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
41 - Barbecue
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
42 )
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
43 """)
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
44
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
45 def RemoveDateTimeLine(s : str):
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
46 # 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
47 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
48 return s2
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
49
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
50 class TestStonegentool(unittest.TestCase):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
51 def test_EatToken_empty(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
52 c = r""
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
53 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
54 self.assertEqual(a,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
55 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
56
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
57 def test_EatToken_simpleNonTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
58 c = r"int32"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
59 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
60 self.assertEqual(a,r"int32")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
61 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
62
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
63 def test_EatToken_simpleTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
64 c = r"vector<string>"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
65 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
66 self.assertEqual(a,r"vector<string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
67 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
68
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
69 def test_EatToken_complexTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
70 c = r"vector<map<int64,string>>,vector<map<int32,string>>"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
71 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
72 self.assertEqual(a,r"vector<map<int64,string>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
73 self.assertEqual(b,r"vector<map<int32,string>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
74
472
3db3289e1c25 Ongoing codegen work
bgo-osimis
parents: 471
diff changeset
75 def test_EatToken_complexTemplates(self):
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
76 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
77 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
78 self.assertEqual(a,r"vector<map<vector<string>,map<int32,string>>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
79 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
80 a,b = EatToken(b)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
81 self.assertEqual(a,r"map<int32,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
82 self.assertEqual(b,r"map<map<int32,string>,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
83
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
84 def test_SplitListOfTypes(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
85 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
86 lot = SplitListOfTypes(c)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
87 self.assertEqual(3,len(lot))
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
88 self.assertEqual("vector<map<vector<string>,map<int32,string>>>",lot[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
89 self.assertEqual("map<int32,string>",lot[1])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
90 self.assertEqual("map<map<int32,string>,string>",lot[2])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
91
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
92 def test_SplitListOfTypes_bogus(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
93 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
94 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
95
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
96 def test_ParseTemplateType_true(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
97 c = "map<vector<map<int,vector<string>>>,map<vector<int>,vector<string>>>"
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
98 (ok,a,b) = ParseTemplateType(c)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
99 self.assertEqual(ok,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
100 self.assertEqual(a,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
101 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
102
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
103 (ok2,a2,b2) = ParseTemplateType(b[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
104 self.assertEqual(ok2,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
105 self.assertEqual(a2,"vector")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
106 self.assertEqual(b2,["map<int,vector<string>>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
107
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
108 (ok3,a3,b3) = ParseTemplateType(b[1])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
109 self.assertEqual(ok3,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
110 self.assertEqual(a3,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
111 self.assertEqual(b3,["vector<int>","vector<string>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
112
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
113 (ok4,a4,b4) = ParseTemplateType(b2[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
114 self.assertEqual(ok4,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
115 self.assertEqual(a4,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
116 self.assertEqual(b4,["int","vector<string>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
117
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
118 def test_ParseSchema(self):
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
119 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml')
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
120 obj = LoadSchema(fn)
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
121 # we're happy if it does not crash :)
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
122 CheckSchemaSchema(obj)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
123
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
124 # def test_ParseSchema_bogus_json(self):
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
125 # fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_json.jsonc')
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
126 # self.assertRaises(Exception,LoadSchema,fn)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
127
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
128 # def test_ParseSchema_bogus_schema(self):
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
129 # fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_schema.jsonc')
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
130 # obj = LoadSchema(fn)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
131 # self.assertRaises(Exception,CheckSchemaSchema,obj)
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
132
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
133 def test_ComputeRequiredDeclarationOrder(self):
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
134 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml')
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
135 obj = LoadSchema(fn)
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
136 genOrder: str = ComputeRequiredDeclarationOrder(obj)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
137 self.assertEqual(3,len(genOrder))
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
138 self.assertEqual("A",genOrder[0])
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
139 self.assertEqual("B",genOrder[1])
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
140 self.assertEqual("C",genOrder[2])
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
141
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
142 # def test_GeneratePreambleEnumerationAndStructs(self):
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
143 # fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
144 # obj = LoadSchema(fn)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
145 # (_,genc,_) = ProcessSchema(obj)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
146
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
147 def test_genEnums(self):
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
148 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml')
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
149 obj = LoadSchema(fn)
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
150 genOrder: str = ComputeRequiredDeclarationOrder(obj)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
151 processedSchema = ProcessSchema(obj, genOrder)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
152 processedSchemaStr = pprint.pformat(processedSchema,indent=2)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
153 processedSchemaStrRef = """{ 'enums': [ { 'fields': ['RomCom', 'Horror', 'ScienceFiction', 'Vegetables'],
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
154 'name': 'MovieType'},
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
155 { 'fields': [ 'SaltAndPepper',
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
156 'CreamAndChives',
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
157 'Paprika',
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
158 'Barbecue'],
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
159 'name': 'CrispType'}],
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
160 'rootName': 'VsolMessages',
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
161 'structs': [ { 'fields': { 'movies': 'vector<MovieType>',
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
162 'someInts2': 'vector<int32>',
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
163 'someStrings': 'vector<string>'},
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
164 'name': 'A'},
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
165 { 'fields': {'someAs': 'vector<A>', 'someInts': 'vector<int32>'},
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
166 'name': 'B'},
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
167 { 'fields': {'ddd': 'vector<string>', 'someBs': 'vector<B>'},
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
168 'name': 'C'}]}"""
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
169
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
170 self.assertEqual(processedSchemaStrRef,processedSchemaStr)
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
171
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
172 def test_GenerateTypeScriptEnums(self):
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
173 fn = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml')
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
174 tdico = GetTemplatingDictFromSchemaFilename(fn)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
175 template = Template(""" // end of generic methods
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
176 {% for enum in enums%} export enum {{enum['name']}} {
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
177 {% for key in enum['fields']%} {{key}},
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
178 {%endfor%} };
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
179
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
180 {%endfor%}""")
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
181 renderedCode = template.render(**tdico)
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
182 renderedCodeRef = """ // end of generic methods
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
183 export enum MovieType {
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
184 RomCom,
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
185 Horror,
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
186 ScienceFiction,
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
187 Vegetables,
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
188 };
485
772516adcbf6 Ongoing work on code generation. Enums and structs OK in ts and cpp
bgo-osimis
parents: 482
diff changeset
189
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
190 export enum CrispType {
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
191 SaltAndPepper,
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
192 CreamAndChives,
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
193 Paprika,
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
194 Barbecue,
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
195 };
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
196
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
197 """
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 489
diff changeset
198 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
199
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
200
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
201 def test_GenerateTypeScriptHandlerInterface(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
202 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
203
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
204 def test_GenerateCppHandlerInterface(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
205 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
206
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
207 def test_GenerateTypeScriptDispatcher(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
208 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
209
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
210 def test_GenerateCppDispatcher(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
211 pass
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
212
472
3db3289e1c25 Ongoing codegen work
bgo-osimis
parents: 471
diff changeset
213 # def test(self):
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
214 # s = 'hello world'
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
215 # self.assertEqual(s.split(), ['hello', 'world'])
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
216 # # check that s.split fails when the separator is not a string
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
217 # with self.assertRaises(TypeError):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
218 # s.split(2)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
219
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
220 if __name__ == '__main__':
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
221 unittest.main()
486
8e40355a172b Unit tests OK for preambles, enums and structs in both TS and C++
bgo-osimis
parents: 485
diff changeset
222