示例#1
0
            public void ArrayContainsJsonElement()
            {
                var e     = new JsonLiteral(1);
                var array = new JsonArray(e);

                Assert.IsTrue(array.Contains(e));
            }
示例#2
0
            public void CreateIntLiteral()
            {
                var literal = new JsonLiteral(1);

                AssertType(literal, JsonType.Number);
                AssertNumberTtype(literal, NumberType.Integer);
            }
示例#3
0
            public void CreateDoubleLiteral()
            {
                var literal = new JsonLiteral(1.1);

                AssertType(literal, JsonType.Number);
                AssertNumberTtype(literal, NumberType.Double);
            }
示例#4
0
        public IJsonNode ReadValue(JsonLiteral literal)
        {
            switch (literal)
            {
            case JsonLiteral.Quote:
                return(new JsonString(ReadString(expectStartToken: false)));

            case JsonLiteral.Number:
                return(ReadNumber());

            case JsonLiteral.Null:
                return(JsonNull.Instance);

            case JsonLiteral.True:
                return(JsonBool.True);

            case JsonLiteral.False:
                return(JsonBool.False);

            case JsonLiteral.Undefined:
                return(JsonUndefined.Instance);

            default:
                throw UnexpectedJsonException.From("value token", _buffer, _encoding);
            }
        }
示例#5
0
            public void ArrayContainsJsonElementWithSameValue()
            {
                var e1    = new JsonLiteral(1);
                var e2    = new JsonLiteral(1);
                var array = new JsonArray(e1);

                Assert.IsTrue(array.Contains(e2));
            }
示例#6
0
            public void JsonLiteralEqualMethod()
            {
                var e1 = new JsonLiteral(1);

                Assert.IsTrue(e1.Equals(e1));
                var e2 = new JsonLiteral(1);

                Assert.IsTrue(e1.Equals(e2));
            }
示例#7
0
            public void CreateObjectWithValues(
                [Values("p")] string key,
                [Values(1, "v", 2.1, false)] object value)
            {
                var obj = new JsonObject();

                obj[key] = new JsonLiteral(value);
                Assert.AreEqual(value, ((JsonLiteral)obj[key]).AsValue());
            }
示例#8
0
            public void JsonLiteralEqualComparator()
            {
                var e1 = new JsonLiteral(1);
                var e2 = new JsonLiteral(1);

                Assert.IsTrue(e1 == e2);
                e2 = null;
                Assert.IsFalse(e1 == e2);
                e1 = null;
                Assert.IsTrue(e1 == e2);
            }
示例#9
0
            public void LiteralToStringMethod(object l)
            {
                var lit = new JsonLiteral(l);

                if (l is bool)
                {
                    Assert.AreEqual(lit.ToString(), l.ToString().ToLower());
                }
                else
                {
                    Assert.AreEqual(lit.ToString(), l.ToString());
                }
            }
示例#10
0
        private static JsonElement ParseValue()
        {
            Next();
            if (_current.TokenType == TokenType.Quote)
            {
                Next();
                string v = "";
                if (_current.TokenType == TokenType.Word)
                {
                    v = _current.Symbol;
                    Next();
                }
                if (_current.TokenType != TokenType.Quote)
                {
                    throw new JsonParseException("");
                }
                Next();
                return(new JsonLiteral(v));
            }
            if (_current.TokenType == TokenType.Number)
            {
                JsonLiteral literal;
                var         sb = new StringBuilder();
                sb.Append(_current.Symbol);
                Next();
                if (_current.TokenType == TokenType.Decimal)
                {
                    sb.Append(_current.Symbol);
                    Next();
                    if (_current.TokenType != TokenType.Number)
                    {
                        throw new JsonParseException("Number after decimal place required.");
                    }
                    sb.Append(_current.Symbol);
                    Next();
                    literal = new JsonLiteral(double.Parse(sb.ToString()));
                }
                else
                {
                    literal = new JsonLiteral(int.Parse(sb.ToString()));
                }

                return(literal);
            }

            return(null);
        }
示例#11
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }
            JsonLiteral other = (JsonLiteral)obj;

            return(value == other.value);
        }
示例#12
0
 public void CreateLiteralFromValue(object v)
 {
     JsonLiteral.FromValue(v);
 }
示例#13
0
            public void CreateBooleanLiteral()
            {
                var literal = new JsonLiteral(true);

                AssertType(literal, JsonType.Boolean);
            }
示例#14
0
            public void CreateStringLiteral()
            {
                var literal = new JsonLiteral("string");

                AssertType(literal, JsonType.String);
            }
示例#15
0
 public static UnexpectedJsonException InObject(JsonLiteral literal)
 {
     return(new UnexpectedJsonException("An object can not directly contain " + literal));
 }
示例#16
0
 public static UnexpectedJsonException InArray(JsonLiteral literal)
 {
     return(new UnexpectedJsonException("An array can not directly contain " + literal));
 }
示例#17
0
            public void LiteralStringToString()
            {
                var literal = new JsonLiteral("String Value");

                Assert.AreEqual(literal.ToString(), "String Value");
            }
示例#18
0
            public void LiteralIntToString()
            {
                var literal = new JsonLiteral(1);

                Assert.AreEqual(literal.ToString(), "1");
            }
示例#19
0
            public void LiteralBooleanToString()
            {
                var literal = new JsonLiteral(false);

                Assert.AreEqual(literal.ToString(), "false");
            }
示例#20
0
            public void LiteralDoubleToString()
            {
                var literal = new JsonLiteral(1.1);

                Assert.AreEqual(literal.ToString(), "1.1");
            }
示例#21
0
 private void AssertType(JsonLiteral literal, JsonType actual)
 {
     Assert.AreEqual(literal.Type, actual);
 }
示例#22
0
 private void AssertNumberTtype(JsonLiteral literal, NumberType actual)
 {
     Assert.AreEqual(literal.NumberType, actual);
 }
示例#23
0
 /// <summary>
 /// 获取Json格式的结构
 /// </summary>
 /// <param name="literal"></param>
 /// <param name="type"></param>
 /// <param name="text"></param>
 /// <param name="errors"></param>
 /// <returns></returns>
 private static object GetStruct(JsonLiteral literal, Struct type, string text, List <string> errors)
 {
     return(null);// JsonUtil.ParseJsonText(text, type, null, errors);
 }