diff --git a/src/Tomlyn.Tests/AssertHelper.cs b/src/Tomlyn.Tests/AssertHelper.cs
new file mode 100644
index 0000000..11248a4
--- /dev/null
+++ b/src/Tomlyn.Tests/AssertHelper.cs
@@ -0,0 +1,23 @@
+// Copyright (c) 2019 - Alexandre Mutel. All rights reserved.
+// Licensed under the BSD-Clause 2 license.
+// See license.txt file in the project root for full license information.
+
+using NUnit.Framework;
+
+namespace Tomlyn.Tests
+{
+ public static class AssertHelper
+ {
+ public static void AreEqualNormalizeNewLine(string expected, string actual, string message = null)
+ {
+ expected = NormalizeEndOfLine(expected);
+ actual = NormalizeEndOfLine(actual);
+ Assert.AreEqual(expected, actual, message);
+ }
+
+ public static string NormalizeEndOfLine(string text)
+ {
+ return text.Replace("\r\n", "\n");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tomlyn.Tests/ModelTests.cs b/src/Tomlyn.Tests/ModelTests.cs
index 41dc826..7bc6daa 100644
--- a/src/Tomlyn.Tests/ModelTests.cs
+++ b/src/Tomlyn.Tests/ModelTests.cs
@@ -250,20 +250,12 @@ private static void AssertJson(string input, string expectedJson)
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Formatting = Formatting.Indented });
var writer = new StringWriter();
serializer.Serialize(writer, model);
- var jsonResult = NormalizeEndOfLine(writer.ToString());
- expectedJson = NormalizeEndOfLine(expectedJson);
+ var jsonResult = writer.ToString();
StandardTests.DisplayHeader("json");
Console.WriteLine(jsonResult);
- Assert.AreEqual(expectedJson, jsonResult);
+ AssertHelper.AreEqualNormalizeNewLine(expectedJson, jsonResult);
}
-
- private static string NormalizeEndOfLine(string text)
- {
- return text.Replace("\r\n", "\n");
- }
-
-
}
}
\ No newline at end of file
diff --git a/src/Tomlyn.Tests/StandardTests.cs b/src/Tomlyn.Tests/StandardTests.cs
index c314fc7..111f991 100644
--- a/src/Tomlyn.Tests/StandardTests.cs
+++ b/src/Tomlyn.Tests/StandardTests.cs
@@ -119,14 +119,14 @@ public static IEnumerable ListTomlFiles(string type)
{
var functionName = Path.GetFileName(file);
- var input = File.ReadAllText(file);
+ var input = File.ReadAllText(file, Encoding.UTF8);
string json = null;
if (type == "valid")
{
var jsonFile = Path.ChangeExtension(file, "json");
Assert.True(File.Exists(jsonFile), $"The json file `{jsonFile}` does not exist");
- json = File.ReadAllText(jsonFile);
+ json = File.ReadAllText(jsonFile, Encoding.UTF8);
}
tests.Add(new TestCaseData(functionName, input, json));
}
diff --git a/src/Tomlyn.Tests/SyntaxTests.cs b/src/Tomlyn.Tests/SyntaxTests.cs
new file mode 100644
index 0000000..00ad27c
--- /dev/null
+++ b/src/Tomlyn.Tests/SyntaxTests.cs
@@ -0,0 +1,56 @@
+// Copyright (c) 2019 - Alexandre Mutel. All rights reserved.
+// Licensed under the BSD-Clause 2 license.
+// See license.txt file in the project root for full license information.
+
+using NUnit.Framework;
+using Tomlyn.Syntax;
+
+namespace Tomlyn.Tests
+{
+ public class SyntaxTests
+ {
+ [Test]
+ public void TestDocument()
+ {
+ var doc = new DocumentSyntax()
+ {
+ Tables =
+ {
+ new TableSyntax("test")
+ {
+ Items =
+ {
+ {"a", 1},
+ {"b", true },
+ {"c", "Check"},
+ {"d", "ToEscape\nWithAnotherChar\t" },
+ {"e", 12.5 },
+ {"f", new int[] {1,2,3,4} },
+ {"g", new string[] {"0", "1", "2"} },
+ {"key with space", 2}
+ }
+ }
+ }
+ };
+
+ var docStr = doc.ToString();
+
+ var expected = @"[test]
+a = 1
+b = true
+c = ""Check""
+d = ""ToEscape\nWithAnotherChar\t""
+e = 12.5
+f = [1, 2, 3, 4]
+g = [""0"", ""1"", ""2""]
+""key with space"" = 2
+";
+
+ AssertHelper.AreEqualNormalizeNewLine(expected, docStr);
+
+ // Reparse the result and compare it again
+ var newDoc = Toml.Parse(docStr);
+ AssertHelper.AreEqualNormalizeNewLine(expected, newDoc.ToString());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tomlyn.sln.DotSettings b/src/Tomlyn.sln.DotSettings
index 25da38b..39dea03 100644
--- a/src/Tomlyn.sln.DotSettings
+++ b/src/Tomlyn.sln.DotSettings
@@ -1,7 +1,10 @@
- Copyright (c) $CURRENT_YEAR$ - Alexandre Mutel. All rights reserved.
+ Copyright (c) Alexandre Mutel. All rights reserved.
Licensed under the BSD-Clause 2 license.
See license.txt file in the project root for full license information.
RFC
+ True
+ True
True
- True
\ No newline at end of file
+ True
+ True
\ No newline at end of file
diff --git a/src/Tomlyn/Model/ObjectKind.cs b/src/Tomlyn/Model/ObjectKind.cs
index bdfadaf..8ac757f 100644
--- a/src/Tomlyn/Model/ObjectKind.cs
+++ b/src/Tomlyn/Model/ObjectKind.cs
@@ -3,6 +3,9 @@
// See license.txt file in the project root for full license information.
namespace Tomlyn.Model
{
+ ///
+ /// Kind of an TOML object.
+ ///
public enum ObjectKind
{
Table,
diff --git a/src/Tomlyn/Model/SyntaxTransform.cs b/src/Tomlyn/Model/SyntaxTransform.cs
index 21b08fb..47dfbf9 100644
--- a/src/Tomlyn/Model/SyntaxTransform.cs
+++ b/src/Tomlyn/Model/SyntaxTransform.cs
@@ -7,6 +7,9 @@
namespace Tomlyn.Model
{
+ ///
+ /// Internal class used to transform a into a
+ ///
internal class SyntaxTransform : SyntaxVisitor
{
private readonly TomlTable _rootTable;
@@ -42,12 +45,12 @@ public override void Visit(TableArraySyntax table)
private TomlTable SetKeyValue(KeySyntax key, object value, SyntaxKind kind)
{
var currentTable = _currentTable;
- var name = GetStringFromBasic(key.Base);
- var items = key.DotKeyItems;
+ var name = GetStringFromBasic(key.Key);
+ var items = key.DotKeys;
for (int i = 0; i < items.ChildrenCount; i++)
{
currentTable = GetTable(currentTable, name, false);
- name = GetStringFromBasic(items.GetChildren(i).Value);
+ name = GetStringFromBasic(items.GetChildren(i).Key);
}
var isTableArray = kind == SyntaxKind.TableArray;
@@ -93,9 +96,9 @@ private TomlTable GetTable(TomlTable table, string key, bool createTableArrayIte
return newTable;
}
- private string GetStringFromBasic(BasicValueSyntax value)
+ private string GetStringFromBasic(BareKeyOrStringValueSyntax value)
{
- if (value is BasicKeySyntax basicKey)
+ if (value is BareKeySyntax basicKey)
{
return basicKey.Key.Text;
}
diff --git a/src/Tomlyn/Model/TomlArray.cs b/src/Tomlyn/Model/TomlArray.cs
index 022bca9..83bb87a 100644
--- a/src/Tomlyn/Model/TomlArray.cs
+++ b/src/Tomlyn/Model/TomlArray.cs
@@ -8,7 +8,10 @@
namespace Tomlyn.Model
{
- public class TomlArray : TomlObject, IList