Example #1
0
        public void TestErrors(TestFilePath testFilePath)
        {
            var inputName = testFilePath.FilePath;
            var baseDir   = Path.GetFullPath(Path.Combine(BaseDirectory, RelativeBasePath));

            var inputFile = Path.Combine(baseDir, inputName);
            var inputText = File.ReadAllText(inputFile);

            var expectedOutputFile = Path.ChangeExtension(inputFile, OutputEndFileExtension);

            Assert.True(File.Exists(expectedOutputFile), $"Expecting output result file [{expectedOutputFile}] for input file [{inputName}]");
            var expectedOutputText = File.ReadAllText(expectedOutputFile, Encoding.UTF8);

            var result = string.Empty;

            try
            {
                Json.Validate(inputText);
            }
            catch (JsonException exception)
            {
                result = exception.ToString();
            }

            Console.Write(result);

            TextAssert.AreEqual(expectedOutputText, result);
        }
Example #2
0
        public void TestLarge()
        {
            var rootPath = Path.GetDirectoryName(typeof(TestParser).Assembly.Location);
            var src      = File.ReadAllText(Path.Combine(rootPath, @"..\..\..\Textamina.Jsonite.Benchmarks\test.json"));
            var obj      = Json.Deserialize(src);
            var output1  = Json.Serialize(obj);
            var obj1     = Json.Deserialize(output1);
            var output2  = Json.Serialize(obj1);

            TextAssert.AreEqual(output1, output2);
        }
Example #3
0
        public void TestObject()
        {
            // See TestErrors files for other cases
            var src = "{\"member\":15,\"member2\":null,\"toto\":[1,2,3,4]}";
            var obj = Json.Deserialize(src);

            Assert.NotNull(obj);
            Assert.AreEqual(typeof(JsonObject), obj.GetType());
            var output = Json.Serialize(obj);

            TextAssert.AreEqual(src, output);
        }
Example #4
0
        public void TestArray()
        {
            // See TestErrors files for other cases
            var src = "[1,2,null,true,false,\"YES\"]";
            var obj = Json.Deserialize(src);

            Assert.NotNull(obj);
            Assert.AreEqual(typeof(JsonArray), obj.GetType());
            Assert.AreEqual(new JsonArray()
            {
                1, 2, null, true, false, "YES"
            }, obj);
            var output = Json.Serialize(obj);

            TextAssert.AreEqual(src, output);
        }
Example #5
0
 public void ParseString()
 {
     // See TestErrors files for other cases
     Assert.AreEqual("test", Json.Deserialize(@"""test"""));
     TextAssert.AreEqual("\"\\\b\f\r\n\t ", Json.Deserialize(@"""\""\\\b\f\r\n\t\u0020""") as string);
 }