Skip to content

Commit ee3e3ca

Browse files
committed
Simplify serialization and inlining heuristic (Fixes #98)
1 parent 9f1e06e commit ee3e3ca

File tree

4 files changed

+158
-180
lines changed

4 files changed

+158
-180
lines changed

src/Tomlyn.Tests/ModelTests/ReflectionModelTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ public void TestCommentRoundtripWithModel()
755755
[Test]
756756
public void TestModelWithSpecialDictionary()
757757
{
758-
var input = @"[values.test]
758+
var input = @"[values]
759+
[values.test]
759760
a = 1
760761
b = true
761762
".ReplaceLineEndings().Trim();

src/Tomlyn.Tests/SerializationTests.cs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public void TestCrlfInMultilineString()
2424

2525
model["property"] = "string\r\nwith\r\nnewlines";
2626

27-
Assert.AreEqual("property = '''string\r\nwith\r\nnewlines'''" + Environment.NewLine, Toml.FromModel(model));
27+
var result = Toml.FromModel(model).Trim();
28+
AssertHelper.AreEqualNormalizeNewLine("property = '''string\r\nwith\r\nnewlines'''", result);
2829
}
2930

3031
[Test]
@@ -41,7 +42,55 @@ public void TestArrayWithPrimitives()
4142
};
4243

4344
var result = Toml.FromModel(model).ReplaceLineEndings("\n").Trim();
44-
Console.WriteLine(result);
45-
Assert.AreEqual("mixed-array = [{a = 1}, 2, 3]", result);
45+
AssertHelper.AreEqualNormalizeNewLine("mixed-array = [{a = 1}, 2, 3]", result);
46+
}
47+
48+
[Test]
49+
public void TestNestedEmptyArrays()
50+
{
51+
var outer = new TomlTable
52+
{
53+
["inner1"] = new TomlTable { },
54+
["inner2"] = new TomlTable {
55+
{ "array1", new TomlArray {} },
56+
{ "array2", new TomlArray {} }
57+
},
58+
["inner3"] = new TomlTable {
59+
{ "array1", new TomlArray {} },
60+
{ "array2", new TomlArray {} },
61+
{ "array3", new TomlArray { "hello" } },
62+
{ "array4", new TomlArray { } },
63+
{ "array5", new TomlArray { } },
64+
{ "array6", new TomlArray { } }
65+
},
66+
["inner4"] = new TomlTable {
67+
{ "array1", new TomlArray {} },
68+
{ "string", "value" },
69+
{ "array2", new TomlArray {} },
70+
{ "array3", new TomlArray {} },
71+
},
72+
};
73+
74+
var expecting = """
75+
[inner1]
76+
[inner2]
77+
array1 = []
78+
array2 = []
79+
[inner3]
80+
array1 = []
81+
array2 = []
82+
array3 = ["hello"]
83+
array4 = []
84+
array5 = []
85+
array6 = []
86+
[inner4]
87+
array1 = []
88+
string = "value"
89+
array2 = []
90+
array3 = []
91+
""".ReplaceLineEndings("\n");
92+
93+
var result = Toml.FromModel(outer).ReplaceLineEndings("\n").Trim();
94+
AssertHelper.AreEqualNormalizeNewLine(expecting, result);
4695
}
4796
}

src/Tomlyn.Tests/Tomlyn.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
16-
<PackageReference Include="nunit" Version="4.3.1" />
17-
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
19-
<PackageReference Include="System.Text.Json" Version="9.0.0" />
20-
<PackageReference Include="Portable.System.DateTimeOnly" Version="8.0.2" Condition="'$(TargetFramework)' == 'net48'" />
16+
<PackageReference Include="nunit" Version="4.3.2" />
17+
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
19+
<PackageReference Include="System.Text.Json" Version="9.0.2" />
20+
<PackageReference Include="Portable.System.DateTimeOnly" Version="9.0.0" Condition="'$(TargetFramework)' == 'net48'" />
2121
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" Condition="'$(TargetFramework)' == 'net48'" />
2222
<PackageReference Include="PolySharp" Version="1.*">
2323
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)