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); }
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); }
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); }
public void CorrectCommaSeparationException() { bool exeptionThrown = false; try { JSONNode.CreateFromString("{ \"field\" : false, \"second field\": true \"third field\":false }"); } catch { exeptionThrown = true; } Assert.IsTrue(exeptionThrown); }
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); }
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); }
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); }
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); }