public void ParseJsonWithStarComment()
 {
     string json = @"/* A Coment */{ /* A Coment */""T""/* A Coment */:/* A Coment */true/* A Coment */, ""F"":false }";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json, supportStartComment:true, relaxMode:true) as Hashtable;
     Assert.AreEqual(true, r["T"]);
     Assert.AreEqual(false, r["F"]);
 }
 public void ParseJsonWithNoQuoteForId()
 {
     string json = @"/* ""use relax"" */{ T:true, ""F"":false }";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json, supportStartComment:true) as Hashtable;
     Assert.AreEqual(true, r["T"]);
     Assert.AreEqual(false, r["F"]);
 }
        public void EmptyObject()
        {
            string json = @"{}";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;

            Assert.AreEqual(0, r.Count);
        }
 public void StringWithUniCode()
 {
     string json = @"{ ""v1"":""\u0041"", ""v2"":""\\\u0041""}";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
     Assert.AreEqual("A", r["v1"]);
     Assert.AreEqual("\\A", r["v2"]);
 }
        public void ParseNumber()
        {
            string json = @"{ ""N"":123 }";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;

            Assert.AreEqual(123.0, r["N"]);
        }
        public void EmptyArray()
        {
            string json = @"[]";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json) as ArrayList;

            Assert.AreEqual(0, r.Count);
        }
        public void TrailingComaInArray_Case002()
        {
            string json            = @"[
   


    ,
]";
            var    exceptionCaugth = false;

            try
            {
                var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
            }
            catch (ParserException ex)
            {
                Assert.AreEqual(5, ex.Line);
                Assert.AreEqual(5, ex.Col);
                exceptionCaugth = true;
            }
            if (!exceptionCaugth)
            {
                Assert.Fail(ERR_MSG_001);
            }
        }
コード例 #8
0
        public void StringWithUniCode()
        {
            string json = @"{ ""v1"":""\u0041"", ""v2"":""\\\u0041""}";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;

            Assert.AreEqual("A", r["v1"]);
            Assert.AreEqual("\\A", r["v2"]);
        }
コード例 #9
0
        public void ParseJsonWithNoQuoteForId()
        {
            string json = @"/* ""use relax"" */{ T:true, ""F"":false }";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json, supportStartComment: true) as Hashtable;

            Assert.AreEqual(true, r["T"]);
            Assert.AreEqual(false, r["F"]);
        }
 public void SlashBackSlash()
 {
     string json = @"{ ""slash1"":""/"",  ""slash2"":""\/"", ""backslash"":""\\""}";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
     Assert.AreEqual("/", r["slash1"]);
     Assert.AreEqual("/", r["slash2"]);
     Assert.AreEqual("\\", r["backslash"]);
 }
        public void ParseBool()
        {
            string json = @"{ ""T"":true, ""F"":false }";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;

            Assert.AreEqual(true, r["T"]);
            Assert.AreEqual(false, r["F"]);
        }
コード例 #12
0
        public void ParseJsonWithStarComment()
        {
            string json = @"/* A Coment */{ /* A Coment */""T""/* A Coment */:/* A Coment */true/* A Coment */, ""F"":false }";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json, supportStartComment: true, relaxMode: true) as Hashtable;

            Assert.AreEqual(true, r["T"]);
            Assert.AreEqual(false, r["F"]);
        }
