Close() public méthode

public Close ( ) : void
Résultat void
Exemple #1
0
        public void BooleanTest()
        {
            string json = "[ true, false ]";

            JsonReader reader = new JsonReader (json);
            reader.Read ();

            reader.Read ();
            Assert.IsTrue ((bool) reader.Value, "A1");
            reader.Read ();
            Assert.IsTrue (! ((bool) reader.Value), "A2");

            reader.Close ();
        }
Exemple #2
0
        public void ImportManyJsonTextPiecesTest()
        {
            string json_arrays = @"
                [ true, true, false, false ]
                [ 10, 0, -10 ]
                [ ""war is over"", ""if you want it"" ]
                ";

            JsonReader reader;
            JsonData   arrays;

            reader = new JsonReader (json_arrays);
            arrays = JsonMapper.ToObject (reader);

            Assert.IsFalse (reader.EndOfInput, "A1");

            Assert.IsTrue (arrays.IsArray, "A2");
            Assert.AreEqual (4, arrays.Count, "A3");
            Assert.AreEqual (true, (bool) arrays[0], "A4");

            arrays = JsonMapper.ToObject (reader);

            Assert.IsFalse (reader.EndOfInput, "A5");

            Assert.IsTrue (arrays.IsArray, "A6");
            Assert.AreEqual (3, arrays.Count, "A7");
            Assert.AreEqual (10, (int) arrays[0], "A8");

            arrays = JsonMapper.ToObject (reader);

            Assert.IsTrue (arrays.IsArray, "A9");
            Assert.AreEqual (2, arrays.Count, "A10");
            Assert.AreEqual ("war is over", (string) arrays[0], "A11");

            reader.Close ();

            string json_objects = @"
                {
                  ""title""  : ""First"",
                  ""name""   : ""First Window"",
                  ""width""  : 640,
                  ""height"" : 480
                }

                {
                  ""title""  : ""Second"",
                  ""name""   : ""Second Window"",
                  ""width""  : 800,
                  ""height"" : 600
                }
                ";

            reader = new JsonReader (json_objects);
            UiWindow window;

            window = JsonMapper.ToObject<UiWindow> (reader);

            Assert.IsFalse (reader.EndOfInput, "A12");

            Assert.AreEqual ("First", window.title, "A13");
            Assert.AreEqual (640, window.width, "A14");

            window = JsonMapper.ToObject<UiWindow> (reader);

            Assert.AreEqual ("Second", window.title, "A15");
            Assert.AreEqual (800, window.width, "A16");

            reader.Close ();

            // Read them in a loop to make sure we get the correct number of
            // iterations
            reader = new JsonReader (json_objects);

            int i = 0;

            while (! reader.EndOfInput) {
                window = JsonMapper.ToObject<UiWindow> (reader);
                i++;
            }

            Assert.AreEqual (2, i, "A17");
        }
Exemple #3
0
        public void DoubleTest()
        {
            string json = @"[ 0.0, -0.0, 3.1416, 8e-3, 7E-5, -128.000009,
                   144e+3, 0.1e2 ]";

            JsonReader reader = new JsonReader (json);
            reader.Read ();

            reader.Read ();
            Assert.AreEqual ((double) reader.Value, 0.0,
                             Double.Epsilon, "A1");
            reader.Read ();
            Assert.AreEqual ((double) reader.Value, 0.0,
                             Double.Epsilon, "A2");
            reader.Read ();
            Assert.AreEqual ((double) reader.Value, 3.1416,
                             Double.Epsilon, "A3");
            reader.Read ();
            Assert.AreEqual ((double) reader.Value, 0.008,
                             Double.Epsilon, "A4");
            reader.Read ();
            Assert.AreEqual ((double) reader.Value, 0.00007,
                             Double.Epsilon, "A5");
            reader.Read ();
            Assert.AreEqual ((double) reader.Value, -128.000009,
                             Double.Epsilon, "A6");
            reader.Read ();
            Assert.AreEqual ((double) reader.Value, 144000.0,
                             Double.Epsilon, "A7");
            reader.Read ();
            Assert.AreEqual ((double) reader.Value, 10.0,
                             Double.Epsilon, "A8");

            reader.Close ();
        }
Exemple #4
0
        public void StringsTest()
        {
            string json =
                "[ \"abc 123 \\n\\f\\b\\t\\r \\\" \\\\ \\u263a \\u25CF\" ]";

            string str = "abc 123 \n\f\b\t\r \" \\ \u263a \u25cf";

            JsonReader reader = new JsonReader (json);
            reader.Read ();
            reader.Read ();

            Assert.AreEqual (str, reader.Value, "A1");

            reader.Close ();

            json = " [ '\"Hello\" \\'world\\'' ] ";
            str  = "\"Hello\" 'world'";

            reader = new JsonReader (json);
            reader.Read ();
            reader.Read ();

            Assert.AreEqual (str, reader.Value, "A2");

            reader.Close ();
        }
Exemple #5
0
        public void NullTest()
        {
            string json = "[ null ]";

            JsonReader reader = new JsonReader (json);
            reader.Read ();

            reader.Read ();
            Assert.IsNull (reader.Value);

            reader.Close ();
        }
Exemple #6
0
        public void LongTest()
        {
            string json = "[ 2147483648, -10000000000 ]";

            JsonReader reader = new JsonReader (json);
            reader.Read ();

            reader.Read ();
            Assert.AreEqual (typeof (Int64), reader.Value.GetType (), "A1");
            Assert.AreEqual (2147483648l, (long) reader.Value, "A2");
            reader.Read ();
            Assert.AreEqual (-10000000000l, (long) reader.Value, "A3");

            reader.Close ();
        }
Exemple #7
0
        public void IntTest()
        {
            string json = "[ 0, -0, 123, 14400, -500 ]";

            JsonReader reader = new JsonReader (json);
            reader.Read ();

            reader.Read ();
            Assert.AreEqual ((int) reader.Value, 0, "A1");
            reader.Read ();
            Assert.AreEqual ((int) reader.Value, 0, "A2");
            reader.Read ();
            Assert.AreEqual ((int) reader.Value, 123, "A3");
            reader.Read ();
            Assert.AreEqual ((int) reader.Value, 14400, "A4");
            reader.Read ();
            Assert.AreEqual ((int) reader.Value, -500, "A5");

            reader.Close ();
        }
Exemple #8
0
        public void EmptyStringTest()
        {
            string json = "[ \"\" ]";

            JsonReader reader = new JsonReader (json);
            reader.Read ();

            reader.Read ();
            Assert.AreEqual (reader.Value, String.Empty);

            reader.Close ();
        }