Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
 private static SKEMAObject ParseWithMetadata(string skema)
 {
     return(SKEMA.Parse(metadataString + skema));
 }