Esempio n. 1
0
        public void ParseError4()
        {
            var src = @"{age: 120 d";

              var parser = new JP(  new JL( new StringSource(src) ), throwErrors: true  );

              parser.Parse();
        }
Esempio n. 2
0
        public void ParseError5()
        {
            var src = @"['age', 120 d";

            var parser = new JP(new JL(new StringSource(src)), throwErrors: true);

            parser.Parse();
        }
Esempio n. 3
0
        public void ParseError7()
        {
            var src = @"{ true: 120}";

            var parser = new JP(new JL(new StringSource(src)), throwErrors: true);

            parser.Parse();
        }
Esempio n. 4
0
        public void ParseError8()
        {
            var src = @"{ a: 120, b: 140, a: 12}";

            var parser = new JP(new JL(new StringSource(src)), throwErrors: true);

            parser.Parse();
        }
Esempio n. 5
0
        public void RootLiteral_NegativeScientificDouble()
        {
            var src = @"-12e2";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Aver.AreObjectsEqual(-12e2d, parser.ResultContext.ResultObject);
        }
Esempio n. 6
0
        public void RootLiteral_PositiveDouble()
        {
            var src = @"+12.7";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Aver.AreObjectsEqual(12.7, parser.ResultContext.ResultObject);
        }
Esempio n. 7
0
        public void RootLiteral_Null()
        {
            var src = @"null";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Aver.IsNull(parser.ResultContext.ResultObject);
        }
Esempio n. 8
0
        public void RootLiteral_NegativeDecimalInt()
        {
            var src = @"-16";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Aver.AreObjectsEqual(-16, parser.ResultContext.ResultObject);
        }
Esempio n. 9
0
        public void RootLiteral_PositiveScientificDouble()
        {
            var src = @"+12e2";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Assert.AreEqual(12e2d, parser.ResultContext.ResultObject);
        }
Esempio n. 10
0
        public void ParseError1()
        {
            var src = @"{age 120}";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Assert.AreEqual(1, parser.Messages.Count);
            Assert.AreEqual((int)JSONMsgCode.eColonOperatorExpected, parser.Messages[0].Code);
        }
Esempio n. 11
0
        public void RootLiteral_String()
        {
            var src = @"'abc'";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Assert.AreEqual("abc", parser.ResultContext.ResultObject);
        }
Esempio n. 12
0
        public void ParseError1()
        {
            var src = @"{age 120}";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.AreEqual(1, parser.Messages.Count);
              Assert.AreEqual((int)JSONMsgCode.eColonOperatorExpected,  parser.Messages[0].Code);
        }
Esempio n. 13
0
        public void RootLiteral_Int()
        {
            var src = @"12";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Assert.AreEqual(12, parser.ResultContext.ResultObject);
        }
Esempio n. 14
0
        public void RootLiteral_PositiveDecimalInt()
        {
            var src = @"+16";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Assert.AreEqual(16, parser.ResultContext.ResultObject);
        }
Esempio n. 15
0
        public void RootLiteral_False()
        {
            var src = @"false";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Aver.AreObjectsEqual(false, parser.ResultContext.ResultObject);
        }
Esempio n. 16
0
        public void RootLiteral_NegativeHexInt()
        {
            var src = @"-0xf";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();


            Assert.AreEqual(-15, parser.ResultContext.ResultObject);
        }
Esempio n. 17
0
        public void RootEmptyArray()
        {
            var src = @"[]";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Aver.IsTrue(parser.ResultContext.ResultObject is JSONDataArray);
            var arr = (JSONDataArray)parser.ResultContext.ResultObject;

            Aver.AreEqual(0, arr.Count);
        }
Esempio n. 18
0
        public void RootEmptyObject()
        {
            var src = @"{}";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Aver.IsTrue(parser.ResultContext.ResultObject is JSONDataMap);
            var obj = (JSONDataMap)parser.ResultContext.ResultObject;

            Aver.AreEqual(0, obj.Count);
        }
Esempio n. 19
0
        public void RootEmptyArray()
        {
            var src = @"[]";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Assert.IsInstanceOf(typeof(JSONDataArray), parser.ResultContext.ResultObject);
            var arr = (JSONDataArray)parser.ResultContext.ResultObject;

            Assert.AreEqual(0, arr.Count);
        }
Esempio n. 20
0
        public void RootEmptyObject()
        {
            var src = @"{}";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
            var obj = (JSONDataMap)parser.ResultContext.ResultObject;

            Assert.AreEqual(0, obj.Count);
        }
Esempio n. 21
0
        public void RootObject()
        {
            var src = @"{a: 1, b: true, c: null}";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
            var obj = (JSONDataMap)parser.ResultContext.ResultObject;

            Assert.AreEqual(3, obj.Count);
            Assert.AreEqual(1, obj["a"]);
            Assert.AreEqual(true, obj["b"]);
            Assert.AreEqual(null, obj["c"]);
        }
