private void assertBoolParseFail(string json) { Assert.Throws <JsonParseException>(() => JsonBool.Parse(json)); JsonBool val; Assert.IsFalse(JsonBool.TryParse(json, out val)); Assert.IsNull(val); }
private void assertBoolParseSucc(string json, bool val) { JsonBool t = null; Assert.DoesNotThrow(() => { t = JsonBool.Parse(json); }); Assert.AreEqual(val, (bool)t); Assert.IsTrue(JsonBool.TryParse(json, out t)); Assert.AreEqual(val, (bool)t); }
public void ParseLiteral() { Assert.IsFalse(JsonBool.Parse("false").Value); Assert.IsTrue(JsonBool.Parse("true").Value); Assert.AreEqual("false", new JsonBool(false).ToString()); Assert.AreEqual("true", new JsonBool(true).ToString()); Assert.AreEqual("id", JsonText.Parse("\"id\"").Value); Assert.AreEqual(89, JsonNumber.Parse("89").Byte); Assert.AreEqual("\"{<guid>}\"", JsonText.Parse("\"\\\"{<guid>}\\\"\"").Value); Assert.AreEqual(-0.5m, JsonNumber.Parse("-0.5").Decimal); Assert.AreEqual(500d, JsonNumber.Parse("+0.5E3").Double); Assert.AreEqual(0.0005d, JsonNumber.Parse("0.5E-3").Double); JsonObject o = new JsonObject(("name", new JsonText("Lars \"kodekarl\" Hammer"))); const string json = "{\"name\":\"Lars \\\"kodekarl\\\" Hammer\"}"; Assert.AreEqual(json, o.ToString()); Assert.AreEqual(json, JsonValue.Parse(json).ToString()); Assert.AreEqual(json, JsonValue.Parse(o.Format()).ToString()); }