unmarshal: convert ints if target type is compatible (#594)

This is required to support custom types.

Fixes #590
This commit is contained in:
Thomas Pelletier
2021-09-09 21:25:14 -04:00
committed by GitHub
parent fa56f48daf
commit ee9b902222
2 changed files with 37 additions and 20 deletions
+16 -7
View File
@@ -782,6 +782,22 @@ func TestIssue424(t *testing.T) {
require.Equal(t, msg2, msg2parsed)
}
func TestIssue567(t *testing.T) {
var m map[string]interface{}
err := toml.Unmarshal([]byte("A = 12:08:05"), &m)
require.NoError(t, err)
require.IsType(t, m["A"], toml.LocalTime{})
}
func TestIssue590(t *testing.T) {
type CustomType int
var cfg struct {
Option CustomType `toml:"option"`
}
err := toml.Unmarshal([]byte("option = 42"), &cfg)
require.NoError(t, err)
}
func ExampleMarshal() {
type MyConfig struct {
Version int
@@ -806,10 +822,3 @@ func ExampleMarshal() {
// Name = 'go-toml'
// Tags = ['go', 'toml']
}
func TestIssue567(t *testing.T) {
var m map[string]interface{}
err := toml.Unmarshal([]byte("A = 12:08:05"), &m)
require.NoError(t, err)
require.IsType(t, m["A"], toml.LocalTime{})
}