| 2622 | } |
| 2623 | |
| 2624 | func 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] |
| 2637 | path = 100 |
| 2638 | port = 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] |
| 2649 | 2| path = 100 |
| 2650 | | ~~~ cannot decode TOML integer into struct field toml_test.Server.Path of type string |
| 2651 | 3| port = 50` |
| 2652 | |
| 2653 | assert.Equal(t, expected, x.String()) |
| 2654 | } |
| 2655 | |
| 2656 | func TestUnmarshalInvalidTarget(t *testing.T) { |
| 2657 | x := "foo" |