summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/pelletier/go-toml/marshal_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pelletier/go-toml/marshal_test.go')
-rw-r--r--vendor/github.com/pelletier/go-toml/marshal_test.go78
1 files changed, 75 insertions, 3 deletions
diff --git a/vendor/github.com/pelletier/go-toml/marshal_test.go b/vendor/github.com/pelletier/go-toml/marshal_test.go
index e7d1d6e4d..291a80d2a 100644
--- a/vendor/github.com/pelletier/go-toml/marshal_test.go
+++ b/vendor/github.com/pelletier/go-toml/marshal_test.go
@@ -146,8 +146,8 @@ var docData = testDoc{
Second: &subdoc,
},
SubDocList: []testSubDoc{
- testSubDoc{"List.First", 0},
- testSubDoc{"List.Second", 0},
+ {"List.First", 0},
+ {"List.Second", 0},
},
SubDocPtrs: []*testSubDoc{&subdoc},
}
@@ -530,7 +530,7 @@ var strPtr = []*string{&str1, &str2}
var strPtr2 = []*[]*string{&strPtr}
var nestedTestData = nestedMarshalTestStruct{
- String: [][]string{[]string{"Five", "Six"}, []string{"One", "Two"}},
+ String: [][]string{{"Five", "Six"}, {"One", "Two"}},
StringPtr: &strPtr2,
}
@@ -721,6 +721,7 @@ func TestEncodeQuotedMapKeys(t *testing.T) {
t.Errorf("Bad maps marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result)
}
}
+
func TestDecodeQuotedMapKeys(t *testing.T) {
result := mapsTestStruct{}
err := NewDecoder(bytes.NewBuffer(mapsTestToml)).Decode(&result)
@@ -732,3 +733,74 @@ func TestDecodeQuotedMapKeys(t *testing.T) {
t.Errorf("Bad maps unmarshal: expected %v, got %v", expected, result)
}
}
+
+type structArrayNoTag struct {
+ A struct {
+ B []int64
+ C []int64
+ }
+}
+
+func TestMarshalArray(t *testing.T) {
+ expected := []byte(`
+[A]
+ B = [1,2,3]
+ C = [1]
+`)
+
+ m := structArrayNoTag{
+ A: struct {
+ B []int64
+ C []int64
+ }{
+ B: []int64{1, 2, 3},
+ C: []int64{1},
+ },
+ }
+
+ b, err := Marshal(m)
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if !bytes.Equal(b, expected) {
+ t.Errorf("Bad arrays marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, b)
+ }
+}
+
+func TestMarshalArrayOnePerLine(t *testing.T) {
+ expected := []byte(`
+[A]
+ B = [
+ 1,
+ 2,
+ 3
+ ]
+ C = [1]
+`)
+
+ m := structArrayNoTag{
+ A: struct {
+ B []int64
+ C []int64
+ }{
+ B: []int64{1, 2, 3},
+ C: []int64{1},
+ },
+ }
+
+ var buf bytes.Buffer
+ encoder := NewEncoder(&buf).ArraysWithOneElementPerLine(true)
+ err := encoder.Encode(m)
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ b := buf.Bytes()
+
+ if !bytes.Equal(b, expected) {
+ t.Errorf("Bad arrays marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, b)
+ }
+}