public void MapSKEMA() { SKEMAObject map = new SKEMAObject(new Dictionary <string, SKEMAObject>() { { "StringKey", SKEMAObject.String }, { "Any", SKEMAObject.Any } }); SKONObject data = new Dictionary <string, SKONObject>() { { "StringKey", "Value" }, { "Any", 1.3d } }; Assert.IsTrue(map.Valid(data)); data["Any"] = new DateTime(1990, 06, 02); Assert.IsTrue(map.Valid(data)); data = new Dictionary <string, SKONObject>() { { "StringKey", 123 }, { "Any", "AnyValue" } }; Assert.IsFalse(map.Valid(data)); data["StringKey"] = "asdf"; Assert.IsTrue(map.Valid(data)); }
public void ArraySKEMA() { SKEMAObject obj = SKEMAObject.ArrayOf(SKEMAObject.Float); Assert.IsFalse(obj.Valid(new int[] { 1, 2, 3 })); Assert.IsTrue(obj.Valid(new double[] { 1, 2, 3 })); obj = SKEMAObject.ArrayOf(SKEMAObject.Any); Assert.IsTrue(obj.Valid(new int[] { 1, 2, 3 })); Assert.IsTrue(obj.Valid(new double[] { 1, 2, 3 })); }
public void TestSKEMA() { SKEMAObject testSKEMA = global::SKON.SKEMA.TestSKEMA.TestSKEMAObject; SKONObject testData = TestSKON.TestSKONObject; Assert.IsTrue(testSKEMA.Valid(testData)); }
public void GenericParsing() { string skema = @"define Color: { Red: Integer, Green: Integer, Blue: Integer, }, Colors: [ #Color ],"; SKEMAObject skemaObj = ParseWithMetadata(skema); Console.Write(SKEMA.Write(skemaObj)); SKONObject data = new Dictionary <string, SKONObject> { { "Colors", new SKONObject[] { new Dictionary <string, SKONObject> { { "Red", 140 }, { "Green", 50 }, { "Blue", 235 }, }, new Dictionary <string, SKONObject> { { "Red", 50 }, { "Green", 50 }, { "Blue", 50 }, }, } }, }; Assert.IsTrue(skemaObj.Valid(data)); data["Colors"].Add(new Dictionary <string, SKONObject> { { "H", 260 }, { "S", 0.3 }, { "V", 1 } }); Assert.IsFalse(skemaObj.Valid(data)); }
public void TreeSKEMA() { string skema = @"define Node: { Value: Any, optional Nodes: [ #Node ], }, Tree: #Node,"; SKEMAObject skemaObj = ParseWithMetadata(skema); SKONObject data = new Dictionary <string, SKONObject> { { "Tree", new Dictionary <string, SKONObject> { { "Value", "TestString" }, { "Nodes", new SKONObject[] { new Dictionary <string, SKONObject> { { "Value", 10 }, { "Nodes", new SKONObject[] { new Dictionary <string, SKONObject> { { "Value", true } } } } }, new Dictionary <string, SKONObject> { { "Value", DateTime.Now } } } } } } }; Assert.IsTrue(skemaObj.Valid(data)); }
/// <summary> /// The main method /// </summary> /// <param name="args">The program arguments</param> public static void Main(string[] args) { string defaultPath = "./SKONTest.skon"; Console.Write("Input file?:"); string filePath = Console.ReadLine(); if (File.Exists(filePath) == false) { filePath = defaultPath; } Stopwatch sw = new Stopwatch(); sw.Start(); SKONObject data = SKON.LoadFile(filePath); sw.Stop(); Console.WriteLine("Successfully parsed SKON file in {0}ms!", sw.ElapsedMilliseconds); Console.WriteLine(); sw.Reset(); sw.Start(); SKON.WriteToFile("./ResultSKON.skon", data); sw.Stop(); Console.WriteLine("Successfully wrote file in {0}ms!", sw.ElapsedMilliseconds); Console.WriteLine(); Console.Write("Show written file? Y/N (N):"); if (Console.ReadLine() == "Y") { ConsoleColor color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkGreen; string[] result = File.ReadAllLines("./ResultSKON.skon"); for (int i = 0; i < result.Length; i++) { Console.WriteLine(result[i]); } Console.ForegroundColor = color; } defaultPath = "./SKEMATest.skema"; Console.Write("SKEMA input file?:"); filePath = Console.ReadLine(); if (File.Exists(filePath) == false) { filePath = defaultPath; } sw.Reset(); sw.Start(); SKEMAObject skema = SKEMA.LoadFile(filePath); sw.Stop(); Console.WriteLine("Successfully parsed SKEMA file in {0}ms!", sw.ElapsedMilliseconds); Console.WriteLine(); sw.Reset(); sw.Start(); SKEMA.WriteToFile("./ResultSKEMA.skema", skema); sw.Stop(); Console.WriteLine("Successfully wrote SKEMA file in {0}ms!", sw.ElapsedMilliseconds); Console.WriteLine(); Console.Write("Show written SKEMA file? Y/N (N):"); if (Console.ReadLine() == "Y") { ConsoleColor color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkGreen; string[] result = File.ReadAllLines("./ResultSKEMA.skema"); for (int i = 0; i < result.Length; i++) { Console.WriteLine(result[i]); } Console.ForegroundColor = color; } defaultPath = "./SKONTest.skon"; Console.Write("SKON input file?:"); filePath = Console.ReadLine(); if (File.Exists(filePath) == false) { filePath = defaultPath; } sw.Reset(); sw.Start(); SKONObject skon = SKON.LoadFile(filePath); sw.Stop(); Console.WriteLine("Successfully parsed SKON file in {0}ms!", sw.ElapsedMilliseconds); Console.WriteLine(); Console.Write("Show SKON? Y/N (N):"); if (Console.ReadLine() == "Y") { ConsoleColor color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine(SKON.Write(skon)); Console.ForegroundColor = color; } Console.WriteLine(); Console.Write("Run SKEMATests? Y/N (Y):"); string ans = Console.ReadLine(); if (ans.Length == 0 || ans == "Y") { sw.Reset(); sw.Start(); bool result = skema.Valid(skon); sw.Stop(); if (result == true) { Console.WriteLine("Successfully verified SKON file in {0}ms!", sw.ElapsedMilliseconds); } else { Console.WriteLine("Failed to verify SKON file. {0}ms!", sw.ElapsedMilliseconds); } Console.WriteLine(); } Console.ReadKey(true); }