Exemple #1
0
        public static bool Equals(JValue left, JValue right)
        {
            var leftType  = left.Type;
            var rightType = right.Type;

            if (leftType == rightType)
            {
                switch (leftType)
                {
                case TypeCode.Null: return(true);

                case TypeCode.Boolean: return(left.ToBooleanCore() == right.ToBooleanCore());

                case TypeCode.Number: return(JNumber.Equals(left.ToNumberCore(JNumber.NaN), right.ToNumberCore(JNumber.NaN)));

                case TypeCode.String: return(EqualsString(left, right));

                case TypeCode.Array: return(SequenceEqual(left.Array().GetEnumerator(), right.Array().GetEnumerator(), Equals));

                case TypeCode.Object: return(SequenceEqual(left.Object().GetEnumerator(), right.Object().GetEnumerator(), EqualsMember));
                }
            }

            return(false);
        }
Exemple #2
0
        public static int Compare(JValue left, JValue right)
        {
            var leftType  = left.typeCode;
            var rightType = right.typeCode;

            if (leftType == rightType)
            {
                switch (leftType)
                {
                case TypeCode.Null:
                    return(0);

                case TypeCode.Boolean:
                    return(left.ToBooleanCore().CompareTo(right.ToBooleanCore()));

                case TypeCode.Number:
                    return(JNumber.Compare(left.ToNumberCore(JNumber.NaN), right.ToNumberCore(JNumber.NaN)));

                case TypeCode.String:
                    return(SequenceCompare <char, CharEnumerator>(left.GetCharEnumerator(), right.GetCharEnumerator(), (x, y) => x.CompareTo(y)));

                case TypeCode.Array:
                    return(SequenceCompare(left.GetArrayItems(), right.GetArrayItems(), Compare));

                case TypeCode.Object:
                    return(SequenceCompare(left.GetObjectKeyValues().GetEnumerator(), right.GetObjectKeyValues(), CompareMember));

                default:
                    return(0);
                }
            }

            return(((int)leftType).CompareTo((int)rightType));
        }
Exemple #3
0
        public static bool Equals(JValue left, JValue right)
        {
            var leftType  = left.typeCode;
            var rightType = right.typeCode;

            if (leftType == rightType)
            {
                switch (leftType)
                {
                case TypeCode.Null:
                    return(true);

                case TypeCode.Boolean:
                    return(left.ToBooleanCore() == right.ToBooleanCore());

                case TypeCode.Number:
                    return(JNumber.Equals(left.ToNumberCore(JNumber.NaN), right.ToNumberCore(JNumber.NaN)));

                case TypeCode.String:
                    return(EqualsString(left, right));

                case TypeCode.Array:
                    return(SequenceEqual <JValue, ArrayEnumerator>(left.GetArrayItems(), right.GetArrayItems(), Equals));

                case TypeCode.Object:
                    return(SequenceEqual <KeyValuePair, ObjectKeyValueEnumerator>(left.GetObjectKeyValues(), right.GetObjectKeyValues(), EqualsMember));
                }
            }

            return(false);
        }
Exemple #4
0
        public void Parse(string input, string expectedIntegerPart, string expectedFractionalPart = null, string expectedExponent = null)
        {
            var number = JNumber.Parse(input);

            if (string.IsNullOrEmpty(expectedIntegerPart) == false)
            {
                Assert.AreEqual(expectedIntegerPart, number.IntegerPart.ToString());
            }
            else
            {
                Assert.IsTrue(number.IntegerPart.IsNaN);
            }

            if (string.IsNullOrEmpty(expectedFractionalPart) == false)
            {
                Assert.AreEqual(expectedFractionalPart, number.FractionalPart.ToString());
            }
            else
            {
                Assert.IsTrue(number.FractionalPart.IsNaN);
            }

            if (string.IsNullOrEmpty(expectedExponent) == false)
            {
                Assert.AreEqual(expectedExponent, number.Exponent.ToString());
            }
            else
            {
                Assert.IsTrue(number.Exponent.IsNaN);
            }
        }
