| 2589 | } |
| 2590 | |
| 2591 | func TestUnmarshalStringInvalidStructField(t *testing.T) { |
| 2592 | type Server struct { |
| 2593 | Path string |
| 2594 | Port int |
| 2595 | } |
| 2596 | |
| 2597 | type Cfg struct { |
| 2598 | Server Server |
| 2599 | } |
| 2600 | |
| 2601 | var cfg Cfg |
| 2602 | |
| 2603 | data := `[server] |
| 2604 | path = "/my/path" |
| 2605 | port = "bad" |
| 2606 | ` |
| 2607 | |
| 2608 | file := strings.NewReader(data) |
| 2609 | err := toml.NewDecoder(file).Decode(&cfg) |
| 2610 | assert.Error(t, err) |
| 2611 | |
| 2612 | var x *toml.DecodeError |
| 2613 | assert.True(t, errors.As(err, &x)) |
| 2614 | assert.Equal(t, "toml: cannot decode TOML string into struct field toml_test.Server.Port of type int", x.Error()) |
| 2615 | expected := `1| [server] |
| 2616 | 2| path = "/my/path" |
| 2617 | 3| port = "bad" |
| 2618 | | ~~~~~ cannot decode TOML string into struct field toml_test.Server.Port of type int` |
| 2619 | |
| 2620 | assert.Equal(t, expected, x.String()) |
| 2621 | assert.Equal(t, toml.Key{"server", "port"}, x.Key()) |
| 2622 | } |
| 2623 | |
| 2624 | func TestUnmarshalIntegerInvalidStructField(t *testing.T) { |
| 2625 | type Server struct { |