Esempio n. 1
0
        public void TestUndefined()
        {
            var json   = "\t undefined,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.Equal(JsonTokenType.UnquotedString, token.Type);
            Assert.Equal("undefined", token.StringValue);
            Assert.Equal(',', buffer.Read());
        }
Esempio n. 2
0
        public void TestUnquotedString()
        {
            var json   = "\t name123:1";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.Equal(JsonTokenType.UnquotedString, token.Type);
            Assert.Equal("name123", token.StringValue);
            Assert.Equal(':', buffer.Read());
        }
Esempio n. 3
0
        public void Test3CharacterString()
        {
            var json   = "\t \"123\"x";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.Equal(JsonTokenType.String, token.Type);
            Assert.Equal("123", token.StringValue);
            Assert.Equal('x', buffer.Read());
        }
Esempio n. 4
0
        public void TestEscapeSequences()
        {
            var json   = "\t \"x\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0030y\"x";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.Equal(JsonTokenType.String, token.Type);
            Assert.Equal("x\"\\/\b\f\n\r\t0y", token.StringValue);
            Assert.Equal('x', buffer.Read());
        }
        public void TestEndArray()
        {
            var json   = "\t ]x";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.EndArray, token.Type);
            Assert.AreEqual("]", token.Lexeme);
            Assert.AreEqual('x', buffer.Read());
        }
        public void TestNameSeparator()
        {
            var json   = "\t :x";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.Colon, token.Type);
            Assert.AreEqual(":", token.Lexeme);
            Assert.AreEqual('x', buffer.Read());
        }
        public void TestRegularExpressionEmpty()
        {
            var json   = "\t //,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.RegularExpression, token.Type);
            Assert.AreEqual("//", token.Lexeme);
            Assert.AreEqual(',', buffer.Read());
        }
        public void TestNull()
        {
            var json   = "\t null,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.UnquotedString, token.Type);
            Assert.AreEqual("null", token.StringValue);
            Assert.AreEqual(',', buffer.Read());
        }
        public void TestBeginObject()
        {
            var json   = "\t {x";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.BeginObject, token.Type);
            Assert.AreEqual("{", token.Lexeme);
            Assert.AreEqual('x', buffer.Read());
        }
        public void TestMinusZeroExponentMinusTwelve()
        {
            var json   = "\t -1e-12,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.Double, token.Type);
            Assert.AreEqual("-1e-12", token.Lexeme);
            Assert.AreEqual(',', buffer.Read());
        }
        public void TestMinusOnePointTwo()
        {
            var json   = "\t -1.2,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.Double, token.Type);
            Assert.AreEqual("-1.2", token.Lexeme);
            Assert.AreEqual(',', buffer.Read());
        }
        public void TestZeroExponentOne()
        {
            var json   = "\t 0e1,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.Double, token.Type);
            Assert.AreEqual("0e1", token.Lexeme);
            Assert.AreEqual(',', buffer.Read());
        }
        public void TestTwelve()
        {
            var json   = "\t 12,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.Int32, token.Type);
            Assert.AreEqual("12", token.Lexeme);
            Assert.AreEqual(',', buffer.Read());
        }
Esempio n. 14
0
        public void TestZero()
        {
            var json   = "\t 0,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.Equal(JsonTokenType.Int32, token.Type);
            Assert.Equal("0", token.Lexeme);
            Assert.Equal(',', buffer.Read());
        }
        public void TestRegularExpressionPatternAndOptions()
        {
            var json   = "\t /pattern/imxs,";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.RegularExpression, token.Type);
            Assert.AreEqual("/pattern/imxs", token.Lexeme);
            Assert.AreEqual(',', buffer.Read());
        }
Esempio n. 16
0
        public void TestEndOfFile()
        {
            var json   = "\t ";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.Equal(JsonTokenType.EndOfFile, token.Type);
            Assert.Equal("<eof>", token.Lexeme);
            Assert.Equal(-1, buffer.Read());
        }
        public void TestEmptyString()
        {
            var json   = "\t \"\"x";
            var buffer = new JsonBuffer(json);
            var token  = JsonScanner.GetNextToken(buffer);

            Assert.AreEqual(JsonTokenType.String, token.Type);
            Assert.AreEqual("", token.StringValue);
            Assert.AreEqual('x', buffer.Read());
        }