Esempio n. 1
0
        public void FromLiteralReturnsFalseSingletonInstance()
        {
            // when
            var obtained = JsonBooleanValue.FromLiteral("false");

            // then
            Assert.That(obtained, Is.SameAs(JsonBooleanValue.False));
        }
Esempio n. 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);
        }
Esempio n. 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}\"");
            }
        }
Esempio n. 4
0
 public void FromLiteralReturnsNullIfLiteralNull()
 {
     // then
     Assert.That(JsonBooleanValue.FromLiteral(null), Is.Null);
 }