Exemplo n.º 1
1
        public void ParseMultipartWithSuccess()
        {
            var reader = new JSonReader(true);

            var data1 = reader.Read("[1][2]");

            Assert.IsNotNull(data1);
            Assert.AreEqual(1, (long)((object[])data1)[0]);

            var data2 = reader.Read();
            Assert.IsNotNull(data2);
            Assert.AreEqual(2, (long)((object[])data2)[0]);
        }
Exemplo n.º 2
0
 public void ParseWrongNumberOfMainElements()
 {
     try
     {
         var reader = new JSonReader("  [ ], [], { }  ");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(0, ex.Line);
         Assert.AreEqual(5, ex.Offset);
         throw;
     }
 }
Exemplo n.º 3
0
        public void ReadWithoutSourceSetWithException()
        {
            var reader = new JSonReader();

            reader.Read();
        }
Exemplo n.º 4
0
        public void ParseSimpleData1()
        {
            var reader = new JSonReader("  { \"A\":1, \"B\": 2   , \"c\": 12.1 } ");
            var result = reader.Read();

            AssertExt.IsInstanceOf<IDictionary>(result, "Item should be a dictionary");
        }
Exemplo n.º 5
0
 public void ParseEmptyObjectWithComma()
 {
     try
     {
         var reader = new JSonReader("\n{,} ");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(1, ex.Line);
         Assert.AreEqual(1, ex.Offset);
         throw;
     }
 }
Exemplo n.º 6
0
        public void ParseValidUnicodeCharacterInString()
        {
            var reader = new JSonReader("  \"\\u0020\"");
            var result = reader.Read();

            AssertExt.IsInstanceOf<string>(result, "Item should be string");
            Assert.AreEqual(" ", result, "Single space was provided as input!");
        }
Exemplo n.º 7
0
        public void ParseArray()
        {
            var reader = new JSonReader(" [ \"a\", \"b\", \"c\" ]");
            var result = reader.Read();

            AssertExt.IsInstanceOf<Array>(result, "Item should be an array");
            Assert.AreEqual(3, ((Array) result).Length, "Invalid number of items");
            Assert.AreEqual("a", ((object[]) result)[0], "Invalid first element");
        }
Exemplo n.º 8
0
        public void ParseKeyword()
        {
            var reader = new JSonReader("  null  ");
            var result = reader.Read();

            AssertExt.IsInstanceOf<DBNull>(result, "Item should be null");
        }
Exemplo n.º 9
0
        public void ParseNumber()
        {
            var reader = new JSonReader("  10.1e-2  ");
            var result = reader.Read();

            AssertExt.IsInstanceOf<double>(result, "Item should be a number");
            Assert.AreEqual(result, 10.1e-2);
        }
Exemplo n.º 10
0
        public void ParseArrayOfBytes()
        {
            var reader = new JSonReader("[1, 2, 3, 4, 5, 6, 255, 0]");
            var result = reader.Read();
            Assert.IsNotNull(result);
            AssertExt.IsInstanceOf<Array>(result, "Result should be an Array");

            object[] array = (object[]) result;
            Assert.AreEqual((long) 1, array[0], "First element should be equal to 1");

            // try the same with JSonObject:
            var oResult = reader.ReadAsJSonObject("[1, 2, 3, 4, 5, 6, 255, 0]");
            Assert.IsNotNull(oResult);
            Assert.AreEqual(1, oResult[0].Int64Value, "First element should be equal to 1");
        }
Exemplo n.º 11
0
        public void ParseArrayOfUInt64()
        {
            var reader = new JSonReader("[0, 0, 1, 2, 3, 18446744073709551615]");
            var result = reader.Read();
            Assert.IsNotNull(result);
            AssertExt.IsInstanceOf<Array>(result, "Result should be an Array");

            object[] array = (object[]) result;
            Assert.AreEqual((object) ulong.MaxValue, array[5], "First element should be equal to ulong.MaxValue");

            // try the same with JSonObject:
            var oResult = reader.ReadAsJSonObject("[0, 0, 1, 2, 3, 18446744073709551615]");
            Assert.IsNotNull(oResult);
            Assert.AreEqual((ulong) ulong.MaxValue, oResult[5].UInt64Value, "First element should be equal to ulong.MaxValue");
        }
