Fix various quoted keys bugs (#400)

Fixes #396 #397 #398 #399
This commit is contained in:
x-hgg-x
2020-05-07 05:13:18 +02:00
committed by GitHub
parent c5fbd3eba6
commit 19eb8cf036
8 changed files with 82 additions and 33 deletions
+53 -1
View File
@@ -287,6 +287,59 @@ func TestBasicUnmarshal(t *testing.T) {
}
}
type quotedKeyMarshalTestStruct struct {
String string `toml:"Z.string-àéù"`
Float float64 `toml:"Yfloat-𝟘"`
Sub basicMarshalTestSubStruct `toml:"Xsubdoc-àéù"`
SubList []basicMarshalTestSubStruct `toml:"W.sublist-𝟘"`
}
var quotedKeyMarshalTestData = quotedKeyMarshalTestStruct{
String: "Hello",
Float: 3.5,
Sub: basicMarshalTestSubStruct{"One"},
SubList: []basicMarshalTestSubStruct{{"Two"}, {"Three"}},
}
var quotedKeyMarshalTestToml = []byte(`"Yfloat-𝟘" = 3.5
"Z.string-àéù" = "Hello"
[["W.sublist-𝟘"]]
String2 = "Two"
[["W.sublist-𝟘"]]
String2 = "Three"
["Xsubdoc-àéù"]
String2 = "One"
`)
func TestBasicMarshalQuotedKey(t *testing.T) {
result, err := Marshal(quotedKeyMarshalTestData)
if err != nil {
t.Fatal(err)
}
expected := quotedKeyMarshalTestToml
if !bytes.Equal(result, expected) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result)
}
}
func TestBasicUnmarshalQuotedKey(t *testing.T) {
tree, err := LoadBytes(quotedKeyMarshalTestToml)
if err != nil {
t.Fatal(err)
}
var q quotedKeyMarshalTestStruct
tree.Unmarshal(&q)
fmt.Println(q)
if !reflect.DeepEqual(quotedKeyMarshalTestData, q) {
t.Errorf("Bad unmarshal: expected\n-----\n%v\n-----\ngot\n-----\n%v\n-----\n", quotedKeyMarshalTestData, q)
}
}
type testDoc struct {
Title string `toml:"title"`
BasicLists testDocBasicLists `toml:"basic_lists"`
@@ -2070,7 +2123,6 @@ func TestUnmarshalCamelCaseKey(t *testing.T) {
}
}
func TestUnmarshalNegativeUint(t *testing.T) {
type check struct{ U uint }