예제 #1
0
        public void Run()
        {
            Test = new UnitTestHelper();
            Test.PrintHeadline("UnitTest1 - Basic Features");

            TestReadOnly();
            TestReadWrite();
            TestCreateNew();
            TestOperators();
            TestSerialization();
            TestParseInvalid();
            TestParseAndSerialize();

            Test.PrintSummary();
            Test = null;
        }
예제 #2
0
        public void Run()
        {
            Test = new UnitTestHelper();
            Test.PrintHeadline("UnitTest3 - Reflection-based Serialization");

            var o1 = new ExampleOuter()
            {
                ValueString      = "Test",
                ValueStringArray = new string[] { "A", "B,", "C" },
                ValueDoubleArray = new double[] { 2, 3.14, 10000 },
                PropertyInteger  = 27,
                PropertyDateTime = new DateTime(2017, 12, 27, 14, 30, 0),
            };

            o1.ValueObject      = new ExampleInner(2);
            o1.ValueObjectArray = new ExampleInner[] { new ExampleInner(4), new ExampleInner(6) };
            o1.ChangePrivateValue(2.345f);

            string s1 = Serialize(o1);
            //Console.WriteLine(s1);

            var          d  = new SLJsonDeserializer();
            ExampleOuter o2 = d.Deserialize <ExampleOuter>(s1);

            string s2 = Serialize(o1);

            Test.Assert(() => s1 == s2);

            SLJsonNode n1 = SLJsonParser.Parse(s1);
            SLJsonNode n2 = n1.Clone();
            SLJsonNode n3 = SLJsonParser.Parse(n2.AsJson);
            SLJsonNode n4 = SLJsonParser.Parse(n3.AsJsonCompact);

            Test.Assert(() => n1 != n2);
            CompareNodes(n1, n1);
            CompareNodes(n1, n2);
            CompareNodes(n1, n3);
            CompareNodes(n1, n4);

            //Console.WriteLine();
            Test.PrintSummary();
            Test = null;
        }
예제 #3
0
        public void Run()
        {
            Test = new UnitTestHelper();
            Test.PrintHeadline("UnitTest2 - Values and Data Types");

            SLJsonNodeType nt;

            nt = SLJsonNodeType.Missing;
            Check("{other: 123}", false, false, false, false, nt, false, 0, 0, 0, null);

            nt = SLJsonNodeType.Null;
            Check("{value: null}", true, false, false, false, nt, false, 0, 0, 0, null);

            nt = SLJsonNodeType.Boolean;
            Check("{value: false}", false, false, false, true, nt, false, 0, 0, 0, "false");
            Check("{value: true}", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check("{value: true }", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check("{value:true}", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" {value:true}", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" { value:true}", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" { value :true}", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" { value : true}", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" { value : true }", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" { value : true } ", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" { value :\ttrue\t}\t", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check("{\"value\":true}", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" { \"value\" : true } ", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check(" { 'value' : true } ", false, false, false, true, nt, true, 0, 0, 0, "true"); // Single-quotation marks are not allowed for JSON expressions

            nt = SLJsonNodeType.Number;
            Check("{value: 123}", false, false, false, true, nt, true, 123, 123, 123, "123");
            Check("{value: 1.23}", false, false, false, true, nt, true, 1, 1, 1.23, "1.23");
            Check("{value: 1.89}", false, false, false, true, nt, true, 1, 1, 1.89, "1.89");
            Check("{value: 0.123}", false, false, false, true, nt, false, 0, 0, 0.123, "0.123");
            Check("{value: .123}", false, false, false, true, nt, false, 0, 0, 0.123, ".123");
            Check("{value: 1e-100}", false, false, false, true, nt, false, 0, 0, 1e-100, "1e-100");
            Check("{value: 1.23e-100}", false, false, false, true, nt, false, 0, 0, 1.23e-100, "1.23e-100");
            Check("{value: 1e+100}", false, false, false, true, nt, true, 0, 0, 1e+100, "1e+100");
            Check("{value: 1.23e+100}", false, false, false, true, nt, true, 0, 0, 1.23e+100, "1.23e+100");

            nt = SLJsonNodeType.String;
            Check("{value: \"text\"}", false, false, false, true, nt, false, 0, 0, 0, "text");
            Check("{value: \"text with \\\" escape sequence\"}", false, false, false, true, nt, false, 0, 0, 0, "text with \" escape sequence");
            Check("{value: \"text with \\\' escape sequence\"}", false, false, false, true, nt, false, 0, 0, 0, "text with \' escape sequence");
            Check("{value: \'text with \\\' escape sequence\'}", false, false, false, true, nt, false, 0, 0, 0, "text with \' escape sequence");
            Check("{value: \"Special_\\0\"}", false, false, false, true, nt, false, 0, 0, 0, "Special_\0");
            Check("{value: \"Special_\\10\"}", false, false, false, true, nt, false, 0, 0, 0, "Special_\b");
            Check("{value: \"Special_\\108\"}", false, false, false, true, nt, false, 0, 0, 0, "Special_\b8");
            Check("{value: \"Special_\\101\"}", false, false, false, true, nt, false, 0, 0, 0, "Special_A");
            Check("{value: \"Special_\\1010\"}", false, false, false, true, nt, false, 0, 0, 0, "Special_A0");
            Check("{value: \"Special_\\1018\"}", false, false, false, true, nt, false, 0, 0, 0, "Special_A8");
            Check("{value: \"Special_\\u0041\"}", false, false, false, true, nt, false, 0, 0, 0, "Special_A");
            Check("{value: \"Special_\\\\_\\/_/_\\b\\t\\n\\v\\f\\r\"}", false, false, false, true, nt, false, 0, 0, 0, "Special_\\_/_/_\b\t\n\v\f\r");
            Check("{value: \"null\"}", false, false, false, true, nt, false, 0, 0, 0, "null");
            Check("{value: \"false\"}", false, false, false, true, nt, false, 0, 0, 0, "false");
            Check("{value: \"FALSE\"}", false, false, false, true, nt, false, 0, 0, 0, "FALSE");
            Check("{value: \"true\"}", false, false, false, true, nt, true, 0, 0, 0, "true");
            Check("{value: \"TRUE\"}", false, false, false, true, nt, false, 0, 0, 0, "TRUE");
            Check("{value: \"123\"}", false, false, false, true, nt, true, 123, 123, 123, "123");
            Check("{value: 'single-quoted'}", false, false, false, true, nt, false, 0, 0, 0, "single-quoted"); // Single-quotation marks are not allowed for JSON expressions

            Check("{value: INVALID}", false, false, false, true, SLJsonNodeType.Number, false, 0, 0, 0, "INVALID");

            Test.PrintSummary();
            Test = null;
        }