Mercurial > pub > ImplabNet
diff Implab.Format.Test/JsonTests.cs @ 229:5f7a3e1d32b9 v2
JsonXmlReader performance tuning
JsonScanner now operates strings and doesn't
parses number and literals.
Added SerializationHelpers to common serialize/deserialize operations
author | cin |
---|---|
date | Tue, 12 Sep 2017 19:07:42 +0300 |
parents | 6fa235c5a760 |
children | 302ca905c19e |
line wrap: on
line diff
--- a/Implab.Format.Test/JsonTests.cs Tue Sep 12 01:19:12 2017 +0300 +++ b/Implab.Format.Test/JsonTests.cs Tue Sep 12 19:07:42 2017 +0300 @@ -5,6 +5,7 @@ using System.Xml; using Implab.Formats; using Implab.Formats.Json; +using System.IO; namespace Implab.Format.Test { [TestFixture] @@ -15,19 +16,19 @@ 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.Number, "9123"), new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null), - new Tuple<JsonTokenType,object>(JsonTokenType.Number, -123d), + new Tuple<JsonTokenType,object>(JsonTokenType.Number, "-123"), new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null), - new Tuple<JsonTokenType,object>(JsonTokenType.Number, 0d), + new Tuple<JsonTokenType,object>(JsonTokenType.Number, "0"), new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null), - new Tuple<JsonTokenType,object>(JsonTokenType.Number, 0.1d), + new Tuple<JsonTokenType,object>(JsonTokenType.Number, "0.1"), new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null), - new Tuple<JsonTokenType,object>(JsonTokenType.Number, -0.2d), + new Tuple<JsonTokenType,object>(JsonTokenType.Number, "-0.2"), new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null), - new Tuple<JsonTokenType,object>(JsonTokenType.Number, -0.1e3d), + new Tuple<JsonTokenType,object>(JsonTokenType.Number, "-0.1e3"), new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null), - new Tuple<JsonTokenType,object>(JsonTokenType.Number, 1.3E-3d), + new Tuple<JsonTokenType,object>(JsonTokenType.Number, "1.3E-3"), new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null), new Tuple<JsonTokenType,object>(JsonTokenType.String, "some \t\n text"), new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null), @@ -39,7 +40,7 @@ new Tuple<JsonTokenType,object>(JsonTokenType.NameSeparator, null) }; - object value; + string value; JsonTokenType tokenType; for (var i = 0; i < expexted.Length; i++) { @@ -73,7 +74,7 @@ foreach (var json in bad) { using (var scanner = JsonStringScanner.Create(json)) { try { - object value; + string value; JsonTokenType token; scanner.ReadToken(out value, out token); if (!Object.Equals(value, json)) { @@ -109,11 +110,11 @@ //DumpJsonParse("{}"); //DumpJsonParse("[]"); DumpJsonParse("{\"one\":1, \"two\":2}"); - DumpJsonParse("[1,2,3]"); + DumpJsonParse("[1,\"\",2,3]"); DumpJsonParse("[{\"info\": [7,8,9]}]"); - DumpJsonFlatParse("[1,2,[3,4],{\"info\": [5,6]},{\"num\": [7,8,null]}, null,[null]]"); + DumpJsonFlatParse("[1,2,\"\",[3,4],{\"info\": [5,6]},{\"num\": [7,8,null]}, null,[null]]"); } - + void AssertRead(XmlReader reader, XmlNodeType expected) { Assert.IsTrue(reader.Read()); Console.WriteLine($"{new string(' ', reader.Depth*2)}{reader}"); @@ -123,7 +124,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(JsonReader.ParseString(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", NodesPrefix = "json" })) { while (xmlReader.Read()) Console.WriteLine($"{new string(' ', xmlReader.Depth * 2)}{xmlReader}"); } @@ -137,7 +138,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(JsonReader.ParseString(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", NodesPrefix = "", FlattenArrays = true })) { xmlWriter.WriteNode(xmlReader, false); } }