Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Improved the tests to reflect improved known fields checks, too #2

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,11 @@ var unmarshalStrictTests = []struct {
data: "a: 1\nc: 2\n",
value: struct{ A, B int }{A: 1},
error: `yaml: unmarshal errors:\n line 2: field c not found in type struct { A int; B int }`,
}, {
known: true,
data: "i: 1\nj: 2\n",
value: customUnmarshaler{I: 2},
error: `yaml: unmarshal errors:\n line 1: field i not found in type yaml_test.bufT`,
}, {
unique: true,
data: "a: 1\nb: 2\na: 3\n",
Expand Down Expand Up @@ -1713,6 +1718,22 @@ func (t *textUnmarshaler) UnmarshalText(s []byte) error {
return nil
}

type customUnmarshaler struct {
I int
}

func (c *customUnmarshaler) UnmarshalYAML(value *yaml.Node) error {
type bufT struct {
J int
}
var buf bufT
if err := value.Decode(&buf); err != nil {
return err
}
c.I = buf.J
return nil
}

func (s *S) TestFuzzCrashers(c *C) {
cases := []string{
// runtime error: index out of range
Expand Down
Loading