public void SelfReferencingSKEMA() { string skema = @"define A: #A, A: #A,"; Assert.Throws <CouldNotSolveReferencesException>(() => ParseWithMetadata(skema)); skema = @"define A: { optional A: #A, }, A: #A,"; SKEMAObject obj = ParseWithMetadata(skema); string res = SKEMA.Write(obj); Console.WriteLine(res); SKEMAObject resObj = SKEMA.Parse(res); Assert.IsTrue(resObj == obj); skema = @"define A: { optional A: #A, optional B: #B, }, define B: #A, A: #A, "; obj = ParseWithMetadata(skema); res = SKEMA.Write(obj); Console.WriteLine(res); resObj = SKEMA.Parse(res); Assert.IsTrue(resObj == obj); }
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 ReplacingMapElements() { SKEMAObject obj = new Dictionary <string, SKEMAObject>() { { "Replace", SKEMAObject.Any } }; Assert.AreEqual(SKEMAType.MAP, obj.Type); Assert.AreEqual(SKEMAType.ANY, obj["Replace"].Type); obj["Replace"] = SKEMAObject.String; Assert.AreEqual(SKEMAType.STRING, obj["Replace"].Type); obj["Replace"] = SKEMAObject.ArrayOf(SKEMAObject.Boolean); Assert.AreEqual(SKEMAType.ARRAY, obj["Replace"].Type); Assert.AreEqual(SKEMAType.BOOLEAN, obj["Replace"].ArrayElementSKEMA.Type); obj["Replace"].ArrayElementSKEMA = SKEMAObject.ArrayOf(SKEMAObject.Float); Console.WriteLine(SKEMA.Write(obj)); Assert.AreEqual(SKEMAType.ARRAY, obj["Replace"].ArrayElementSKEMA.Type); Assert.AreEqual(SKEMAType.FLOAT, obj["Replace"].ArrayElementSKEMA.ArrayElementSKEMA.Type); }
void definition(out string key, out SKEMAObject def) { Expect(15); Ident(out key); Expect(2); skema_value(out def); }
void skema_value(out SKEMAObject skemaObj) { skemaObj = null; if (StartOf(2)) { type(out skemaObj); } else if (la.kind == 4) { skema_map(out skemaObj); } else if (la.kind == 6) { skema_array(out skemaObj); } else if (la.kind == 14) { Get(); skemaObj = new SKEMAObject(t.val.Substring(1)); } else { SynErr(24); } }
public void TestSKEMA() { SKEMAObject testSKEMA = global::SKON.SKEMA.TestSKEMA.TestSKEMAObject; SKONObject testData = TestSKON.TestSKONObject; Assert.IsTrue(testSKEMA.Valid(testData)); }
void skema_map(out SKEMAObject map) { Dictionary <string, SKEMAObject> mapElements; Dictionary <string, bool> optionalMap; Expect(4); open_skema_map(out mapElements, out optionalMap); map = new SKEMAObject(mapElements, optionalMap); Expect(5); }
void skema_array(out SKEMAObject array) { SKEMAObject skemaObj; Expect(6); skema_value(out skemaObj); array = SKEMAObject.ArrayOf(skemaObj); Expect(7); }
public void ParseOptionalElements() { string skema = @"Required: Any, optional Optional: Any,"; SKEMAObject obj = ParseWithMetadata(skema); Assert.IsFalse(obj.IsOptional("Required")); Assert.IsTrue(obj.IsOptional("Optional")); }
void skema_map_element(out string key, out SKEMAObject obj, out bool optional) { optional = false; if (la.kind == 16) { Get(); optional = true; } Ident(out key); Expect(2); skema_value(out obj); }
void SKEMA() { Dictionary <string, SKEMAObject> mapElements; Dictionary <string, bool> optionalMap; int version; string docVersion; meta_version(out version); metadata.LanguageVersion = version; meta_docVersion(out docVersion); metadata.DocuemntVersion = docVersion; open_skema_map(out mapElements, out optionalMap); this.data = new SKEMAObject(mapElements, optionalMap); }
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)); }
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 })); }
void type(out SKEMAObject skemaObj) { skemaObj = null; switch (la.kind) { case 17: { Get(); skemaObj = SKEMAObject.Any; break; } case 18: { Get(); skemaObj = SKEMAObject.String; break; } case 19: { Get(); skemaObj = SKEMAObject.Integer; break; } case 20: { Get(); skemaObj = SKEMAObject.Float; break; } case 21: { Get(); skemaObj = SKEMAObject.Boolean; break; } case 22: { Get(); skemaObj = SKEMAObject.DateTime; break; } default: SynErr(25); break; } }
static void Main(string[] args) { string defaultPath = "./SKONTest.skon"; Console.Write("SKON Input file?:"); string filePath = Console.ReadLine(); if (File.Exists(filePath) == false) { filePath = defaultPath; } SKONObject obj = VerboseParseFile(filePath); Console.WriteLine(); Console.WriteLine(SKON.Write(obj)); Console.ReadKey(true); defaultPath = "./SKEMATest.skema"; Console.Write("SKEMA Input file?:"); filePath = Console.ReadLine(); if (File.Exists(filePath) == false) { filePath = defaultPath; } SKEMAObject skemaObj = VerboseParseFileSKEMA(filePath); Console.WriteLine(); Console.WriteLine(SKEMA.Write(skemaObj)); Console.ReadKey(true); }
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 WriteSKEMA() { string skema = @"define Color: { Red: Integer, Green: Integer, Blue: Integer, }, Colors: [ #Color ],"; SKEMAObject skemaObj = ParseWithMetadata(skema); string res = SKEMA.Write(skemaObj); SKEMAObject newSkemaObj = SKEMA.Parse(res); Assert.AreEqual(skemaObj, newSkemaObj); Console.WriteLine(res); skema = @"define Node: { Value: Any, optional Nodes: [ #Node ], }, Tree: #Node,"; skemaObj = ParseWithMetadata(skema); res = SKEMA.Write(skemaObj); newSkemaObj = SKEMA.Parse(res); //Assert.AreEqual(skemaObj, newSkemaObj); Console.WriteLine(res); }
public void ObjectEquality() { SKEMAObject obj1 = SKEMAObject.String; SKEMAObject obj2 = SKEMAObject.String; Assert.IsTrue(obj1.Equals(obj2)); Assert.IsTrue(obj1 == obj2); Assert.IsTrue(obj1.GetHashCode() == obj2.GetHashCode()); obj1 = SKEMAObject.AsReference(obj1, "Test"); obj2 = SKEMAObject.AsReference(obj2, "Test"); Assert.IsTrue(obj1.Equals(obj2)); Assert.IsTrue(obj1 == obj2); Assert.IsTrue(obj1.GetHashCode() == obj2.GetHashCode()); obj2 = SKEMAObject.Any; Assert.IsFalse(obj1.Equals(obj2)); Assert.IsFalse(obj1 == obj2); obj1 = new Dictionary <string, SKEMAObject> { { "Test", SKEMAObject.Float } }; Assert.IsFalse(obj1.Equals(obj2)); Assert.IsFalse(obj1 == obj2); }
/// <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); }