Exemplo n.º 12
0
 public void ParseTopLevelElementsWithoutComma()
 {
     try
     {
         var reader = new JSonReader("  [ ]\r\n [] { }  ");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(1, ex.Line);
         Assert.AreEqual(1, ex.Offset);
         throw;
     }
 }
Exemplo n.º 13
0
 public void ParseArrayWithoutCommaNextItemOnLineStart()
 {
     try
     {
         var reader = new JSonReader(" [ \"a\"\r\n\r\n\"b\"]");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(2, ex.Line);
         Assert.AreEqual(0, ex.Offset);
         throw;
     }
 }
Exemplo n.º 14
0
 public void ParseArrayWithoutComma()
 {
     try
     {
         var reader = new JSonReader(" [ \"a\",\r\n\r\n \"b\"\r\n \t   \"c\" ]");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(3, ex.Line);
         Assert.AreEqual(5, ex.Offset);
         throw;
     }
 }
Exemplo n.º 15
0
 public void ParseInvalidUnicodeCharacters()
 {
     try
     {
         var reader = new JSonReader("\"test-\\u12\\u123\"");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(0, ex.Line);
         Assert.AreEqual(6, ex.Offset);
         throw;
     }
 }
Exemplo n.º 16
0
        public void ParseNumberInt64()
        {
            var reader = new JSonReader("  " + Int64.MaxValue + "  ");
            var result = reader.Read();

            AssertExt.IsInstanceOf<Int64>(result, "Item should be a number");
            Assert.AreEqual(Int64.MaxValue, result);
        }
Exemplo n.º 17
0
        public void ParseSeveralUnicodeCharacters()
        {
            var reader = new JSonReader("\"\\u308f\\u3084\\u307e\\u3061\\u306a\\u306a\"");
            var result = reader.Read();

            Assert.IsNotNull(result, "Value should be some string");
            AssertExt.IsInstanceOf<string>(result, "Value shoule be string class");
            Assert.AreEqual("\u308f\u3084\u307e\u3061\u306a\u306a", result);
        }
Exemplo n.º 18
0
        public void ParseNumberTicks()
        {
            DateTime now = DateTime.Now;
            var reader = new JSonReader("  " + now.Ticks + "  ");
            var result = reader.Read();

            AssertExt.IsInstanceOf<Int64>(result, "Item should be a number");
            Assert.AreEqual(now.Ticks, result);
        }
Exemplo n.º 19
0
        public void ParseStringSpecialCharacter()
        {
            var reader = new JSonReader("  \"\\\"\"");
            var result = reader.Read();

            AssertExt.IsInstanceOf<string>(result, "Item should be string");
            Assert.AreEqual("\"", result, "Expected special character!");
        }
Exemplo n.º 20
0
 public void ParseInvalidNumber()
 {
     try
     {
         var reader = new JSonReader("  10,1e-2  ");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(0, ex.Line);
         Assert.AreEqual(4, ex.Offset);
         throw;
     }
 }
Exemplo n.º 21
0
 public void ParseEmptyArrayWithComma()
 {
     try
     {
         var reader = new JSonReader(" [,] ");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(0, ex.Line);
         Assert.AreEqual(2, ex.Offset);
         throw;
     }
 }
Exemplo n.º 22
0
        public void ParseString()
        {
            var reader = new JSonReader("  \"Paweł\\r\\nJSON\\r\\nText\ttab\tspaced.\"  ");
            var result = reader.Read();

            AssertExt.IsInstanceOf<string>(result, "Item should be a string");
        }
Exemplo n.º 23
0
        public void ParseEmptyObject()
        {
            var reader = new JSonReader("  { } ");
            var result = reader.Read();

            AssertExt.IsInstanceOf<IDictionary>(result, "Item should be a dictionary");
        }
