Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public void ParseError7()
        {
            var src = @"{ true: 120}";

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

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

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

            parser.Parse();
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void RootLiteral_Double()
        {
            var src = @"12.7";

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

            parser.Parse();

            Aver.AreObjectsEqual(12.7, parser.ResultContext.ResultObject);
        }
Exemplo n.º 6
0
        public void RootLiteral_PositiveHexInt()
        {
            var src = @"+0xf";

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

            parser.Parse();

            Aver.AreObjectsEqual(15, parser.ResultContext.ResultObject);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void RootLiteral_String()
        {
            var src = @"'abc'";

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

            parser.Parse();

            Aver.AreObjectsEqual("abc", parser.ResultContext.ResultObject);
        }
Exemplo n.º 9
0
        public void RootLiteral_Null()
        {
            var src = @"null";

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

            parser.Parse();

            Aver.IsNull(parser.ResultContext.ResultObject);
        }
Exemplo n.º 10
0
        public void RootLiteral_PositiveScientificDouble()
        {
            var src = @"+12e2";

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

            parser.Parse();

            Aver.AreObjectsEqual(12e2d, parser.ResultContext.ResultObject);
        }
Exemplo n.º 11
0
        public void ParseError1()
        {
            var src = @"{age 120}";

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

            parser.Parse();

            Aver.AreEqual(1, parser.Messages.Count);
            Aver.AreEqual((int)JsonMsgCode.eColonOperatorExpected, parser.Messages[0].Code);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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]);
        }
Exemplo n.º 15
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"]);
        }
Exemplo n.º 16
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();

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

            Aver.AreEqual(3, obj.Count);
            Aver.AreObjectsEqual(12, obj["age"]);
            Aver.AreObjectsEqual("Vasya", obj["name"]);
            Aver.AreObjectsEqual(6, ((JsonDataArray)obj["numbers"]).Count);
            Aver.AreObjectsEqual(7, ((JsonDataArray)obj["numbers"])[3]);
        }
Exemplo n.º 17
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();

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

            Aver.AreEqual(3, obj.Count);
            Aver.AreObjectsEqual(120, obj["age"]);
            Aver.AreObjectsEqual("Vasya", obj["name"]);
            Aver.AreObjectsEqual(true, ((JsonDataMap)obj["numbers"])["positive"]);
            Aver.AreObjectsEqual(12.7, ((JsonDataMap)obj["numbers"])["bad"]);
        }
Exemplo n.º 18
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();

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

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

            var obj = (JsonDataMap)arr[0];

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

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

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

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

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

            var ww2 = history[1] as JsonDataMap;

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

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

            Aver.IsNotNull(who);
            Aver.AreEqual(6, who.Count);
            Aver.AreObjectsEqual("USA", who[2]);
        }