dezhidki / Tommy

A single-file TOML reader and writer for C#
MIT License
212 stars 16 forks source link

TomlArray populated with TomlString missing quotations #5

Closed Calytic closed 4 years ago

Calytic commented 4 years ago

Hey! I've got another one.

When serializing a TomlArray with TomlString elements, the TomlStrings are serialized without quotation marks. The output is invalid, causing a TomlParseException when attempting to deserialize the TOML.

Expected Result: array = [ "hello world" ]

Actual Result: array = [ hello world, ]

[TestMethod]
public void TestArrayConstruct()
{
    TomlArray tomlArray = new TomlArray();

    tomlArray.Add(new TomlString()
    {
        Value = "hello world"
    });

    string expectedResult = @"array = [ ""hello world"" ]";

    var table = new TomlTable
    {
        ["array"] = tomlArray
    };

    StringBuilder sb = new StringBuilder();
    using (var sw = new StringWriter(sb))
    {
        table.ToTomlString(sw);
    }

    string actualResult = sb.ToString();

    Assert.AreEqual(expectedResult, actualResult);
}
dezhidki commented 4 years ago

Hmm, that is indeed an issue. I'll push a fix in a moment.

While at it, I also noticed values don't get collapsed properly in inline tables, so that's going to get fixed as well.