MCPcopy Index your code
hub / github.com/dunglas/httpsfv / TestUnmarshalList

Function TestUnmarshalList

list_test.go:53–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestUnmarshalList(t *testing.T) {
54 t.Parallel()
55
56 l1 := List{Item{Token("foo"), NewParams()}, Item{Token("bar"), NewParams()}}
57
58 il2 := Item{"foo", NewParams()}
59 l2 := List{il2}
60 il2.Params.Add("bar", true)
61 il2.Params.Add("baz", Token("tok"))
62
63 il3 := InnerList{[]Item{{Token("foo"), NewParams()}, {Token("bar"), NewParams()}}, NewParams()}
64 il3.Params.Add("bat", true)
65 l3 := List{il3}
66
67 data := []struct {
68 in []string
69 out List
70 err bool
71 }{
72 {[]string{""}, nil, false},
73 {[]string{"foo,bar"}, l1, false},
74 {[]string{"foo, bar"}, l1, false},
75 {[]string{"foo,\t bar"}, l1, false},
76 {[]string{"foo", "bar"}, l1, false},
77 {[]string{`"foo";bar;baz=tok`}, l2, false},
78 {[]string{`(foo bar);bat`}, l3, false},
79 {[]string{`()`}, List{InnerList{nil, NewParams()}}, false},
80 {[]string{` "foo";bar;baz=tok, (foo bar);bat `}, List{il2, il3}, false},
81 {[]string{`foo,bar,`}, nil, true},
82 {[]string{`foo,baré`}, nil, true},
83 {[]string{`é`}, nil, true},
84 {[]string{`foo,"bar" é`}, nil, true},
85 {[]string{`(foo `}, nil, true},
86 {[]string{`(foo);é`}, nil, true},
87 {[]string{`("é")`}, nil, true},
88 {[]string{`(""`}, nil, true},
89 {[]string{`(`}, nil, true},
90 }
91
92 for _, d := range data {
93 l, err := UnmarshalList(d.in)
94 if d.err && err == nil {
95 t.Errorf("UnmarshalList(%s): error expected", d.in)
96 }
97
98 if !d.err && !reflect.DeepEqual(d.out, l) {
99 t.Errorf("UnmarshalList(%s) = %t, %v; %t, <nil> expected", d.in, l, err, d.out)
100 }
101 }
102}
103
104func FuzzUnmarshalList(f *testing.F) {
105 testCases := []string{"",

Callers

nothing calls this directly

Calls 4

TokenTypeAlias · 0.85
NewParamsFunction · 0.85
UnmarshalListFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…