Exemple #5
0
 public int JValueParse()
 {
     return
         (JNumber.ParseInt32(shortNumber) +
          JNumber.ParseInt32(longNumber) +
          JNumber.ParseInt32(negativeNumber) +
          JNumber.ParseInt32(minNumber) +
          JNumber.ParseInt32(maxNumber));
 }
Exemple #6
0
 public void Equality(string left, string right)
 {
     Assert.IsTrue(JNumber.Equals(JNumber.Parse(left), JNumber.Parse(right)));
     if (left.StartsWith("-", StringComparison.Ordinal) == false)
     {
         left  = FormattableString.Invariant($"-{left}");
         right = FormattableString.Invariant($"-{right}");
         Assert.IsTrue(JNumber.Equals(JNumber.Parse(left), JNumber.Parse(right)));
     }
 }
Exemple #7
0
        public JNumber ToNumber(JNumber defaultValue)
        {
            switch (Type)
            {
            case TypeCode.Boolean: return(ToBooleanCore() ? JNumber.One : JNumber.Zero);

            case TypeCode.Number: return(ToNumberCore(defaultValue));

            case TypeCode.String: return(ConvertForNumberParsing().ToNumberCore(defaultValue));

            default: return(JNumber.NaN);
            }
        }
Exemple #8
0
 private double ToDoubleCore(double defaultValue)
 => JNumber.ParseDouble(source, startIndex, defaultValue);
Exemple #9
0
 public void TwoNumber_Are_Equal_But_NotEquivalent(string left, string right)
 {
     Assert.IsTrue(
         JNumber.Equals(JNumber.Parse(left), JNumber.Parse(right)) &&
         JNumber.Compare(JNumber.Parse(left), JNumber.Parse(right)) != 0);
 }
Exemple #10
0
 public int LeadingZeros(string input)
 => JNumber.Parse(input).FractionalPart.LeadingZeros;
Exemple #11
0
 public void Inequality(string left, string right)
 => Assert.IsFalse(JNumber.Equals(JNumber.Parse(left), JNumber.Parse(right)));
Exemple #12
0
 public void Compare(string less, string greater)
 {
     Assert.IsTrue(JNumber.Compare(JNumber.Parse(less), JNumber.Parse(greater)) < 0);
     Assert.IsTrue(JNumber.Compare(JNumber.Parse(greater), JNumber.Parse(less)) > 0);
 }
Exemple #13
0
 private byte ToByteCore(byte defaultValue)
 => (byte)JNumber.ParseInt32(source, startIndex, defaultValue);      // TODO
Exemple #14
0
 private int ToInt32Core(int defaultValue)
 => JNumber.ParseInt32(source, startIndex, defaultValue);
Exemple #15
0
 static int Parse(string s) => JNumber.ParseInt32(s);
Exemple #16
0
 private long ToInt64Core(long defaultValue)
 => JNumber.ParseInt64(source, startIndex, defaultValue);
Exemple #17
0
 private float ToSingleCore(float defaultValue)
 => JNumber.ParseSingle(source, startIndex, defaultValue);
Exemple #18
0
 public double JValueParse()
 {
     return
         (JNumber.ParseDouble(number1) +
          JNumber.ParseDouble(number2));
 }
Exemple #19
0
 private decimal ToDecimalCore(decimal defaultValue)
 => JNumber.ParseDecimal(source, startIndex, length, defaultValue);
Exemple #20
0
 public float JValueParse()
 {
     return
         (JNumber.ParseSingle(number1) +
          JNumber.ParseSingle(number2));
 }
Exemple #21
0
 private JNumber ToNumberCore(JNumber defaultValue)
 => JNumber.TryParse(source, startIndex, out var value) ? value : defaultValue;