diff Resources/CodeGeneration/stonegentool_test.py @ 473:628941d63b8c bgo-commands-codegen

Ongoing work. Parsing tests work
author bgo-osimis
date Wed, 13 Feb 2019 12:07:00 +0100
parents 3db3289e1c25
children 38997ceb9bc6
line wrap: on
line diff
--- a/Resources/CodeGeneration/stonegentool_test.py	Wed Feb 13 06:46:36 2019 +0100
+++ b/Resources/CodeGeneration/stonegentool_test.py	Wed Feb 13 12:07:00 2019 +0100
@@ -1,5 +1,6 @@
-from stonegentool import EatToken
+from stonegentool import EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema
 import unittest
+import os
 
 class TestStonegentool(unittest.TestCase):
   def test_EatToken_empty(self):
@@ -35,6 +36,58 @@
     self.assertEqual(a,r"map<int32,string>")
     self.assertEqual(b,r"map<map<int32,string>,string>")
 
+  def test_SplitListOfTypes(self):
+    c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
+    lot = SplitListOfTypes(c)
+    self.assertEqual(3,len(lot))
+    self.assertEqual("vector<map<vector<string>,map<int32,string>>>",lot[0])
+    self.assertEqual("map<int32,string>",lot[1])
+    self.assertEqual("map<map<int32,string>,string>",lot[2])
+
+  def test_SplitListOfTypes_bogus(self):
+    c = r"vector<map<vector<string>,map<int32,string>>,map<int32,string>,map<map<int32,string>,string"
+    self.assertRaises(Exception,SplitListOfTypes,c) # the argument c must be passed to assertRaises, not as a normal call of SplitListOfTypes
+    
+  def test_ParseTemplateType_true(self):
+    c = "map<vector<map<int,vector<string>>>,map<vector<int>,vector<string>>>"
+    (ok,a,b) = ParseTemplateType(c)
+    self.assertEqual(ok,True)
+    self.assertEqual(a,"map")
+    self.assertEqual(b,["vector<map<int,vector<string>>>","map<vector<int>,vector<string>>"])
+
+    (ok2,a2,b2) = ParseTemplateType(b[0])
+    self.assertEqual(ok2,True)
+    self.assertEqual(a2,"vector")
+    self.assertEqual(b2,["map<int,vector<string>>"])
+
+    (ok3,a3,b3) = ParseTemplateType(b[1])
+    self.assertEqual(ok3,True)
+    self.assertEqual(a3,"map")
+    self.assertEqual(b3,["vector<int>","vector<string>"])
+
+    (ok4,a4,b4) = ParseTemplateType(b2[0])
+    self.assertEqual(ok4,True)
+    self.assertEqual(a4,"map")
+    self.assertEqual(b4,["int","vector<string>"])
+    
+  def test_ParseSchema(self):
+    fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
+    obj = LoadSchema(fn)
+    # we're happy if it does not crash
+    CheckSchemaSchema(obj)
+
+  def test_ParseSchema_bogus_json(self):
+    fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_json.jsonc')
+    self.assertRaises(Exception,LoadSchema,fn)
+
+  def test_ParseSchema_bogus_schema(self):
+    fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_schema.jsonc')
+    obj = LoadSchema(fn)
+    self.assertRaises(Exception,CheckSchemaSchema,obj) 
+
+
+
+
 # def test(self):
 #   s = 'hello world'
 #   self.assertEqual(s.split(), ['hello', 'world'])