diff Implab.Format.Test/JsonTests.cs @ 228:6fa235c5a760 v2

Rewritten JsonScanner, JsonParser, fixed naming style
author cin
date Tue, 12 Sep 2017 01:19:12 +0300
parents 8d5de4eb9c2c
children 5f7a3e1d32b9
line wrap: on
line diff
--- a/Implab.Format.Test/JsonTests.cs	Sat Sep 09 03:53:13 2017 +0300
+++ b/Implab.Format.Test/JsonTests.cs	Tue Sep 12 01:19:12 2017 +0300
@@ -1,41 +1,42 @@
 using NUnit.Framework;
 using System;
-using Implab.Formats.JSON;
 using Implab.Automaton;
 using Implab.Xml;
 using System.Xml;
-using System.Text;
+using Implab.Formats;
+using Implab.Formats.Json;
 
 namespace Implab.Format.Test {
     [TestFixture]
     public class JsonTests {
+        
         [Test]
         public void TestScannerValidTokens() {
-            using (var scanner = new JSONScanner(@"9123, -123, 0, 0.1, -0.2, -0.1e3, 1.3E-3, ""some \t\n\u0020 text"", literal []{}:")) {
+            using (var scanner = JsonStringScanner.Create(@"9123, -123, 0, 0.1, -0.2, -0.1e3, 1.3E-3, ""some \t\n\u0020 text"", literal []{}:")) {
 
                 Tuple<JsonTokenType, object>[] expexted = {
                     new Tuple<JsonTokenType,object>(JsonTokenType.Number, 9123d),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", "),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
                     new Tuple<JsonTokenType,object>(JsonTokenType.Number, -123d),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", "),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
                     new Tuple<JsonTokenType,object>(JsonTokenType.Number, 0d),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", "),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
                     new Tuple<JsonTokenType,object>(JsonTokenType.Number, 0.1d),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", "),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
                     new Tuple<JsonTokenType,object>(JsonTokenType.Number, -0.2d),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", "),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
                     new Tuple<JsonTokenType,object>(JsonTokenType.Number, -0.1e3d),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", "),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
                     new Tuple<JsonTokenType,object>(JsonTokenType.Number, 1.3E-3d),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", "),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
                     new Tuple<JsonTokenType,object>(JsonTokenType.String, "some \t\n  text"),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", "),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
                     new Tuple<JsonTokenType,object>(JsonTokenType.Literal, "literal"),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.BeginArray, " ["),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.EndArray, "]"),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.BeginObject, "{"),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.EndObject, "}"),
-                    new Tuple<JsonTokenType,object>(JsonTokenType.NameSeparator, ":")
+                    new Tuple<JsonTokenType,object>(JsonTokenType.BeginArray, null),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.EndArray, null),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.BeginObject, null),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.EndObject, null),
+                    new Tuple<JsonTokenType,object>(JsonTokenType.NameSeparator, null)
                 };
 
                 object value;
@@ -70,7 +71,7 @@
             };
 
             foreach (var json in bad) {
-                using (var scanner = new JSONScanner(json)) {
+                using (var scanner = JsonStringScanner.Create(json)) {
                     try {
                         object value;
                         JsonTokenType token;
@@ -122,7 +123,7 @@
         void DumpJsonParse(string json) {
             Console.WriteLine($"JSON: {json}");
             Console.WriteLine("XML");
-            using (var xmlReader = new JsonXmlReader(new JSONParser(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", NodesPrefix = "json" })) {
+            using (var xmlReader = new JsonXmlReader(new JsonParser(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", NodesPrefix = "json" })) {
                 while (xmlReader.Read())
                     Console.WriteLine($"{new string(' ', xmlReader.Depth * 2)}{xmlReader}");
             }
@@ -136,7 +137,7 @@
                 CloseOutput = false,
                 ConformanceLevel = ConformanceLevel.Document
             }))
-            using (var xmlReader = new JsonXmlReader(new JSONParser(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", NodesPrefix = "", FlattenArrays = true })) {
+            using (var xmlReader = new JsonXmlReader(new JsonParser(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", NodesPrefix = "", FlattenArrays = true })) {
                 xmlWriter.WriteNode(xmlReader, false);
             }
         }