Skip to content

Commit 3609e94

Browse files
committed
tests: add fuzz test
1 parent 40c06dc commit 3609e94

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This [Go (golang)](https://golang.org) library implements parsing and serializat
1111

1212
* Fully implementing the RFC
1313
* Compliant with [the official test suite](https://github.com/httpwg/structured-field-tests)
14-
* Unit tested
14+
* Unit and fuzz tested
1515
* Strongly-typed
1616
* Fast (see [the benchmark](httpwg_test.go))
1717
* No dependencies

list_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,41 @@ func TestUnmarshalList(t *testing.T) {
100100
}
101101
}
102102
}
103+
104+
func FuzzUnmarshalList(f *testing.F) {
105+
testCases := []string{"",
106+
"foo,bar",
107+
"foo, bar",
108+
"foo,\t bar",
109+
"foo", "bar",
110+
`"foo";bar;baz=tok`,
111+
`(foo bar);bat`,
112+
`()`,
113+
` "foo";bar;baz=tok, (foo bar);bat `,
114+
`foo,bar,`,
115+
`foo,baré`,
116+
`é`,
117+
`foo,"bar" é`,
118+
`(foo `,
119+
`(foo);é`,
120+
`("é")`,
121+
`(""`,
122+
`(`,
123+
}
124+
125+
for _, t := range testCases {
126+
f.Add(t)
127+
}
128+
129+
f.Fuzz(func(t *testing.T, b string) {
130+
l, err := UnmarshalList([]string{b})
131+
132+
if err != nil {
133+
return
134+
}
135+
136+
if _, err := Marshal(l); err != nil {
137+
t.Errorf("Unexpected marshaling error %q for %q, %#v", err, b, l)
138+
}
139+
})
140+
}

0 commit comments

Comments
 (0)