コード例 #13
0
        public void SlashBackSlash()
        {
            string json = @"{ ""slash1"":""/"",  ""slash2"":""\/"", ""backslash"":""\\""}";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;

            Assert.AreEqual("/", r["slash1"]);
            Assert.AreEqual("/", r["slash2"]);
            Assert.AreEqual("\\", r["backslash"]);
        }
        public void ArrayWithValues()
        {
            string json = @"[1, 2.0, true, false, ""Hi"", ""1964-12-11T00:00:00Z"", null]";
            var    r    = new JSON.SyntaxValidator.Compiler().Validate(json) as ArrayList;

            Assert.AreEqual(7, r.Count);
            Assert.AreEqual(1.0, r[0]);
            Assert.AreEqual(2.0, r[1]);
            Assert.AreEqual(true, r[2]);
            Assert.AreEqual(false, r[3]);
            Assert.AreEqual("Hi", r[4]);
            Assert.AreEqual(new DateTime(1964, 12, 11), r[5]);
            Assert.AreEqual(null, r[6]);
        }
 public static void HandleException(string json, string expectedErrorMessage, int expectedLine, int expectedColumn, bool supportStarComments = false, bool relaxMode = false)
 {
     var exceptionCaugth = false;
     try
     {
         var r = new JSON.SyntaxValidator.Compiler().Validate(json, relaxMode:relaxMode, supportStartComment: supportStarComments ) as Hashtable;
     }
     catch (ParserException ex)
     {
         Assert.IsTrue(ex.Message.StartsWith(expectedErrorMessage));
         Assert.AreEqual(expectedLine, ex.Line);
         Assert.AreEqual(expectedColumn, ex.Col);
         exceptionCaugth = true;
     }
     if (!exceptionCaugth) Assert.Fail(ERR_MSG_001);
 }
        public static void HandleException(string json, string expectedErrorMessage, int expectedLine, int expectedColumn, bool supportStarComments = false, bool relaxMode = false)
        {
            var exceptionCaugth = false;

            try
            {
                var r = new JSON.SyntaxValidator.Compiler().Validate(json, relaxMode: relaxMode, supportStartComment: supportStarComments) as Hashtable;
            }
            catch (ParserException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith(expectedErrorMessage));
                Assert.AreEqual(expectedLine, ex.Line);
                Assert.AreEqual(expectedColumn, ex.Col);
                exceptionCaugth = true;
            }
            if (!exceptionCaugth)
            {
                Assert.Fail(ERR_MSG_001);
            }
        }
        public void SyntaxError_MissingArrayClosingBraket_Case001()
        {
            string json            = @"[1";
            var    exceptionCaugth = false;

            try
            {
                var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
            }
            catch (ParserException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith(JSON.SyntaxValidator.Compiler.SYNTAX_ERROR_009));
                Assert.AreEqual(1, ex.Line);
                Assert.AreEqual(2, ex.Col);
                exceptionCaugth = true;
            }
            if (!exceptionCaugth)
            {
                Assert.Fail(ERR_MSG_001);
            }
        }
 public void ParseDate()
 {
     string json = @"{ ""d"":""1964-12-11T00:00:00Z""}";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json);
 }
 public void ParseNumber()
 {
     string json = @"{ ""N"":123 }";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
     Assert.AreEqual(123.0, r["N"]);
 }        
 public void EmptyArray()
 {
     string json = @"[]";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json) as ArrayList;
     Assert.AreEqual(0, r.Count);
 }
 public void EmptyObject()
 {
     string json = @"{}";            
     var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
     Assert.AreEqual(0, r.Count);
 }
 public void ArrayWithValues()
 {
     string json = @"[1, 2.0, true, false, ""Hi"", ""1964-12-11T00:00:00Z"", null]";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json) as ArrayList;
     Assert.AreEqual(7, r.Count);
     Assert.AreEqual(1.0, r[0]);
     Assert.AreEqual(2.0, r[1]);
     Assert.AreEqual(true, r[2]);
     Assert.AreEqual(false, r[3]);
     Assert.AreEqual("Hi", r[4]);
     Assert.AreEqual(new DateTime(1964, 12, 11), r[5]);
     Assert.AreEqual(null, r[6]);            
 }
        public void TrailingComaInArray_Case002()
        {
            string json = @"[
   


    ,
]";
             var exceptionCaugth = false; 
            try
            {
                var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
            }
            catch (ParserException ex)
            {
                Assert.AreEqual(5, ex.Line);
                Assert.AreEqual(5, ex.Col);
                exceptionCaugth = true;
            }
            if (!exceptionCaugth) Assert.Fail(ERR_MSG_001);
        }
        public void SyntaxError_MissingObjectClosingBraket_Case001()
        {
            string json = @"{ 
                ""a""
                    :
1 ";
            var exceptionCaugth = false; 
            try
            {
                var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
            }
            catch (ParserException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith(JSON.SyntaxValidator.Compiler.SYNTAX_ERROR_010));
                Assert.AreEqual(4, ex.Line);
                Assert.AreEqual(1, ex.Col);
                exceptionCaugth = true;
            }
            if (!exceptionCaugth) Assert.Fail(ERR_MSG_001);
        }
 public void ParseDate()
 {
     string json = @"{ ""d"":""1964-12-11T00:00:00Z""}";
     var    r    = new JSON.SyntaxValidator.Compiler().Validate(json);
 }
 public void ParseBool()
 {
     string json = @"{ ""T"":true, ""F"":false }";
     var r = new JSON.SyntaxValidator.Compiler().Validate(json) as Hashtable;
     Assert.AreEqual(true, r["T"]);
     Assert.AreEqual(false, r["F"]);
 }