예제 #1
0
파일: Tests.cs 프로젝트: substans/JohJSON
        public void HeroTestA()
        {
            string data   = "{\"playerInfo\":{\"cash\":10,\"diamonds\":10,\"selectedAttributes\":[\"StandardSubmarine 2\"],\"attributes\":[\"StandardSubmarine 2\",\"StandardSubmarine\"]}}";
            var    loaded = JSONNode.CreateFromString(data).ToString();

            Assert.AreEqual(data, loaded);
        }
예제 #2
0
파일: Tests.cs 프로젝트: substans/JohJSON
        public void EmptyArrays()
        {
            string   s = "{\"field\":[],\"second field\":{}}";
            JSONNode n = JSONNode.CreateFromString(s);

            Assert.AreEqual(s, n.ToString());
            Assert.AreEqual(0, n["field"].length);
            Assert.AreEqual(0, n["second field"].length);
        }
예제 #3
0
파일: Tests.cs 프로젝트: substans/JohJSON
        void TestEscapeChar(char c)
        {
            var x = new JSONNode();

            x[c.ToString()].asText = c.ToString();
            string testString = x.ToString();

            Console.WriteLine(testString);
            var y = JSONNode.CreateFromString(testString);

            Assert.AreEqual(x.ToString(), y.ToString());
            Assert.AreEqual(y[c.ToString()].asText[0], c);
            Assert.AreEqual(x[c.ToString()].asText[0], c);
        }
예제 #4
0
파일: Tests.cs 프로젝트: substans/JohJSON
        public void CorrectCommaSeparationException()
        {
            bool exeptionThrown = false;

            try
            {
                JSONNode.CreateFromString("{ \"field\" : false, \"second field\": true \"third field\":false }");
            }
            catch
            {
                exeptionThrown = true;
            }
            Assert.IsTrue(exeptionThrown);
        }
예제 #5
0
파일: Tests.cs 프로젝트: substans/JohJSON
        public void BooleanTest()
        {
            JSONNode n;

            n = JSONNode.CreateFromString("false");
            Assert.IsFalse(n.asBool);

            n = JSONNode.CreateFromString("true");
            Assert.IsTrue(n.asBool);

            n = JSONNode.CreateFromString("{ \"field\" : false }");
            Assert.IsFalse(n["field"].asBool);

            n = JSONNode.CreateFromString("{ \"field\" : true }");
            Assert.IsTrue(n["field"].asBool);
        }
예제 #6
0
파일: Tests.cs 프로젝트: substans/JohJSON
        public void NullTest()
        {
            JSONNode n = new JSONNode();

            n["A"] = null;
            Assert.AreEqual(NodeType.NULL, n["A"].nodeType);

            n["A"].asText = null;
            Assert.AreEqual(NodeType.NULL, n["A"].nodeType);

            n["A"].asInt = 10;
            Assert.AreEqual(NodeType.NUMBER, n["A"].nodeType);

            string json = "{\"list with null\":[0,1,2,3,null],\"nullfield\":null,\"nested\":{\"stuff\":null}}";
            var    node = JSONNode.CreateFromString(json);

            Assert.AreEqual(node.ToString(), json);

            json = "null";
            node = JSONNode.CreateFromString(json);
            Assert.AreEqual(node.ToString(), json);
        }
예제 #7
0
파일: Tests.cs 프로젝트: substans/JohJSON
        public void EmptyStrings()
        {
            JSONNode root = new JSONNode();

            root["root"]["X"].asText = string.Empty;
            root["root"]["Y"].asText = "";
            root["root"]["Z"].asText = null;

            Assert.AreEqual("", root["root"]["X"].asText);
            Assert.AreEqual("", root["root"]["Y"].asText);
            Assert.AreEqual(null, root["root"]["Z"].asText);

            string jsonString = "";

            jsonString = root.ToString();
            Console.WriteLine(jsonString);

            var n = JSONNode.CreateFromString(jsonString);

            Assert.AreEqual(string.Empty, n["root"]["Y"].asText);
            Assert.AreEqual("", n["root"]["Y"].asText);
            Assert.AreEqual(null, n["root"]["Z"].asText);
        }
예제 #8
0
파일: Tests.cs 프로젝트: substans/JohJSON
        public void SaveLoad()
        {
            List <string> s = new List <string>
            {
                "one", "two", "three", null, "five"
            };

            JSONNode n = new JSONNode()["root"];

            n["cash"].asInt     = 10;
            n["diamonds"].asInt = 100;
            SaveArray(n["saved numbers"], s);
            SaveArray(n["saved"][0], s);

            var      json   = n.ToString();
            JSONNode loaded = JSONNode.CreateFromString(json);

            Assert.AreEqual(loaded.ToString(), json);
            Console.WriteLine(json);
            List <string> tmpList = new List <string>();

            LoadArray(loaded["saved numbers"], tmpList);
            for (int i = 0; i < s.Count; ++i)
            {
                Assert.AreEqual(s[i], tmpList[i]);
            }
            tmpList.Clear();

            LoadArray(loaded["saved"][0], tmpList);
            for (int i = 0; i < s.Count; ++i)
            {
                Assert.AreEqual(s[i], tmpList[i]);
            }

            tmpList.Clear();
            Console.Write(json);
        }