Exemplo n.º 1
0
    public void EmbeddedComment() {
      JSONReader reader= new JSONReader();
      IValue root = reader.JsonToValue("/* comment */null", false, false);
      Assert.True(root.IsType(ValueType.NullValue));

      root = reader.JsonToValue("40 /* comment */", false, false);
      Assert.True(root.IsType(ValueType.Integer));

      root = reader.JsonToValue("true // comment", false, false);
      Assert.True(root.IsType(ValueType.Boolean));

      root = reader.JsonToValue("/* comment */\"sample string\"", false, false);
      Assert.True(root.IsType(ValueType.String));
      Assert.AreEqual("sample string", root.GetAsString());
    }
Exemplo n.º 2
0
        public void SimpleBool()
        {
            JSONReader reader = new JSONReader();
            IValue     root   = reader.JsonToValue("true   ", false, false);

            Assert.True(root.IsType(ValueType.Boolean));
        }
Exemplo n.º 3
0
 public void Reading() {
   // some whitespace checking.
   IValue root;
   JSONReader reader = new JSONReader();
   root = reader.JsonToValue("   null   ", false, false);
   Assert.True(root.IsType(ValueType.NullValue));
 }
Exemplo n.º 4
0
        public void NumberFormat()
        {
            JSONReader reader = new JSONReader();
            IValue     root   = reader.JsonToValue("43", false, false);

            Assert.True(root.IsType(ValueType.Integer));
            Assert.AreEqual(43, root.GetAsInteger());
        }
Exemplo n.º 5
0
        public void EmbeddedComment()
        {
            JSONReader reader = new JSONReader();
            IValue     root   = reader.JsonToValue("/* comment */null", false, false);

            Assert.True(root.IsType(ValueType.NullValue));

            root = reader.JsonToValue("40 /* comment */", false, false);
            Assert.True(root.IsType(ValueType.Integer));

            root = reader.JsonToValue("true // comment", false, false);
            Assert.True(root.IsType(ValueType.Boolean));

            root = reader.JsonToValue("/* comment */\"sample string\"", false, false);
            Assert.True(root.IsType(ValueType.String));
            Assert.AreEqual("sample string", root.GetAsString());
        }
Exemplo n.º 6
0
        public void Reading()
        {
            // some whitespace checking.
            IValue     root;
            JSONReader reader = new JSONReader();

            root = reader.JsonToValue("   null   ", false, false);
            Assert.True(root.IsType(ValueType.NullValue));
        }
Exemplo n.º 7
0
        public void ParseInt()
        {
            JSONReader reader = new JSONReader();
            Value value = reader.JsonToValue("{ \"number\":10, \"numbere\":10e5, \"real\":10.01, \"frac\":-10.00E-5, \"string\":\"5478\n965\", /* string value with comment */\"string_comment\":\"teste50125\" }", true, true);

            Assert.IsInstanceOf<DictionaryValue>(value);
            DictionaryValue dict = value as DictionaryValue;

            // int parse
            int i;
            Assert.AreEqual(true, dict.GetInteger("number", out i));
            Assert.AreEqual(i, 10);

            // exponential int
            Assert.AreEqual(true, dict.GetInteger("numbere", out i));
            Assert.AreEqual(i, 10e5);

            // real number
            double d;
            Assert.AreEqual(true, dict.GetReal("real", out d));
            Assert.AreEqual(d, 10.01);

            // fractional
            Assert.AreEqual(true, dict.GetReal("frac", out d));
            Assert.AreEqual(d, -10.00e-5);

            // string parse
            string s;
            Assert.AreEqual(true, dict.GetString("string", out s));
            Assert.AreEqual(s, "5478\n965");

            // comment
            Assert.AreEqual(true, dict.GetString("string_comment", out s));
            Assert.AreEqual(s, "teste50125");

            // invalid numbers
            // valid number is: [minus] int [frac] [exp]
            Assert.Throws<ArgumentException>( delegate() {
                reader.JsonToValue("{ \"number\":10e }", true, true);
            });

            Assert.Throws<ArgumentException>(delegate() {
                reader.JsonToValue("{ \"number\":+10 }", true, true);
            });

            // unquoted strings
            Assert.Throws<ArgumentException>(delegate() {
                reader.JsonToValue("{ \"string\":string }", true, true);
            });

            Assert.Throws<ArgumentException>(delegate() {
                reader.JsonToValue("{ string:string }", true, true);
            });

            // trailing comma
            Assert.Throws<ArgumentException>(delegate() {
                reader.JsonToValue("{ \"string\":\"string\", }", true, false);
            });
        }
Exemplo n.º 8
0
 public void InvalidJSONString()
 {
     JSONReader reader = new JSONReader();
     IValue     root   = reader.JsonToValue("nu", false, false);
 }
Exemplo n.º 9
0
 public void NumberFormat() {
   JSONReader reader = new JSONReader();
   IValue root = reader.JsonToValue("43", false, false);
   Assert.True(root.IsType(ValueType.Integer));
   Assert.AreEqual(43, root.GetAsInteger());
 }
Exemplo n.º 10
0
 public void SimpleBool() {
   JSONReader reader = new JSONReader();
   IValue root = reader.JsonToValue("true   ", false, false);
   Assert.True(root.IsType(ValueType.Boolean));
 }
Exemplo n.º 11
0
 public void InvalidJSONString() {
   JSONReader reader = new JSONReader();
   IValue root = reader.JsonToValue("nu", false, false);
 }