Nested arrays

This commit is contained in:
Thomas Pelletier
2021-02-09 19:22:54 -05:00
parent 2790964270
commit 7dbf7554c4
4 changed files with 523 additions and 102 deletions
+36
View File
@@ -245,6 +245,42 @@ func TestArraySimple(t *testing.T) {
assert.Equal(t, []string{"hello", "world"}, x.Foo)
}
func TestArrayNestedInTable(t *testing.T) {
x := struct {
Wrapper struct {
Foo []string
}
}{}
doc := `[Wrapper]
Foo = ["hello", "world"]`
err := toml.Unmarshal([]byte(doc), &x)
require.NoError(t, err)
assert.Equal(t, []string{"hello", "world"}, x.Wrapper.Foo)
}
func TestArrayMixed(t *testing.T) {
x := struct {
Wrapper struct {
Foo []interface{}
}
}{}
doc := `[Wrapper]
Foo = ["hello", true]`
err := toml.Unmarshal([]byte(doc), &x)
require.NoError(t, err)
assert.Equal(t, []interface{}{"hello", true}, x.Wrapper.Foo)
}
func TestArrayNested(t *testing.T) {
x := struct {
Foo [][]string
}{}
doc := `Foo = [["hello", "world"], ["a"], []]`
err := toml.Unmarshal([]byte(doc), &x)
require.NoError(t, err)
assert.Equal(t, [][]string{{"hello", "world"}, {"a"}, nil}, x.Foo)
}
func TestBool(t *testing.T) {
x := struct {
Truthy bool