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); }
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 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)); }
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 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); }