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

Function TestMarshalList

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

Source from the content-addressed store, hash-verified

6)
7
8func TestMarshalList(t *testing.T) {
9 t.Parallel()
10
11 params := NewParams()
12 params.Add("foo", true)
13 params.Add("bar", Token("baz"))
14
15 tokItem := NewItem(Token("tok"))
16 tokItem.Params.Add("tp1", 42.42)
17 tokItem.Params.Add("tp2", []byte{0, 1})
18
19 il := InnerList{
20 []Item{NewItem("il"), tokItem},
21 NewParams(),
22 }
23 il.Params.Add("ilp1", true)
24 il.Params.Add("ilp2", false)
25
26 data := []struct {
27 in List
28 expected string
29 valid bool
30 }{
31 {List{}, "", true},
32 {List{NewItem(true)}, "?1", true},
33 {List{Item{"hello", params}}, `"hello";foo;bar=baz`, true},
34 {List{il, Item{"hi", params}}, `("il" tok;tp1=42.42;tp2=:AAE=:);ilp1;ilp2=?0, "hi";foo;bar=baz`, true},
35 {List{NewItem(Token("é"))}, "", false},
36 {List{Item{}}, "", false},
37 }
38
39 for _, d := range data {
40 r, err := Marshal(d.in)
41 if d.valid && err != nil {
42 t.Errorf("error not expected for %v, got %v", d.in, err)
43 } else if !d.valid && err == nil {
44 t.Errorf("error expected for %v, got %v", d.in, err)
45 }
46
47 if r != d.expected {
48 t.Errorf("got %v; want %v", r, d.expected)
49 }
50 }
51}
52
53func TestUnmarshalList(t *testing.T) {
54 t.Parallel()

Callers

nothing calls this directly

Calls 5

AddMethod · 0.95
NewParamsFunction · 0.85
TokenTypeAlias · 0.85
NewItemFunction · 0.85
MarshalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…