/// <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, Console.Out); sw.Stop(); Console.WriteLine("Successfully parsed file in {0}ms!", sw.ElapsedMilliseconds); Console.WriteLine(); Console.WriteLine(SKON.Write(data)); SKON.WriteToFile("./ResultSKON.skon", data); Console.ReadKey(); }
public void RecursiveObject() { SKONObject recursiveArray = SKONObject.GetEmptyArray(); recursiveArray.Add(recursiveArray); Assert.DoesNotThrow(() => recursiveArray.Equals(recursiveArray)); Assert.Throws <ArgumentException>(() => SKON.Write(new Dictionary <string, SKONObject> { { "Test", recursiveArray } })); recursiveArray.Add(new Dictionary <string, SKONObject> { { "Test2", recursiveArray } }); Assert.DoesNotThrow(() => recursiveArray.Equals(recursiveArray[1])); // Equality between two recursive objects SKONObject rec1 = SKONObject.GetEmptyMap(); rec1.Add("Rec", rec1); SKONObject rec2 = SKONObject.GetEmptyMap(); rec2.Add("Rec", rec2); Assert.IsTrue(rec1.Equals(rec2)); }
public void EmptyInput() { Assert.Throws <FormatException>(() => SKON.Parse(string.Empty)); SKONObject emptyMap = ParseWithMetadata(string.Empty); IsNotSimpleType(emptyMap); IsNotEmpty(emptyMap); }
public void NonReqursiveMapWithEqualMaps() { SKONObject skonObject = SKONObject.GetEmptyMap(); skonObject.Add("test", new List <SKONObject> { new Dictionary <string, SKONObject> { { "test", 1 } }, new Dictionary <string, SKONObject> { { "test", 1 } } }); Assert.IsFalse(SKON.ContainsLoops(skonObject)); Console.WriteLine(SKON.Write(skonObject)); }
public void BooleanObject() { string booleanSKON = "BooleanKey: true,"; SKONObject booleanMap = ParseWithMetadata(booleanSKON); Console.WriteLine(SKON.Write(booleanMap)); IsNotEmpty(booleanMap); IsNotSimpleType(booleanMap); Assert.IsTrue(booleanMap.ContainsKey("BooleanKey")); SKONObject booleanObj = booleanMap["BooleanKey"]; HasValue(true, booleanObj); }
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 ParseWriteParse() { string skon = @"Boolean: true, Int: 12, Map: { Content: ""Hello"", },"; SKONMetadata meta; SKONObject obj = ParseWithMetadata(skon, out meta); string res = SKON.Write(obj, meta); SKONMetadata meta2; SKONObject objRes = SKON.Parse(res, out meta2); HasKey(obj, "Boolean", SKONValueType.BOOLEAN); HasKey(obj, "Int", SKONValueType.INTEGER); HasKey(obj, "Map", SKONValueType.MAP); HasKey(obj["Map"], "Content", SKONValueType.STRING); Assert.IsTrue(meta.LanguageVersion == meta2.LanguageVersion); Assert.IsTrue(meta.DocuemntVersion == meta2.DocuemntVersion); Assert.IsTrue(meta.SKEMA == meta2.SKEMA); Assert.IsTrue(obj == objRes); }
private static SKONObject ParseWithMetadata(string skon, out SKONMetadata meta) { return(SKON.Parse(metadataString + skon, out meta)); }
static void Main(string[] args) { string skonPath = "./SKONTest.skon"; string jsonPath = "./TestJSON.json"; string skon = File.ReadAllText(skonPath); string json = File.ReadAllText(jsonPath); Console.WriteLine("=== SKON Tests ==="); double skonNMean = Clock.BenchmarkCpu(() => SKON.Parse(skon)); Console.WriteLine("Normalized mean: {0}ms", skonNMean); Console.WriteLine(); Console.WriteLine("=== JSON Tests ===="); var definition = new { Version = string.Empty, VersionName = string.Empty, Author = new { }, ExampleString = string.Empty, ExampleInteger = 0, ExampleDecimal = 0.0, ExampleBoolean = false, ExampleDatetime = string.Empty, ExampleArray = new string[] { }, ExampleMap = new { ThisIsAKey = string.Empty, ThisIsAnotherKey = 0 }, ArrayOfMaps = new dynamic[] { new { Key = string.Empty }, new { Key = string.Empty }, new { AnotherKey = string.Empty } }, MapOfAllDataTypes = new { String = string.Empty, Integer = 0, Double = 0.0, Boolean = false, DateTime = string.Empty, Array = new dynamic[] { }, Map = new { } }, ArrayOfArrayOfStrings = new[] { new[] { string.Empty, string.Empty }, new[] { string.Empty, string.Empty }, new[] { string.Empty, string.Empty } } }; double jsonNMean = Clock.BenchmarkCpu(() => { JsonConvert.DeserializeAnonymousType(json, definition); }); Console.WriteLine("Normalized mean: {0}ms", jsonNMean); Console.WriteLine(); Console.WriteLine("SKON: {0:F3}, JSON: {1:F3}", skonNMean, jsonNMean); Console.WriteLine(); double ratio = (skonNMean > jsonNMean) ? skonNMean / jsonNMean : jsonNMean / skonNMean; Console.WriteLine("Skon is " + ratio.ToString("F3") + "x " + ((skonNMean < jsonNMean) ? "faster" : (skonNMean == jsonNMean) ? "equal" : "slower") + " than json at this time!\n\n"); SKONObject skonObject = TestSKON.TestSKONObject; Console.WriteLine(SKON.Write(skonObject)); Console.ReadKey(true); }
/// <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); }