Write empty tables as well (#169)

Empty tables are allowed by the spec, so they should not be removed:

  [[empty-tables]]
  [[empty-tables]]

is perfectly valid.

Fixes #163
This commit is contained in:
Thomas Pelletier
2017-05-30 18:35:27 -07:00
committed by GitHub
parent 40ecdac242
commit 5ccdfb18c7
2 changed files with 33 additions and 11 deletions
+24
View File
@@ -40,6 +40,30 @@ func assertErrorString(t *testing.T, expected string, err error) {
}
}
func TestTreeWriteToEmptyTable(t *testing.T) {
doc := `[[empty-tables]]
[[empty-tables]]`
toml, err := Load(doc)
if err != nil {
t.Fatal("Unexpected Load error:", err)
}
tomlString, err := toml.ToTomlString()
if err != nil {
t.Fatal("Unexpected ToTomlString error:", err)
}
expected := `
[[empty-tables]]
[[empty-tables]]
`
if tomlString != expected {
t.Fatalf("Expected:\n%s\nGot:\n%s", expected, tomlString)
}
}
func TestTreeWriteToTomlString(t *testing.T) {
toml, err := Load(`name = { first = "Tom", last = "Preston-Werner" }
points = { x = 1, y = 2 }`)