Esempio n. 1
0
        public void 文字列の後ろにその他の値がある場合は例外2()
        {
            var target  = @"'abcde'abde";
            var expects = new ReaderExpect[] { };

            ReaderUtil.Check(target, expects);
        }
Esempio n. 2
0
 public void 文字列以外のプロパティ名は駄目() {
     var target = "{12345:'HOGE'}";
     var expects = new ReaderExpect[] {
         new ReaderExpect(){Token = JsonToken.StartObject, IsStrict = true},
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowNonStringKeyName);
 }
Esempio n. 3
0
        public void 文字列中に改行がある場合は例外3()
        {
            var target  = "\"abc\r\nabc\"";
            var expects = new ReaderExpect[] { };

            ReaderUtil.Check(target, expects);
        }
Esempio n. 4
0
 public void 数値の8進数は駄目2() {
     var target = "{013:'HOGE'}";
     var expects = new ReaderExpect[] {
         new ReaderExpect(){Token = JsonToken.StartObject, IsStrict = true},
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowOctalNumber);
 }
Esempio n. 5
0
        public void 数値の0左埋めは駄目1_1()
        {
            var target  = "0000";
            var expects = new ReaderExpect[] {
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowLeftZeroPaddingNumber);
        }
Esempio n. 6
0
        public void 単一引用符の文字列はだめ()
        {
            var target  = "'abcde'";
            var expects = new ReaderExpect[] {
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowSingleQuoteString);
        }
Esempio n. 7
0
        public void undefinedは駄目()
        {
            var target  = "undefined";
            var expects = new ReaderExpect[] {
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowUndefined);
        }
Esempio n. 8
0
        public void Infinityは駄目2()
        {
            var target  = "-Infinity";
            var expects = new ReaderExpect[] {
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowInfinity);
        }
Esempio n. 9
0
        public void NaNは駄目()
        {
            var target  = "NaN";
            var expects = new ReaderExpect[] {
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowNaN);
        }
Esempio n. 10
0
        public void 数値の16進数は駄目1()
        {
            var target  = "0xFF";
            var expects = new ReaderExpect[] {
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowHexNumber);
        }
Esempio n. 11
0
        public void  明な型の値は駄目()
        {
            var target  = "+0iajoljc";
            var expects = new ReaderExpect[] {
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowUnknownType);
        }
Esempio n. 12
0
 public void 数値の8進数は駄目3() {
     var target = "{Foo:016}";
     var expects = new ReaderExpect[] {
         new ReaderExpect(){Token = JsonToken.StartObject, IsStrict = true},
         new ReaderExpect(){Token = JsonToken.Key,  Type=ValueType.Unknown, Value = "Foo"}
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowOctalNumber);
 }
Esempio n. 13
0
        public void 文字列以外のプロパティ名は駄目()
        {
            var target  = "{12345:'HOGE'}";
            var expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Token = JsonToken.StartObject, IsStrict = true
                },
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowNonStringKeyName);
        }
Esempio n. 14
0
        public void 数値の0左埋めは駄目2()
        {
            var target  = "{009:'HOGE'}";
            var expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Token = JsonToken.StartObject, IsStrict = true
                },
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowLeftZeroPaddingNumber);
        }
Esempio n. 15
0
        public void 数値の8進数は駄目1() {
            var target = "019";
            var expects = new ReaderExpect[] {
                new ReaderExpect(){Token = JsonToken.Value,  Type=ValueType.Number, Value = "019"}
            };
            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowOctalNumber);

            target = "012";
            expects = new ReaderExpect[] {
            };
            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowOctalNumber);
        }
Esempio n. 16
0
        public void 数値の8進数は駄目2()
        {
            var target  = "{013:'HOGE'}";
            var expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Token = JsonToken.StartObject, IsStrict = true
                },
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowOctalNumber);
        }
Esempio n. 17
0
        public void 数値の16進数は駄目3()
        {
            var target  = "{Foo:0x254}";
            var expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Token = JsonToken.StartObject, IsStrict = true
                },
                new ReaderExpect()
                {
                    Token = JsonToken.Key, Type = ValueType.Unknown, Value = "Foo"
                }
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowHexNumber);
        }