Esempio n. 22
0
        public void RootObject()
        {
            var src = @"{a: 1, b: true, c: null}";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Aver.IsTrue(parser.ResultContext.ResultObject is JSONDataMap);
            var obj = (JSONDataMap)parser.ResultContext.ResultObject;

            Aver.AreEqual(3, obj.Count);
            Aver.AreObjectsEqual(1, obj["a"]);
            Aver.AreObjectsEqual(true, obj["b"]);
            Aver.IsNull(obj["c"]);
        }
Esempio n. 23
0
        public void RootArray()
        {
            var src = @"[1,2,3]";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Aver.IsTrue(parser.ResultContext.ResultObject is JSONDataArray);
            var arr = (JSONDataArray)parser.ResultContext.ResultObject;

            Aver.AreEqual(3, arr.Count);
            Aver.AreObjectsEqual(1, arr[0]);
            Aver.AreObjectsEqual(2, arr[1]);
            Aver.AreObjectsEqual(3, arr[2]);
        }
Esempio n. 24
0
        public void RootObjectWithArray()
        {
            var src = @"{age: 12, numbers: [4,5,6,7,8,9], name: ""Vasya""}";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
            var obj = (JSONDataMap)parser.ResultContext.ResultObject;

            Assert.AreEqual(3, obj.Count);
            Assert.AreEqual(12, obj["age"]);
            Assert.AreEqual("Vasya", obj["name"]);
            Assert.AreEqual(6, ((JSONDataArray)obj["numbers"]).Count);
            Assert.AreEqual(7, ((JSONDataArray)obj["numbers"])[3]);
        }
Esempio n. 25
0
        public void RootObjectWithSubObjects()
        {
            var src = @"{age: 120, numbers: {positive: true, bad: 12.7}, name: ""Vasya""}";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
            var obj = (JSONDataMap)parser.ResultContext.ResultObject;

            Assert.AreEqual(3, obj.Count);
            Assert.AreEqual(120, obj["age"]);
            Assert.AreEqual("Vasya", obj["name"]);
            Assert.AreEqual(true, ((JSONDataMap)obj["numbers"])["positive"]);
            Assert.AreEqual(12.7, ((JSONDataMap)obj["numbers"])["bad"]);
        }
Esempio n. 26
0
        public void RootEmptyObject()
        {
            var src = @"{}";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
              var obj = (JSONDataMap)parser.ResultContext.ResultObject;

              Assert.AreEqual(0, obj.Count);
        }
Esempio n. 27
0
        public void RootComplexArray()
        {
            var src =
                @"[
 {FirstName: ""Oleg"",  //comments dont hurt
  'LastName': ""Ogurtsov"",
  ""Middle Name"": 'V.',
  ""Crazy\nName"": 'Shamanov',
  LuckyNumbers: [4,5,6,7,8,9], 
  /* comments
  do not break stuff */
  |* in this JSON superset *|
  History: 
  [
    #HOT_TOPIC
    {Date: '05/14/1905', What: 'Tsushima'},
    #MODERN_TOPIC
    {Date: '09/01/1939', What: 'WW2 Started', Who: ['Germany','USSR', 'USA', 'Japan', 'Italy', 'Others']}
  ] ,
  Note:
$'This note text
can span many lines
and
this \r\n is not escape'
 }, 
 123
]";

            var parser = new JP(new JL(new StringSource(src)));

            parser.Parse();

            Assert.IsInstanceOf(typeof(JSONDataArray), parser.ResultContext.ResultObject);
            var arr = (JSONDataArray)parser.ResultContext.ResultObject;

            Assert.AreEqual(2, arr.Count);
            Assert.AreEqual(123, arr[1]);

            var obj = (JSONDataMap)arr[0];

            Assert.AreEqual(7, obj.Count);
            Assert.AreEqual("Oleg", obj["FirstName"]);
            Assert.AreEqual("Ogurtsov", obj["LastName"]);
            Assert.AreEqual("V.", obj["Middle Name"]);
            Assert.AreEqual("Shamanov", obj["Crazy\nName"]);

            var lucky = obj["LuckyNumbers"] as JSONDataArray;

            Assert.IsNotNull(lucky);
            Assert.AreEqual(6, lucky.Count);
            Assert.AreEqual(4, lucky[0]);
            Assert.AreEqual(9, lucky[5]);

            var history = obj["History"] as JSONDataArray;

            Assert.IsNotNull(history);
            Assert.AreEqual(2, history.Count);

            var ww2 = history[1] as JSONDataMap;

            Assert.IsNotNull(ww2);
            Assert.AreEqual(3, ww2.Count);

            var who = ww2["Who"] as JSONDataArray;

            Assert.IsNotNull(who);
            Assert.AreEqual(6, who.Count);
            Assert.AreEqual("USA", who[2]);
        }
Esempio n. 28
0
        public void RootLiteral_NegativeDouble()
        {
            var src = @"-12.7";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.AreEqual(-12.7, parser.ResultContext.ResultObject);
        }
Esempio n. 29
0
        public void RootLiteral_PositiveHexInt()
        {
            var src = @"+0xf";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.AreEqual(15, parser.ResultContext.ResultObject);
        }
