@@ -44,6 +44,19 @@ Zstring = "Hello"
|
||||
String2 = "One"
|
||||
`)
|
||||
|
||||
var basicTestTomlCustomIndentation = []byte(`Ystrlist = ["Howdy","Hey There"]
|
||||
Zstring = "Hello"
|
||||
|
||||
[[Wsublist]]
|
||||
String2 = "Two"
|
||||
|
||||
[[Wsublist]]
|
||||
String2 = "Three"
|
||||
|
||||
[Xsubdoc]
|
||||
String2 = "One"
|
||||
`)
|
||||
|
||||
var basicTestTomlOrdered = []byte(`Zstring = "Hello"
|
||||
Ystrlist = ["Howdy","Hey There"]
|
||||
|
||||
@@ -207,6 +220,26 @@ func TestBasicMarshal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBasicMarshalCustomIndentation(t *testing.T) {
|
||||
var result bytes.Buffer
|
||||
err := NewEncoder(&result).Indentation("\t").Encode(basicTestData)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := basicTestTomlCustomIndentation
|
||||
if !bytes.Equal(result.Bytes(), expected) {
|
||||
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestBasicMarshalWrongIndentation(t *testing.T) {
|
||||
var result bytes.Buffer
|
||||
err := NewEncoder(&result).Indentation(" \n").Encode(basicTestData)
|
||||
if err.Error() != "invalid indentation: must only contains space or tab characters" {
|
||||
t.Error("expect err:invalid indentation: must only contains space or tab characters but got:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBasicMarshalOrdered(t *testing.T) {
|
||||
var result bytes.Buffer
|
||||
err := NewEncoder(&result).Order(OrderPreserve).Encode(basicTestData)
|
||||
|
||||
Reference in New Issue
Block a user