474
|
1 from stonegentool import \
|
|
2 EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema,ProcessSchema
|
471
|
3 import unittest
|
473
|
4 import os
|
471
|
5
|
|
6 class TestStonegentool(unittest.TestCase):
|
|
7 def test_EatToken_empty(self):
|
|
8 c = r""
|
|
9 a,b = EatToken(c)
|
|
10 self.assertEqual(a,r"")
|
|
11 self.assertEqual(b,r"")
|
|
12
|
|
13 def test_EatToken_simpleNonTemplate(self):
|
|
14 c = r"int32"
|
|
15 a,b = EatToken(c)
|
|
16 self.assertEqual(a,r"int32")
|
|
17 self.assertEqual(b,r"")
|
|
18
|
|
19 def test_EatToken_simpleTemplate(self):
|
|
20 c = r"vector<string>"
|
|
21 a,b = EatToken(c)
|
|
22 self.assertEqual(a,r"vector<string>")
|
|
23 self.assertEqual(b,r"")
|
|
24
|
|
25 def test_EatToken_complexTemplate(self):
|
|
26 c = r"vector<map<int64,string>>,vector<map<int32,string>>"
|
|
27 a,b = EatToken(c)
|
|
28 self.assertEqual(a,r"vector<map<int64,string>>")
|
|
29 self.assertEqual(b,r"vector<map<int32,string>>")
|
|
30
|
472
|
31 def test_EatToken_complexTemplates(self):
|
471
|
32 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
|
|
33 a,b = EatToken(c)
|
|
34 self.assertEqual(a,r"vector<map<vector<string>,map<int32,string>>>")
|
|
35 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>")
|
|
36 a,b = EatToken(b)
|
|
37 self.assertEqual(a,r"map<int32,string>")
|
|
38 self.assertEqual(b,r"map<map<int32,string>,string>")
|
|
39
|
473
|
40 def test_SplitListOfTypes(self):
|
|
41 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
|
|
42 lot = SplitListOfTypes(c)
|
|
43 self.assertEqual(3,len(lot))
|
|
44 self.assertEqual("vector<map<vector<string>,map<int32,string>>>",lot[0])
|
|
45 self.assertEqual("map<int32,string>",lot[1])
|
|
46 self.assertEqual("map<map<int32,string>,string>",lot[2])
|
|
47
|
|
48 def test_SplitListOfTypes_bogus(self):
|
|
49 c = r"vector<map<vector<string>,map<int32,string>>,map<int32,string>,map<map<int32,string>,string"
|
|
50 self.assertRaises(Exception,SplitListOfTypes,c) # the argument c must be passed to assertRaises, not as a normal call of SplitListOfTypes
|
|
51
|
|
52 def test_ParseTemplateType_true(self):
|
|
53 c = "map<vector<map<int,vector<string>>>,map<vector<int>,vector<string>>>"
|
|
54 (ok,a,b) = ParseTemplateType(c)
|
|
55 self.assertEqual(ok,True)
|
|
56 self.assertEqual(a,"map")
|
|
57 self.assertEqual(b,["vector<map<int,vector<string>>>","map<vector<int>,vector<string>>"])
|
|
58
|
|
59 (ok2,a2,b2) = ParseTemplateType(b[0])
|
|
60 self.assertEqual(ok2,True)
|
|
61 self.assertEqual(a2,"vector")
|
|
62 self.assertEqual(b2,["map<int,vector<string>>"])
|
|
63
|
|
64 (ok3,a3,b3) = ParseTemplateType(b[1])
|
|
65 self.assertEqual(ok3,True)
|
|
66 self.assertEqual(a3,"map")
|
|
67 self.assertEqual(b3,["vector<int>","vector<string>"])
|
|
68
|
|
69 (ok4,a4,b4) = ParseTemplateType(b2[0])
|
|
70 self.assertEqual(ok4,True)
|
|
71 self.assertEqual(a4,"map")
|
|
72 self.assertEqual(b4,["int","vector<string>"])
|
|
73
|
|
74 def test_ParseSchema(self):
|
|
75 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
|
|
76 obj = LoadSchema(fn)
|
|
77 # we're happy if it does not crash
|
|
78 CheckSchemaSchema(obj)
|
|
79
|
|
80 def test_ParseSchema_bogus_json(self):
|
|
81 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_json.jsonc')
|
|
82 self.assertRaises(Exception,LoadSchema,fn)
|
|
83
|
|
84 def test_ParseSchema_bogus_schema(self):
|
|
85 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_schema.jsonc')
|
|
86 obj = LoadSchema(fn)
|
|
87 self.assertRaises(Exception,CheckSchemaSchema,obj)
|
|
88
|
474
|
89 def test_GenOrderQueue(self):
|
|
90 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
|
|
91 obj = LoadSchema(fn)
|
|
92 genOrderQueue,structTypes = ProcessSchema(obj)
|
|
93 print(f"genOrderQueue = {genOrderQueue}")
|
|
94 print("")
|
473
|
95
|
474
|
96 def test_GenerateTypeScriptEnumeration(self):
|
|
97 pass
|
473
|
98
|
474
|
99 def test_GenerateCppEnumeration(self):
|
|
100 pass
|
|
101
|
|
102 def test_GenerateTypeScriptClasses(self):
|
|
103 pass
|
|
104
|
|
105 def test_GenerateCppClasses(self):
|
|
106 pass
|
|
107
|
|
108 def test_GenerateTypeScriptHandlerInterface(self):
|
|
109 pass
|
|
110
|
|
111 def test_GenerateCppHandlerInterface(self):
|
|
112 pass
|
|
113
|
|
114 def test_GenerateTypeScriptDispatcher(self):
|
|
115 pass
|
|
116
|
|
117 def test_GenerateCppDispatcher(self):
|
|
118 pass
|
473
|
119
|
472
|
120 # def test(self):
|
471
|
121 # s = 'hello world'
|
|
122 # self.assertEqual(s.split(), ['hello', 'world'])
|
|
123 # # check that s.split fails when the separator is not a string
|
|
124 # with self.assertRaises(TypeError):
|
|
125 # s.split(2)
|
|
126
|
|
127 if __name__ == '__main__':
|
474
|
128 print("")
|
|
129 unittest.main()
|