Exemplo n.º 24
0
 public void ParseInvalidNotFinishedString()
 {
     try
     {
         var reader = new JSonReader("\n\"Not finished text  ");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(1, ex.Line);
         Assert.AreEqual(0, ex.Offset);
         throw;
     }
 }
Exemplo n.º 25
0
 public void ParseArrayWithUnknownKeyword()
 {
     try
     {
         var reader = new JSonReader("\n \t[nulll]");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(1, ex.Line);
         Assert.AreEqual(3, ex.Offset);
         throw;
     }
 }
Exemplo n.º 26
0
 public void ParseInvalidStringWithNewLine()
 {
     try
     {
         var reader = new JSonReader("  \"Test string with new line\r\n\"");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(0, ex.Line);
         Assert.AreEqual(3, ex.Offset);
         throw;
     }
 }
Exemplo n.º 27
0
        public void ParseForbiddenMultipartWithException()
        {
            var reader = new JSonReader();

            reader.Read("[0][1]");
        }
Exemplo n.º 28
0
        public void ParseCorrectlyTooLongUnicodeCharacterDefinitionInString()
        {
            var reader = new JSonReader("  \"Text-\\u12345\"");
            var result = reader.Read();

            Assert.IsNotNull(result, "Result can't be null");
            Assert.AreEqual("Text-\u12345", result, "Invalid text read");
        }
Exemplo n.º 29
0
        public void ParseNumberWithForcedFormat()
        {
            var reader = new JSonReader();
            
            var result1 = reader.ReadAsJSonObject("[12, 13, 14]", JSonReaderNumberFormat.AsInt32);
            var result2 = reader.ReadAsJSonObject("[" + (uint.MaxValue + 1ul) + ", " + (uint.MaxValue + 2ul) + ", " + (uint.MaxValue + 3ul) + "]", JSonReaderNumberFormat.AsInt64);
            var result3 = reader.ReadAsJSonObject("[12.12, 13.13, 14.14]", JSonReaderNumberFormat.AsDouble);
            var result4 = reader.ReadAsJSonObject("[12.12, 13.13, 14.14]", JSonReaderNumberFormat.AsDecimal);
            var result5 = reader.Read("[12, 13, 14]", JSonReaderNumberFormat.AsInt32);
            var result6 = reader.Read("[" + (uint.MaxValue + 1ul) + ", " + (uint.MaxValue + 2ul) + ", " + (uint.MaxValue + 3ul) + "]", JSonReaderNumberFormat.AsInt64);
            var result7 = reader.Read("[12.12, 13.13, 14.14]", JSonReaderNumberFormat.AsDouble);
            var result8 = reader.Read("[12.12, 13.13, 14.14]", JSonReaderNumberFormat.AsDecimal);
            var result9 = reader.ReadAsJSonMutableObject("[12, 13, 14]", JSonReaderNumberFormat.AsInt32);
            var result10 = reader.ReadAsJSonMutableObject("[" + (uint.MaxValue + 1ul) + ", " + (uint.MaxValue + 2ul) + ", " + (uint.MaxValue + 3ul) + "]", JSonReaderNumberFormat.AsInt64);
            var result11 = reader.ReadAsJSonMutableObject("[12.12, 13.13, 14.14]", JSonReaderNumberFormat.AsDouble);
            var result12 = reader.ReadAsJSonMutableObject("[12.12, 13.13, 14.14]", JSonReaderNumberFormat.AsDecimal);

            Assert.IsNotNull(result1);
            Assert.IsNotNull(result2);
            Assert.IsNotNull(result3);
            Assert.IsNotNull(result4);
            Assert.IsNotNull(result5);
            Assert.IsNotNull(result6);
            Assert.IsNotNull(result7);
            Assert.IsNotNull(result8);
            Assert.IsNotNull(result9);
            Assert.IsNotNull(result10);
            Assert.IsNotNull(result11);
            Assert.IsNotNull(result12);
        }
Exemplo n.º 30
0
 public void ParseUnfinishedString()
 {
     try
     {
         var reader = new JSonReader("   \"start");
         reader.Read();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(0, ex.Line);
         Assert.AreEqual(3, ex.Offset);
         throw;
     }
 }