Ejemplo n.º 1
0
        public void Object_2()
        {
            var json = @"{ /*
      ""a"": 1, 'b': true, ""c"": null, d: false, e: {}, |* some comment *| f: [],
       g: 'string',

    this
    is
    all
    comment

       h: ""string2""
 //this is a complex
 //multiline

  ,
    list: [
        +11,-12,





        -345e3, null ,
      ], //notice trailing comma
    */
     a: 123, }";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);
            Aver.AreEqual(1, got.Count);
            Aver.AreObjectsEqual(123, got["a"]);
        }
Ejemplo n.º 2
0
        public void ParserTest()
        {
            var json = @"{ a:       1, b: ""something"", c: null, d: {}, e: 23.7}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true);

            got.See();
        }
Ejemplo n.º 3
0
        public void ULongMax()
        {
            var json = @"{ v: 18446744073709551615}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);
            Aver.AreObjectsEqual(ulong.MaxValue, got["v"]);
        }
Ejemplo n.º 4
0
        public void Int_3()
        {
            var json = @"{ v: +2147483647}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);
            Aver.AreObjectsEqual(int.MaxValue, got["v"]);
        }
Ejemplo n.º 5
0
        public void Int_1()
        {
            var json = @"{ v: -2147483647}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);
            Aver.AreObjectsEqual(int.MinValue + 1, got["v"]);//+1 because lexer treats int as [-2147483647, +2147483647] whereas int min is -214748364[8]
        }
Ejemplo n.º 6
0
        public void Dbl_5()
        {
            var json = @"{ v: -2.2e3}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);
            Aver.AreObjectsEqual(-2.2e3, got["v"]);
        }
Ejemplo n.º 7
0
        public void Long_3()
        {
            var json = @"{ v: +9223372036854775807}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);
            Aver.AreObjectsEqual(long.MaxValue, got["v"]);
        }
Ejemplo n.º 8
0
        public void Depth_6()
        {
            var json = @"123";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true, 0);//only allow root values, not objects or arrays

            Aver.IsNotNull(got);
            Aver.AreObjectsEqual(123, got);
        }
Ejemplo n.º 9
0
        public void Depth_2()
        {
            var json = @"{ v: 'abc'}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true, 1) as JsonDataMap;

            Aver.IsNotNull(got);
            Aver.AreObjectsEqual("abc", got["v"]);
        }
Ejemplo n.º 10
0
        public void Depth_4()
        {
            var json = @"{ v: {v2: 'abc'}}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true, 2) as JsonDataMap;

            var v = got["v"] as JsonDataMap;

            Aver.IsNotNull(v);
            Aver.AreObjectsEqual("abc", v["v2"]);
        }
Ejemplo n.º 11
0
        public void Object_1()
        {
            var json = @"{ 
      ""a"": 1, 'b': true, ""c"": null, d: false, e: {}, /* some comment */ f: [],
       g: 'string',
  /*
    this
    is
    all
    comment
    */
       h: ""string2""
 //this is a complex
 //multiline

  ,
    list: [
        +11,-12,





        -345e3, null ,
      ], //notice trailing comma

}";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);
            Aver.AreObjectsEqual(1, got["a"]);
            Aver.AreObjectsEqual(true, got["b"]);
            Aver.AreObjectsEqual(null, got["c"]);
            Aver.AreObjectsEqual(false, got["d"]);

            Aver.IsTrue(got["e"] is JsonDataMap);
            Aver.IsTrue(got["f"] is JsonDataArray);

            Aver.AreObjectsEqual("string", got["g"]);
            Aver.AreObjectsEqual("string2", got["h"]);

            Aver.IsTrue(got["list"] is JsonDataArray);
            Aver.AreEqual(4, (got["list"] as JsonDataArray).Count);

            Aver.AreObjectsEqual(11, (got["list"] as JsonDataArray)[0]);
            Aver.AreObjectsEqual(-12, (got["list"] as JsonDataArray)[1]);
            Aver.AreObjectsEqual(-345e3d, (got["list"] as JsonDataArray)[2]);
            Aver.AreObjectsEqual(null, (got["list"] as JsonDataArray)[3]);
        }
Ejemplo n.º 12
0
        public void TrailingComma_Object_2()
        {
            var json = @"{ a: [1,-2,], b: [{f: true},{f: false},{f: null},]    , /* comment: comment */  }";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);
            var a = got["a"] as JsonDataArray;

            Aver.IsNotNull(a);
            Aver.AreEqual(2, a.Count);
            Aver.AreObjectsEqual(1, a[0]);
            Aver.AreObjectsEqual(-2, a[1]);

            var b = got["b"] as JsonDataArray;

            Aver.IsNotNull(b);
            Aver.AreEqual(3, b.Count);
            Aver.AreObjectsEqual(true, (b[0] as JsonDataMap)["f"]);
            Aver.AreObjectsEqual(false, (b[1] as JsonDataMap)["f"]);
            Aver.AreObjectsEqual(null, (b[2] as JsonDataMap)["f"]);
        }
Ejemplo n.º 13
0
        public void Object_3()
        {
            var json = @"{ s: $'/*
      ""a"": 1, ''b'': true, ""c"": null, d: false, e: {}, |* some comment *| f: [],
       g: ''string'',

    this
    is
    all
    comment

       h: ""string2""
 //this is a complex
 //multiline

  ,
    list: [
        +11,   -12,





        -345e3, null ,
      ], //notice trailing comma
    */',
     a: -123, }";
            var src  = new StringSource(json);
            var got  = JazonParser.Parse(src, true) as JsonDataMap;

            Aver.IsNotNull(got);

            got["s"].See();

            Aver.AreEqual(2, got.Count);
            Aver.IsTrue(got["s"].ToString().MatchPattern("/* 'b': true*g: 'string',*+11,   -12*trailing comma*/"));
            Aver.AreObjectsEqual(-123, got["a"]);
        }
Ejemplo n.º 14
0
 public void Int_5()
 {
     var json = @"{ v: --1}";
     var src  = new StringSource(json);
     var got  = JazonParser.Parse(src, true) as JsonDataMap;
 }
Ejemplo n.º 15
0
 public void Dbl_7()
 {
     var json = @"{ v: ++2.2e3}";
     var src  = new StringSource(json);
     var got  = JazonParser.Parse(src, true) as JsonDataMap;
 }
Ejemplo n.º 16
0
 public void TrailingComma_Object_4()
 {
     var json = @"{ a: [1,-2,], b: [{f: true},{f: false},{f: null},]    , /* comment: comment */  , }";
     var src  = new StringSource(json);
     var got  = JazonParser.Parse(src, true) as JsonDataMap;
 }
Ejemplo n.º 17
0
 public void TrailingComma_Array_4()
 {
     var json = @"{ a: [1,-2,], b: [{f: true},{f: false},{f: null}, ,]}";
     var src  = new StringSource(json);
     var got  = JazonParser.Parse(src, true) as JsonDataMap;
 }
Ejemplo n.º 18
0
 public void Depth_5()
 {
     var json = @"{ v: {v2: 'abc'}}";
     var src  = new StringSource(json);
     var got  = JazonParser.Parse(src, true, 1) as JsonDataMap;
 }
Ejemplo n.º 19
0
 public void Dbl_8()
 {
     var json = @"{ v: 6873468576328476598723647856234805803928059823123489273184972937498263462137864823.76}";
     var src  = new StringSource(json);
     var got  = JazonParser.Parse(src, true) as JsonDataMap;
 }