Esempio n. 18
0
       public void ポジションとライン() {
           var target = "{    \r\"FOO\": 1234,\"BAR\": [\n        1.0,  'ABCD'\r\n  ]\r\n\r\n}";
           var expects = new ReaderExpect[] { 
               new ReaderExpect(){Token = JsonToken.StartObject, Pos = 0, Line = 1, IsStrict = true},
               new ReaderExpect(){Token = JsonToken.Key,  Type=ValueType.String, Quote=QuoteType.Double, Pos = 6, Line = 2, Value = "FOO" , IsStrict = true},
               new ReaderExpect(){Token = JsonToken.Value, Type = ValueType.Number, Value = "1234", Pos = 13, Line = 2, IsStrict = true},
               new ReaderExpect(){Token = JsonToken.Key,  Type=ValueType.String, Quote=QuoteType.Double, Pos = 18, Line = 2, Value = "BAR", IsStrict = true },
               new ReaderExpect(){Token = JsonToken.StartArray, Pos = 25, Line = 2, IsStrict = true},
               new ReaderExpect(){Token = JsonToken.Value, Type = ValueType.Number, Value = "1.0", Pos = 35, Line = 3, IsStrict = true},
               new ReaderExpect(){Token = JsonToken.Value, Type = ValueType.String, Quote = QuoteType.Single, Value = "ABCD", Pos = 41, Line = 3},
               new ReaderExpect(){Token = JsonToken.EndArray, Pos = 51, Line = 4, IsStrict = true},
               new ReaderExpect(){Token = JsonToken.EndObject, Pos = 56, Line = 6, IsStrict = true},
 
           };
           ReaderUtil.Check(target, expects);
       }
Esempio n. 19
0
        public void 数値の0左埋めは駄目1()
        {
            var target  = "012"; //8進数だからOK
            var expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Token = JsonToken.Value, Type = ValueType.Number, Value = "012", IsOctalNumber = true
                }
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowLeftZeroPaddingNumber);

            target  = "0019";
            expects = new ReaderExpect[] {
            };
            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowLeftZeroPaddingNumber);
        }
Esempio n. 20
0
        public void 数値の8進数は駄目1()
        {
            var target  = "019";
            var expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Token = JsonToken.Value, Type = ValueType.Number, Value = "019"
                }
            };

            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowOctalNumber);

            target  = "012";
            expects = new ReaderExpect[] {
            };
            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowOctalNumber);
        }
Esempio n. 21
0
        public void ポジションとライン()
        {
            var target  = "{    \r\"FOO\": 1234,\"BAR\": [\n        1.0,  'ABCD'\r\n  ]\r\n\r\n}";
            var expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Token = JsonToken.StartObject, Pos = 0, Line = 1, IsStrict = true
                },
                new ReaderExpect()
                {
                    Token = JsonToken.Key, Type = ValueType.String, Quote = QuoteType.Double, Pos = 6, Line = 2, Value = "FOO", IsStrict = true
                },
                new ReaderExpect()
                {
                    Token = JsonToken.Value, Type = ValueType.Number, Value = "1234", Pos = 13, Line = 2, IsStrict = true
                },
                new ReaderExpect()
                {
                    Token = JsonToken.Key, Type = ValueType.String, Quote = QuoteType.Double, Pos = 18, Line = 2, Value = "BAR", IsStrict = true
                },
                new ReaderExpect()
                {
                    Token = JsonToken.StartArray, Pos = 25, Line = 2, IsStrict = true
                },
                new ReaderExpect()
                {
                    Token = JsonToken.Value, Type = ValueType.Number, Value = "1.0", Pos = 35, Line = 3, IsStrict = true
                },
                new ReaderExpect()
                {
                    Token = JsonToken.Value, Type = ValueType.String, Quote = QuoteType.Single, Value = "ABCD", Pos = 41, Line = 3
                },
                new ReaderExpect()
                {
                    Token = JsonToken.EndArray, Pos = 51, Line = 4, IsStrict = true
                },
                new ReaderExpect()
                {
                    Token = JsonToken.EndObject, Pos = 56, Line = 6, IsStrict = true
                },
            };

            ReaderUtil.Check(target, expects);
        }
Esempio n. 22
0
        public void エスケープされている場合はOK()
        {
            var target  = "\"abc\\\rabc\"";
            var expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Quote = QuoteType.Double, Token = JsonToken.Value, Type = ValueType.String, Value = "abc\\\rabc", IsStrict = true
                }
            };

            ReaderUtil.Check(target, expects);

            target  = "\"abc\\\nabc\"";
            expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Quote = QuoteType.Double, Token = JsonToken.Value, Type = ValueType.String, Value = "abc\\\nabc", IsStrict = true
                }
            };
            ReaderUtil.Check(target, expects);

            target  = "\"abc\\\r\\\nabc\"";
            expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Quote = QuoteType.Double, Token = JsonToken.Value, Type = ValueType.String, Value = "abc\\\r\\\nabc", IsStrict = true
                }
            };
            ReaderUtil.Check(target, expects);

            target  = "\"abc\\\"abc\"";
            expects = new ReaderExpect[] {
                new ReaderExpect()
                {
                    Quote = QuoteType.Double, Token = JsonToken.Value, Type = ValueType.String, Value = "abc\\\"abc", IsStrict = true
                }
            };
            ReaderUtil.Check(target, expects);
        }
