public void ctor_single() { const string expected = "1.2300000190734863"; var actual = new JsonNumber(1.23f).Value; Assert.Equal(expected, actual); }
public void ctor_decimal() { const string expected = "1.23"; var actual = new JsonNumber(1.23m).Value; Assert.Equal(expected, actual); }
public void ctor_string() { const string expected = "123"; var actual = new JsonNumber(expected).Value; Assert.Equal(expected, actual); }
public void ctor_short() { const short value = 123; const string expected = "123"; var actual = new JsonNumber(value).Value; Assert.Equal(expected, actual); }
public void JsonNumberToInt(string raw) { var token = new JsonToken { Value = raw, Type = JsonTokenType.Number, Line = 1, Column = 321 }; var json = new JsonNumber(token); int value = FromJsonNumberToInt(json); Assert.Equal(123, value); Assert.Equal(1, json.Line); Assert.Equal(321, json.Column); }
private static JsonReader Export(JsonNumber value) { JsonRecorder writer = new JsonRecorder(); JsonConvert.Export(value, writer); return writer.CreatePlayer(); }
public void op_ToSingle() { const float expected = 1.23f; var actual = new JsonNumber(XmlConvert.ToString(expected)).ToSingle(); Assert.Equal(expected, actual); }
public void op_ToInt32() { const int expected = 123; var actual = new JsonNumber(XmlConvert.ToString(expected)).ToInt32(); Assert.Equal(expected, actual); }
public void op_ToInt64() { const long expected = 12345; var actual = new JsonNumber(XmlConvert.ToString(expected)).ToInt64(); Assert.Equal(expected, actual); }
public void op_ToDecimal() { const decimal expected = 1.23m; var actual = new JsonNumber(XmlConvert.ToString(expected)).ToDecimal(); Assert.Equal(expected, actual); }
public void op_ToDouble(string value) { const double expected = 123.45; var actual = new JsonNumber(value).ToDouble(); Assert.Equal(expected, actual); }
static void AssertEqual(double expectedValue, JsonNumber result) => Assert.IsTrue(Math.Abs(result - expectedValue) < double.Epsilon);
public void op_Number_int() { var expected = new JsonNumber("value"); var document = new JsonArray { Values = { expected } }; var actual = document.Number(0); Assert.Equal(expected, actual); }
public JsonString(JsonNumber n) { this.val = n.ToString(); }
public static void TestEquals() { var jsonNumber = new JsonNumber(123); Assert.True(jsonNumber.Equals(new JsonNumber(123))); Assert.True(new JsonNumber(123).Equals(jsonNumber)); Assert.True(jsonNumber.Equals(new JsonNumber((ushort)123))); Assert.True(new JsonNumber((ushort)123).Equals(jsonNumber)); Assert.True(jsonNumber.Equals(new JsonNumber("123"))); Assert.True(new JsonNumber("123").Equals(jsonNumber)); Assert.False(jsonNumber.Equals(new JsonNumber("123e0"))); Assert.False(new JsonNumber("123e0").Equals(jsonNumber)); Assert.False(jsonNumber.Equals(new JsonNumber("123e1"))); Assert.False(new JsonNumber("123e1").Equals(jsonNumber)); Assert.False(jsonNumber.Equals(new JsonNumber(17))); Assert.False(new JsonNumber(17).Equals(jsonNumber)); Assert.True(jsonNumber == new JsonNumber(123)); Assert.True(jsonNumber != new JsonNumber(17)); JsonNode jsonNode = new JsonNumber(123); Assert.True(jsonNumber.Equals(jsonNode)); IEquatable <JsonNumber> jsonNumberIEquatable = jsonNumber; Assert.True(jsonNumberIEquatable.Equals(jsonNumber)); Assert.True(jsonNumber.Equals(jsonNumberIEquatable)); Assert.False(jsonNumber.Equals(null)); object jsonNumberCopy = jsonNumber; object jsonNumberObject = new JsonNumber(123); Assert.True(jsonNumber.Equals(jsonNumberObject)); Assert.True(jsonNumberCopy.Equals(jsonNumberObject)); Assert.True(jsonNumberObject.Equals(jsonNumber)); jsonNumber = new JsonNumber(); Assert.True(jsonNumber.Equals(new JsonNumber())); Assert.False(jsonNumber.Equals(new JsonNumber(5))); Assert.False(jsonNumber.Equals(new Exception())); JsonNumber jsonNumberNull = null; Assert.False(jsonNumber == jsonNumberNull); Assert.False(jsonNumberNull == jsonNumber); Assert.True(jsonNumber != jsonNumberNull); Assert.True(jsonNumberNull != jsonNumber); JsonNumber otherJsonNumberNull = null; Assert.True(jsonNumberNull == otherJsonNumberNull); }
public IList GetListObjects(string listName, string itemName, Type type, DAopConvert convert) { IList listObjs = null; Object jsonObject = json[listName]; IList jsonList = null; if (jsonObject is IList) { jsonList = jsonObject as IList; } else if (jsonObject is IDictionary) { IDictionary jsonMap = jsonObject as IDictionary; if (jsonMap != null && jsonMap.Count > 0) { Object itemTmp = jsonMap[itemName]; if (itemTmp == null && listName != null) { itemTmp = jsonMap[listName.Substring(0, listName.Length - 1)]; } if (itemTmp is IList) { jsonList = itemTmp as IList; } } } if (jsonList != null && jsonList.Count > 0) { Type listType = typeof(List <>).MakeGenericType(new Type[] { type }); listObjs = Activator.CreateInstance(listType) as IList; foreach (object item in jsonList) { if (typeof(IDictionary).IsAssignableFrom(item.GetType())) // object { IDictionary subMap = item as IDictionary; object subObj = convert(new AopJsonReader(subMap), type); if (subObj != null) { listObjs.Add(subObj); } } else if (typeof(IList).IsAssignableFrom(item.GetType())) // list/array { // TODO not support yet } else if (typeof(JsonNumber).IsAssignableFrom(item.GetType())) // list/array { JsonNumber jsonNumber = (JsonNumber)item; if (typeof(long).IsAssignableFrom(type)) { listObjs.Add(jsonNumber.ToInt64()); } else if (typeof(int).IsAssignableFrom(type)) { listObjs.Add(jsonNumber.ToInt32()); } else if (typeof(double).IsAssignableFrom(type)) { listObjs.Add(jsonNumber.ToDouble()); } } else // boolean, string, null { listObjs.Add(item); } } } return(listObjs); }
public void EqualsObject_SameInstance_True() { JsonNumber obj = 1; EqualityTester.AssertEquals <JsonNumber>(obj, obj); }
public void EqualsJsonNumber_SameInstance_True() { JsonNumber obj = 1; EqualityTester.AssertEquals(obj, obj); }
public void op_Number_string() { const string name = "name"; var expected = new JsonNumber("value"); var document = new JsonObject { new JsonPair(name, expected) }; var actual = document.Number(name); Assert.Equal(expected, actual); }
public static void JsonNumberMethodsTest() { JsonNumber intA = 233, intB = 666, intC = 666, floatA = 43.25, floatB = 96.625, floatC = 96.625; object objA = ""; Assert.True(floatA.IsFloat); Assert.True(floatB.IsFloat); Assert.False(intA.IsFloat); Assert.False(intB.IsFloat); Assert.True(intB == intC); Assert.False(intB != intC); Assert.Equal <double>(233, intA); Assert.Equal <double>(43.25, floatA); Assert.True(intB.Equals(intC)); Assert.False(intA.Equals(intB)); Assert.False(intA.Equals(floatA)); Assert.True(floatB.Equals(floatC)); Assert.True(intB.Equals((object)intB)); Assert.True(intB.Equals((object)intC)); Assert.False(intB.Equals(objA)); Assert.False(intB.Equals((object)null)); Assert.False(intB.Equals(null)); Assert.Equal(intB.ValueInt.GetHashCode(), intB.GetHashCode()); Assert.Equal(floatB.ValueFloat.GetHashCode(), floatB.GetHashCode()); Assert.Throws <ArgumentOutOfRangeException>(() => new JsonNumber("invalid")); }