MCPcopy
hub / github.com/pelletier/go-toml / TestUnmarshalIntegerInvalidStructField

Function TestUnmarshalIntegerInvalidStructField

unmarshaler_test.go:2624–2654  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2622}
2623
2624func TestUnmarshalIntegerInvalidStructField(t *testing.T) {
2625 type Server struct {
2626 Path string
2627 Port int
2628 }
2629
2630 type Cfg struct {
2631 Server Server
2632 }
2633
2634 var cfg Cfg
2635
2636 data := `[server]
2637path = 100
2638port = 50
2639`
2640
2641 file := strings.NewReader(data)
2642 err := toml.NewDecoder(file).Decode(&cfg)
2643 assert.Error(t, err)
2644
2645 var x *toml.DecodeError
2646 assert.True(t, errors.As(err, &x))
2647 assert.Equal(t, "toml: cannot decode TOML integer into struct field toml_test.Server.Path of type string", x.Error())
2648 expected := `1| [server]
26492| path = 100
2650 | ~~~ cannot decode TOML integer into struct field toml_test.Server.Path of type string
26513| port = 50`
2652
2653 assert.Equal(t, expected, x.String())
2654}
2655
2656func TestUnmarshalInvalidTarget(t *testing.T) {
2657 x := "foo"

Callers

nothing calls this directly

Calls 6

ErrorMethod · 0.95
StringMethod · 0.95
ErrorFunction · 0.92
TrueFunction · 0.92
EqualFunction · 0.92
DecodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…