Esempio n. 30
0
        public void RootLiteral_ScientificDouble()
        {
            var src = @"12e2";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.AreEqual(12e2d, parser.ResultContext.ResultObject);
        }
Esempio n. 31
0
        public void RootLiteral_String()
        {
            var src = @"'abc'";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.AreEqual("abc", parser.ResultContext.ResultObject);
        }
Esempio n. 32
0
        public void RootLiteral_True()
        {
            var src = @"true";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.AreEqual(true, parser.ResultContext.ResultObject);
        }
Esempio n. 33
0
        public void RootComplexObject()
        {
            var src =
            @"
             {FirstName: ""Oleg"",  //comments dont hurt
              'LastName': ""Ogurtsov"",
              ""Middle Name"": 'V.',
              ""Crazy\nName"": 'Shamanov',
              LuckyNumbers: [4,5,6,7,8,9],
              /* comments
              do not break stuff */
              |* in this JSON superset *|
              History:
              [
            #HOT_TOPIC
            {Date: '05/14/1905', What: 'Tsushima'},
            #MODERN_TOPIC
            {Date: '09/01/1939', What: 'WW2 Started', Who: ['Germany','USSR', 'USA', 'Japan', 'Italy', 'Others']}
              ] ,
              Note:
            $'This note text
            can span many lines
            and
            this \r\n is not escape'
             }
            ";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
              var obj = (JSONDataMap)parser.ResultContext.ResultObject;

              Assert.AreEqual(7, obj.Count);
              Assert.AreEqual("Oleg", obj["FirstName"]);
              Assert.AreEqual("Ogurtsov", obj["LastName"]);
              Assert.AreEqual("V.", obj["Middle Name"]);
              Assert.AreEqual("Shamanov", obj["Crazy\nName"]);

              var lucky = obj["LuckyNumbers"] as JSONDataArray;
              Assert.IsNotNull(lucky);
              Assert.AreEqual(6, lucky.Count);
              Assert.AreEqual(4, lucky[0]);
              Assert.AreEqual(9, lucky[5]);

              var history = obj["History"] as JSONDataArray;
              Assert.IsNotNull(history);
              Assert.AreEqual(2, history.Count);

              var ww2 = history[1] as JSONDataMap;
              Assert.IsNotNull(ww2);
              Assert.AreEqual(3, ww2.Count);

              var who = ww2["Who"] as JSONDataArray;
              Assert.IsNotNull(who);
              Assert.AreEqual(6, who.Count);
              Assert.AreEqual("USA", who[2]);
        }
Esempio n. 34
0
        public void RootEmptyArray()
        {
            var src = @"[]";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.IsInstanceOf(typeof(JSONDataArray), parser.ResultContext.ResultObject);
              var arr = (JSONDataArray)parser.ResultContext.ResultObject;

              Assert.AreEqual(0, arr.Count);
        }
Esempio n. 35
0
        public void RootObjectWithArray()
        {
            var src = @"{age: 12, numbers: [4,5,6,7,8,9], name: ""Vasya""}";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
              var obj = (JSONDataMap)parser.ResultContext.ResultObject;

              Assert.AreEqual(3, obj.Count);
              Assert.AreEqual(12, obj["age"]);
              Assert.AreEqual("Vasya", obj["name"]);
              Assert.AreEqual(6, ((JSONDataArray)obj["numbers"]).Count);
              Assert.AreEqual(7, ((JSONDataArray)obj["numbers"])[3]);
        }
Esempio n. 36
0
        public void RootObject()
        {
            var src = @"{a: 1, b: true, c: null}";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
              var obj = (JSONDataMap)parser.ResultContext.ResultObject;

              Assert.AreEqual(3, obj.Count);
              Assert.AreEqual(1, obj["a"]);
              Assert.AreEqual(true, obj["b"]);
              Assert.AreEqual(null, obj["c"]);
        }
Esempio n. 37
0
        public void ParseError8()
        {
            var src = @"{ a: 120, b: 140, a: 12}";

              var parser = new JP(  new JL( new StringSource(src) ), throwErrors: true  );

              parser.Parse();
        }
Esempio n. 38
0
        public void RootObjectWithSubObjects()
        {
            var src = @"{age: 120, numbers: {positive: true, bad: 12.7}, name: ""Vasya""}";

              var parser = new JP(  new JL( new StringSource(src) )  );

              parser.Parse();

              Assert.IsInstanceOf(typeof(JSONDataMap), parser.ResultContext.ResultObject);
              var obj = (JSONDataMap)parser.ResultContext.ResultObject;

              Assert.AreEqual(3, obj.Count);
              Assert.AreEqual(120, obj["age"]);
              Assert.AreEqual("Vasya", obj["name"]);
              Assert.AreEqual(true, ((JSONDataMap)obj["numbers"])["positive"]);
              Assert.AreEqual(12.7, ((JSONDataMap)obj["numbers"])["bad"]);
        }