Пример #1
0
        public void testLists()
        {
            Jai j = new Jai();
            IDictionary <string, object> dict = new Dictionary <string, object>();

            List <string> strings = new List <string>();
            List <int>    ints    = new List <int>();
            List <long>   longs   = new List <long>();
            List <float>  floats  = new List <float>();
            List <object> objects = new List <object>();

            strings.Add("one");
            strings.Add("two");
            ints.Add(1);
            ints.Add(2);
            longs.Add(1);
            longs.Add(1);
            floats.Add(1);
            floats.Add(2);
            objects.Add("one");
            objects.Add(2);
            objects.Add(3.0001);

            dict.Add("string", strings);
            dict.Add("ints", ints);
            dict.Add("longs", longs);
            dict.Add("floats", floats);
            dict.Add("objects", objects);

            string actual   = j.Serialize(dict);
            string expected = JSON_LISTS;

            //Console.WriteLine("actual: " + actual);
            AssertEquals(expected, actual);
        }
Пример #2
0
        public void testString()
        {
            Jai jai = new Jai();

            string actual   = jai.Serialize("te\"st");
            string expected = "\"te\\\"st\"";

            // Console.WriteLine("actual: " + actual);
            AssertEquals(expected, actual);
        }
Пример #3
0
        public void testSorted()
        {
            Jai j = new Jai().WithSorted();
            IDictionary <string, object> dict = new Dictionary <string, object>();

            List <string> list = new List <string>();

            list.Add("one");
            list.Add("two");
            list.Add("three");

            int[] array = { 1, 2, 3 };

            dict.Add("list", list);
            dict.Add("array", array);

            dict.Add("long", 9999999999999999L);
            dict.Add("int", 2);
            dict.Add("double", 47.11);
            dict.Add("float", 47.11f);
            dict.Add("bool", true);
            dict.Add("null", null);

            string actual = j.Serialize(dict);
            //Console.WriteLine("actual: " + actual);

            string expected = "" +
                              "{\n" +
                              "  \"list\":[\n" +
                              "    \"one\",\n" +
                              "    \"two\",\n" +
                              "    \"three\"\n" +
                              "  ],\n" +
                              "  \"array\":[\n" +
                              "    1,\n" +
                              "    2,\n" +
                              "    3\n" +
                              "  ],\n" +
                              "  \"long\":9999999999999999,\n" +
                              "  \"int\":2,\n" +
                              "  \"double\":47.11,\n" +
                              "  \"float\":47.11,\n" +
                              "  \"bool\":True,\n" +
                              "  \"null\":null\n" +
                              "}";

            AssertEquals(expected, actual);
        }
Пример #4
0
        public void testUnsorted()
        {
            Jai j = new Jai();
            IDictionary <string, object> dict = j.Deserialize <IDictionary <string, object> >(JSON_STRING);

            dict.Add("a", 2);
            string actual = j.Serialize(dict);
            //Console.WriteLine("actual: " + actual);

            string expected = "" +
                              "{\n" +
                              "  \"string\":\"value\",\n" +
                              "  \"a\":2\n" +
                              "}";

            AssertEquals(expected, actual);
        }
Пример #5
0
        public void testList()
        {
            Jai jai = new Jai();

            List <string> list = new List <string>();

            list.Add("one");
            list.Add("two");
            list.Add("three");

            string actual = jai.Serialize(list);
            //Console.WriteLine("actual: " + actual);

            string expected = "" +
                              "[\n" +
                              "  \"one\",\n" +
                              "  \"two\",\n" +
                              "  \"three\"\n" +
                              "]";

            AssertEquals(expected, actual);
        }