Esempio n. 1
0
        public void TestEmptyStringConversion()
        {
            var value = JValue.Parse("\"\"");

            Assert.AreEqual(false, (bool)value);
            Assert.AreEqual(0, (int)value);
            Assert.AreEqual(0L, (long)value);
            Assert.AreEqual(0.0f, (float)value);
            Assert.AreEqual(0.0, (double)value);
            Assert.IsNotNull(value.ToArray());
            Assert.IsNotNull(value.ToObject());
            Assert.IsTrue(value.ToArray().SequenceEqual(new List <JValue>()));
            Assert.IsTrue(value.ToObject().SequenceEqual(new Dictionary <JValue, JValue>()));
        }
Esempio n. 2
0
        public void TestFlatObjectParsing()
        {
            var person = JValue.Parse(@"{
                ""first_name"": ""Mario"",
                ""last_name"":  ""Kim"",
                ""age"": 30,
                ""job"": ""Programmer""
            }");

            Assert.AreEqual("Mario", (string)person["first_name"]);
            Assert.AreEqual("Kim", (string)person["last_name"]);
            Assert.AreEqual(30, (int)person["age"]);
            Assert.AreEqual("Programmer", (string)person["job"]);
        }
Esempio n. 3
0
 public void TestParsedValueType()
 {
     Assert.AreEqual(JValue.TypeCode.Boolean, JValue.Parse("true").Type);
     Assert.AreEqual(JValue.TypeCode.Boolean, JValue.Parse("false").Type);
     Assert.AreEqual(JValue.TypeCode.Number, JValue.Parse("10").Type);
     Assert.AreEqual(JValue.TypeCode.Number, JValue.Parse("100").Type);
     Assert.AreEqual(JValue.TypeCode.Number, JValue.Parse("10.0").Type);
     Assert.AreEqual(JValue.TypeCode.Number, JValue.Parse("  50.0     ").Type);
     Assert.AreEqual(JValue.TypeCode.String, JValue.Parse("\"Hello\"").Type);
     Assert.AreEqual(JValue.TypeCode.String, JValue.Parse("\"World Hello\"").Type);
     Assert.AreEqual(JValue.TypeCode.Null, JValue.Parse("").Type);
     Assert.AreEqual(JValue.TypeCode.Null, JValue.Parse("null").Type);
     Assert.AreEqual(JValue.TypeCode.Null, new JValue().Type);
 }
Esempio n. 4
0
        public void TestNumberStringConversion()
        {
            var value = JValue.Parse("\"123.456\"");

            Assert.AreEqual(true, (bool)value);
            Assert.AreEqual(123, (int)value);
            Assert.AreEqual(123L, (long)value);
            Assert.AreEqual(123.456f, (float)value);
            Assert.AreEqual(123.456, (double)value);
            Assert.IsNotNull(value.ToArray());
            Assert.IsNotNull(value.ToObject());
            Assert.IsTrue(value.ToArray().SequenceEqual(new List <JValue>()));
            Assert.IsTrue(value.ToObject().SequenceEqual(new Dictionary <JValue, JValue>()));
        }
Esempio n. 5
0
        public void TestTrueConversion()
        {
            var value = JValue.Parse("true");

            Assert.AreEqual(1, (int)value);
            Assert.AreEqual(1L, (long)value);
            Assert.AreEqual(1.0f, (float)value);
            Assert.AreEqual(1.0, (double)value);
            Assert.AreEqual("true", (string)value);
            Assert.IsNotNull(value.ToArray());
            Assert.IsNotNull(value.ToObject());
            Assert.IsTrue(value.ToArray().SequenceEqual(new List <JValue>()));
            Assert.IsTrue(value.ToObject().SequenceEqual(new Dictionary <JValue, JValue>()));
        }
Esempio n. 6
0
        public void TestRuntimeValues()
        {
            AssertAreEqual(JValue.Null, new JValue());
            AssertAreEqual(JValue.Null, default(JValue));
            AssertAreEqual(JValue.Null, JValue.Parse("null"));
            AssertAreEqual(JValue.Null, JValue.Null);

            AssertAreEqual(JValue.EmptyString, Parse(@""""""));
            AssertAreEqual(JValue.EmptyArray, Parse(@"[   ]"));
            AssertAreEqual(JValue.EmptyObject, Parse(@"{   }"));
            AssertAreEqual(JValue.True, Parse(@"true"));
            AssertAreNotEqual(JValue.True, Parse(@"false"));
            AssertAreEqual(JValue.False, Parse(@"false"));
            AssertAreNotEqual(JValue.False, Parse(@"true"));
        }
Esempio n. 7
0
        public void TestBasicArrayParsing()
        {
            var array = JValue.Parse(@"   [10,  20    ,  [10  ,30,40 ]     ,30 ,""Hello""  , ""World"", 1]");

            Assert.AreEqual(array.Type, JValue.TypeCode.Array);

            var elements = array.Array().ToArray();

            Assert.AreEqual(10, (int)elements[0]);
            Assert.AreEqual(20, (int)elements[1]);
            Assert.AreEqual(JValue.TypeCode.Array, elements[2].Type);
            Assert.AreEqual(30, (int)elements[3]);
            Assert.AreEqual("Hello", (string)elements[4]);
            Assert.AreEqual("World", (string)elements[5]);
            Assert.AreEqual(1, (int)elements[6]);

            var subElements = array[2].ToArray();

            Assert.AreEqual(10, (int)subElements[0]);
            Assert.AreEqual(30, (int)subElements[1]);
            Assert.AreEqual(40, (int)subElements[2]);
        }
Esempio n. 8
0
 public void TestBasicValueParsing()
 {
     Assert.IsTrue(JValue.Parse("true"));
     Assert.IsFalse(JValue.Parse("false"));
     Assert.AreEqual(JValue.Parse("10").ToInt32(), 10);
 }
Esempio n. 9
0
 public void TestNull()
 => Assert.AreEqual(JValue.Null.GetHashCode(), JValue.Parse("null").GetHashCode());
Esempio n. 10
0
        public void TestAnotherLocatedValue()
        {
            var array = JValue.Parse("[123, 123]");

            Assert.AreEqual(array[0].GetHashCode(), array[1].GetHashCode());
        }
Esempio n. 11
0
 public void TestNumberAndDigitString(int n)
 => Assert.AreNotEqual(new JValue(n).GetHashCode(), JValue.Parse(FormattableString.Invariant($@"""{n}""")));
Esempio n. 12
0
 public void TestFalse()
 {
     Assert.AreEqual(JValue.False.GetHashCode(), JValue.Parse("false").GetHashCode());
     Assert.AreEqual(JValue.False.GetHashCode(), new JValue(false).GetHashCode());
 }
Esempio n. 13
0
 public void TestTrue()
 {
     Assert.AreEqual(JValue.True.GetHashCode(), JValue.Parse("true").GetHashCode());
     Assert.AreEqual(JValue.True.GetHashCode(), new JValue(true).GetHashCode());
 }
Esempio n. 14
0
 public float HalakJValue()
 {
     return(JValue.Parse(json)["y"]);
 }
Esempio n. 15
0
 public static JValue EnsureAscii(string s)
 => JValue.Parse(string.Concat("\"", HexEscape(s), "\""));
Esempio n. 16
0
 public void TraverseJson(string source)
 {
     Traverse(JValue.Parse(source));