示例#1
0
        public void FromLiteralReturnsFalseSingletonInstance()
        {
            // when
            var obtained = JsonBooleanValue.FromLiteral("false");

            // then
            Assert.That(obtained, Is.SameAs(JsonBooleanValue.False));
        }
示例#2
0
        public void FromLiteralReturnsNullForNonBooleanLiterals()
        {
            // when invalid case is used
            Assert.That(JsonBooleanValue.FromLiteral("TRUE"), Is.Null);
            Assert.That(JsonBooleanValue.FromLiteral("FALSE"), Is.Null);

            // when invalid literal strings is used
            Assert.That(JsonBooleanValue.FromLiteral("1234"), Is.Null);

            // when an empty string is passed
            Assert.That(JsonBooleanValue.FromLiteral(""), Is.Null);
        }
示例#3
0
        /// <summary>
        ///     Helper method for converting a simple JSON token to a JSON value.
        /// </summary>
        /// <param name="token">the token to convert to a JSON value</param>
        /// <returns>the converted JSON value</returns>
        private static JsonValue TokenToSimpleJsonValue(JsonToken token)
        {
            switch (token.TokenType)
            {
            case JsonTokenType.LITERAL_NULL:
                return(JsonNullValue.Null);

            case JsonTokenType.LITERAL_BOOLEAN:
                return(JsonBooleanValue.FromLiteral(token.Value));

            case JsonTokenType.VALUE_STRING:
                return(JsonStringValue.FromString(token.Value));

            case JsonTokenType.VALUE_NUMBER:
                return(JsonNumberValue.FromNumberLiteral(token.Value));

            default:
                throw new JsonParserException($"Internal parser error: Unexpected JSON token \"{token}\"");
            }
        }
示例#4
0
 public void FromLiteralReturnsNullIfLiteralNull()
 {
     // then
     Assert.That(JsonBooleanValue.FromLiteral(null), Is.Null);
 }