Esempio n. 23
0
        public static void Check(string json, ReaderExpect[] expects, Relaxations? relax = null) {
            var pos = 0;
            using (var reader = relax.HasValue ? new JsonReader(json, relax.Value) : new JsonReader(json)) {
                while (reader.Read()) {
                    var expect = expects[pos++];
                    Assert.AreEqual(expect.Value, reader.Value, string.Format("{0}-Value:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.Quote, reader.Quote, string.Format("{0}-Quote:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.Type, reader.Type, string.Format("{0}-Type:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.Token, reader.Token, string.Format("{0}-Token:{1}", pos, expect.AssertMessage));

                    Assert.AreEqual(expect.IsStrict, reader.IsStrict, string.Format("{0}-IsStrict:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.IsHexNumber, reader.IsHexNumber, string.Format("{0}-IsHexNumber:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.IsOctalNumber, reader.IsOctalNumber, string.Format("{0}-IsOctalNumber:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.HasLastComma, reader.HasLastComma, string.Format("{0}-HasLastComma:{1}", pos, expect.AssertMessage));

                    if (expect.Pos.HasValue) {
                        Assert.AreEqual(expect.Pos.Value, reader.Position, string.Format("{0}-Pos:{1}", pos, expect.AssertMessage));
                    }
                    if (expect.Line.HasValue) {
                        Assert.AreEqual(expect.Line.Value, reader.Line, string.Format("{0}-Line:{1}", pos, expect.AssertMessage));
                    }
                }
            }
        }
Esempio n. 24
0
 public void 数値の0左埋めは駄目1_1() {
     var target = "0000";
     var expects = new ReaderExpect[] {
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowLeftZeroPaddingNumber);
 }
Esempio n. 25
0
 public void 単一引用符の文字列はだめ() {
     var target = "'abcde'";
     var expects = new ReaderExpect[] { 
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowSingleQuoteString);
 }
Esempio n. 26
0
 public void Infinityは駄目2() {
     var target = "-Infinity";
     var expects = new ReaderExpect[] {
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowInfinity);
 }
Esempio n. 27
0
 public void undefinedは駄目() {
     var target = "undefined";
     var expects = new ReaderExpect[] {
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowUndefined);
 }
Esempio n. 28
0
 public void NaNは駄目() {
     var target = "NaN";
     var expects = new ReaderExpect[] {
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowNaN);
 }
Esempio n. 29
0
 public void 不明な型の値は駄目() {
     var target = "+0iajoljc";
     var expects = new ReaderExpect[] {
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowUnknownType);
 }
Esempio n. 30
0
 public void 数値の16進数は駄目1() {
     var target = "0xFF";
     var expects = new ReaderExpect[] {
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowHexNumber);
 }
Esempio n. 31
0
        public void 数値の0左埋めは駄目1() {
            var target = "012";  //8進数だからOK
            var expects = new ReaderExpect[] {
                new ReaderExpect(){Token = JsonToken.Value,  Type=ValueType.Number, Value = "012", IsOctalNumber = true}
            };
            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowLeftZeroPaddingNumber);

            target = "0019";
            expects = new ReaderExpect[] {
            };
            ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowLeftZeroPaddingNumber);
        }
Esempio n. 32
0
 public void 文字列の後ろにその他の値がある場合は例外2() {
     var target = @"'abcde'abde";
     var expects = new ReaderExpect[] { };
     ReaderUtil.Check(target, expects);
 }
Esempio n. 33
0
 public void 文字列中に改行がある場合は例外3() {
     var target = "\"abc\r\nabc\"";
     var expects = new ReaderExpect[] { };
     ReaderUtil.Check(target, expects);
 }
Esempio n. 34
0
        public void エスケープされている場合はOK() {
            var target = "\"abc\\\rabc\"";
            var expects = new ReaderExpect[] { 
                new ReaderExpect(){Quote = QuoteType.Double, Token = JsonToken.Value, Type = ValueType.String, Value = "abc\\\rabc", IsStrict=true}  
            };
            ReaderUtil.Check(target, expects);

            target = "\"abc\\\nabc\"";
            expects = new ReaderExpect[] { 
                new ReaderExpect(){Quote = QuoteType.Double, Token = JsonToken.Value, Type = ValueType.String, Value = "abc\\\nabc", IsStrict=true}  
            };
            ReaderUtil.Check(target, expects);

            target = "\"abc\\\r\\\nabc\"";
            expects = new ReaderExpect[] { 
                new ReaderExpect(){Quote = QuoteType.Double, Token = JsonToken.Value, Type = ValueType.String, Value = "abc\\\r\\\nabc", IsStrict=true}  
            };
            ReaderUtil.Check(target, expects);

            target = "\"abc\\\"abc\"";
            expects = new ReaderExpect[] { 
                new ReaderExpect(){Quote = QuoteType.Double, Token = JsonToken.Value, Type = ValueType.String, Value = "abc\\\"abc", IsStrict=true}  
            };
            ReaderUtil.Check(target, expects);
        }
Esempio n. 35
0
 public void 数値の0左埋めは駄目2() {
     var target = "{009:'HOGE'}";
     var expects = new ReaderExpect[] {
         new ReaderExpect(){Token = JsonToken.StartObject, IsStrict = true},
     };
     ReaderUtil.Check(target, expects, Relaxations.AllowAll ^ Relaxations.AllowLeftZeroPaddingNumber);
 }