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

Function TestOfficialTestSuiteParsing

httpwg_test.go:144–201  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestOfficialTestSuiteParsing(t *testing.T) {
145 const dir = "structured-field-tests/"
146 f, _ := os.Open(dir)
147 files, _ := f.Readdir(-1)
148
149 for _, fi := range files {
150 n := fi.Name()
151 if !strings.HasSuffix(n, ".json") {
152 continue
153 }
154
155 file, _ := os.Open(dir + n)
156 dec := json.NewDecoder(file)
157 dec.UseNumber()
158
159 var tests []test
160 _ = dec.Decode(&tests)
161
162 for _, te := range tests {
163 t.Run(n+"/"+te.Name, func(t *testing.T) {
164 var (
165 expected, got StructuredFieldValue
166 err error
167 )
168
169 switch te.HeaderType {
170 case ITEM:
171 expected = valToItem(te.Expected)
172 got, err = UnmarshalItem(te.Raw)
173 case LIST:
174 expected = valToList(te.Expected)
175 got, err = UnmarshalList(te.Raw)
176 case DICTIONARY:
177 expected = valToDictionary(te.Expected)
178 got, err = UnmarshalDictionary(te.Raw)
179 default:
180 panic("unknown header type")
181 }
182
183 if te.MustFail && err == nil {
184 t.Errorf("%s: %s: must fail", n, te.Name)
185
186 return
187 }
188
189 if (!te.MustFail && !te.CanFail) && err != nil {
190 t.Errorf("%s: %s: must not fail, got error %s", n, te.Name, err)
191
192 return
193 }
194
195 if err == nil && !reflect.DeepEqual(expected, got) {
196 t.Errorf("%s: %s: %#v expected, got %#v", n, te.Name, expected, got)
197 }
198 })
199 }
200 }
201}

Callers

nothing calls this directly

Calls 6

valToItemFunction · 0.85
UnmarshalItemFunction · 0.85
valToListFunction · 0.85
UnmarshalListFunction · 0.85
valToDictionaryFunction · 0.85
UnmarshalDictionaryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…