Skip to content

Commit dc31b54

Browse files
author
Sam Byass
committed
Release 3.0.1 - See CHANGELOG.md for details.
1 parent 34ce14c commit dc31b54

12 files changed

+77
-46
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [Tomlet Changelog](#tomlet-changelog)
66
- [Contents](#contents)
7+
- [3.0.1](#301)
78
- [3.0.0](#300)
89
- [2.2.0](#220)
910
- [2.1.0](#210)
@@ -24,6 +25,10 @@
2425
- [1.0.1](#101)
2526
- [1.0.0](#100)
2627

28+
## 3.0.1
29+
- Hotfix for an issue where the new, preferred, inline serialization would create invalid TOML documents
30+
due to not quoting keys.
31+
2732
## 3.0.0
2833
- BREAKING CHANGE: Moved TomlPropertyAttribute to the `Tomlet.Attributes` namespace.
2934
- BREAKING CHANGE: Removed several exceptions that weren't ever actually thrown

README_trimmed_for_nuget.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,13 @@
44
[![NuGet](https://img.shields.io/nuget/v/Samboy063.Tomlet)](https://www.nuget.org/packages/Samboy063.Tomlet/)
55
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/SamboyCoding/Tomlet/.NET)
66
![Toml Version](https://img.shields.io/badge/TOML%20Version-1.0.0-blue)
7+
[![Coverage Status](https://coveralls.io/repos/github/SamboyCoding/Tomlet/badge.svg?branch=master)](https://coveralls.io/github/SamboyCoding/Tomlet?branch=master)
78

89
### I have a [discord server](https://discord.gg/CfPSP5GMMv) for support
910

1011
Tomlet is a zero-dependency library for the [TOML](https://toml.io/) configuration file format. It's targeting [TOML v1.0.0](https://toml.io/en/v1.0.0).
1112

12-
Currently supported features are as follows:
13-
14-
- [x] Primitive key-value pair reading
15-
- [x] Table Reading
16-
- [x] Inline Table Reading
17-
- [x] Array Reading
18-
- [x] Table-Array Reading
19-
- [x] Primitive key-value pair writing
20-
- [x] Table Writing
21-
- [x] Inline Table Writing
22-
- [x] Array Writing
23-
- [x] Table-Array Writing
24-
- [x] Full Unit Tests for everything supported here.
13+
The entire 1.0.0 specification as described [here](https://toml.io/en/v1.0.0) is implemented.
2514

2615
## A word on dotted keys
2716

@@ -67,6 +56,19 @@ class MyClass {
6756
}
6857
```
6958

59+
### Comments
60+
61+
Comments are parsed and stored alongside their corresponding values, where possible. Every instance of `TomlValue`
62+
has a `Comments` property, which contains both the "inline" and "preceding" comments. Precending comments are
63+
the comments that appear before the value (and therefore can span multiple lines), and inline comments are
64+
the comments that appear on the same line as the value (and thus must be a single line).
65+
66+
Any preceding comment which is not associated with a value (i.e. it is placed after the last value) will be
67+
stored in the `TrailingComment` property of the TOML document itself, and will be re-serialized from there.
68+
69+
If you're using Tomlet's reflective serialization feature (i.e. `TomletMain.____From`), you can use the `TomlInlineComment` and `TomlPrecedingComment`
70+
attributes on fields or properties to specify the respective comments.
71+
7072
### Parse a TOML File
7173

7274
`TomlParser.ParseFile` is a utility method to parse an on-disk toml file. This just uses File.ReadAllText, so I/O errors will be thrown up to your calling code.

Tomlet.Tests/DeliberatelyIncorrectTestResources.Designer.cs

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tomlet.Tests/DeliberatelyIncorrectTestResources.resx

+11
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,15 @@ one = 1</value>
148148
<value>[table
149149
one = 1</value>
150150
</data>
151+
<data name="InlineTableLockedTestInput" xml:space="preserve">
152+
<value>type = { name = "Nail" }
153+
type.edible = false # INVALID</value>
154+
</data>
155+
<data name="TableRedefinitionTestInput" xml:space="preserve">
156+
<value>[fruit]
157+
apple = "red"
158+
159+
[fruit]
160+
orange = "orange"</value>
161+
</data>
151162
</root>

Tomlet.Tests/ExceptionTests.cs

+8
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ public void UnterminatedTableArrayThrows() =>
172172
[Fact]
173173
public void UnterminatedTableNameThrows() =>
174174
AssertThrows<UnterminatedTomlTableNameException>(() => GetDocument(DeliberatelyIncorrectTestResources.TomlUnterminatedTableExample));
175+
176+
[Fact]
177+
public void AttemptingToModifyInlineTablesThrowsAnException() =>
178+
AssertThrows<TomlTableLockedException>(() => GetDocument(DeliberatelyIncorrectTestResources.InlineTableLockedTestInput));
179+
180+
[Fact]
181+
public void ReDefiningATableThrowsAnException() =>
182+
AssertThrows<TomlTableRedefinitionException>(() => GetDocument(DeliberatelyIncorrectTestResources.TableRedefinitionTestInput));
175183

176184
//These are all runtime mistakes on otherwise-valid TOML documents, so they aren't in the DeliberatelyIncorrectTestResources file.
177185

Tomlet.Tests/InlineTableTests.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Tomlet.Exceptions;
22
using Tomlet.Models;
3+
using Tomlet.Tests.TestModelClasses;
34
using Xunit;
45

56
namespace Tomlet.Tests
@@ -26,9 +27,18 @@ public void InlineTablesAreSupported()
2627
}
2728

2829
[Fact]
29-
public void AttemptingToModifyInlineTablesThrowsAnException()
30+
public void TablesWithKeysContainingWhitespaceDoNotSerializeInline()
3031
{
31-
Assert.Throws<TomlTableLockedException>(() => GetDocument(TestResources.InlineTableLockedTestInput));
32+
//Serializing these inline means we have to duplicate all the key quoting shenanigans, it's easier just to not inline them
33+
var obj = new KeyWithWhitespaceTestClass() {KeyWithWhitespace = "hello"};
34+
var document = TomlDocument.CreateEmpty();
35+
document.Put("myTable", obj);
36+
37+
var tomlString = document.SerializedValue;
38+
var doc = GetDocument(tomlString);
39+
var newObj = TomletMain.To<KeyWithWhitespaceTestClass>(doc.GetSubTable("myTable"));
40+
41+
Assert.Equal(obj.KeyWithWhitespace, newObj.KeyWithWhitespace);
3242
}
3343
}
3444
}

Tomlet.Tests/TableTests.cs

-6
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,5 @@ public void TablesCanHaveQuotedDottedNames()
5656

5757
Assert.Equal("pug", document.GetSubTable("dog").GetSubTable("tater.man").GetSubTable("type").GetString("name"));
5858
}
59-
60-
[Fact]
61-
public void ReDefiningATableThrowsAnException()
62-
{
63-
Assert.Throws<TomlTableRedefinitionException>(() => GetDocument(TestResources.TableRedefinitionTestInput));
64-
}
6559
}
6660
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Tomlet.Attributes;
2+
3+
namespace Tomlet.Tests.TestModelClasses;
4+
5+
public class KeyWithWhitespaceTestClass
6+
{
7+
[TomlProperty("Key With Whitespace")]
8+
public string KeyWithWhitespace { get; set; }
9+
}

Tomlet.Tests/TestResources.Designer.cs

-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tomlet.Tests/TestResources.resx

-11
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ fruit . flavor = "banana" # same as fruit.flavor</value>
204204
empty = { }
205205
point = { x = 1, y = 2 }
206206
animal = { type.name = "pug" }</value>
207-
</data>
208-
<data name="InlineTableLockedTestInput" xml:space="preserve">
209-
<value>type = { name = "Nail" }
210-
type.edible = false # INVALID</value>
211207
</data>
212208
<data name="BasicTableTestInput" xml:space="preserve">
213209
<value>[table-1]
@@ -221,13 +217,6 @@ key2 = 456</value>
221217
<data name="TableWithQuotedDottedStringTestInput" xml:space="preserve">
222218
<value>[dog."tater.man"]
223219
type.name = "pug"</value>
224-
</data>
225-
<data name="TableRedefinitionTestInput" xml:space="preserve">
226-
<value>[fruit]
227-
apple = "red"
228-
229-
[fruit]
230-
orange = "orange"</value>
231220
</data>
232221
<data name="ComplexTableArrayTestInput" xml:space="preserve">
233222
<value>[[fruits]]

Tomlet/Models/TomlTable.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public class TomlTable : TomlValue
1919

2020
public HashSet<string> Keys => new(Entries.Keys);
2121

22-
public bool ShouldBeSerializedInline => Entries.Count < 4 && Entries.All(e => e.Value.Comments.ThereAreNoComments && (e.Value is TomlArray arr ? arr.IsSimpleArray : e.Value is not TomlTable));
22+
public bool ShouldBeSerializedInline => Entries.Count < 4
23+
&& Entries.All(e => !e.Key.Contains(" ")
24+
&& e.Value.Comments.ThereAreNoComments
25+
&& (e.Value is TomlArray arr ? arr.IsSimpleArray : e.Value is not TomlTable));
2326

2427
public override string SerializedValue
2528
{

Tomlet/Tomlet.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<LangVersion>10</LangVersion>
55
<Nullable>enable</Nullable>
66
<PackageId>Samboy063.Tomlet</PackageId>
7-
<Version>3.0.0</Version>
7+
<Version>3.0.1</Version>
88
<Authors>Sam Byass</Authors>
99
<Company>N/A</Company>
1010
<PackageTags>toml</PackageTags>

0 commit comments

Comments
 (0)