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

Function TestMarshalParameters

params_test.go:9–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestMarshalParameters(t *testing.T) {
10 t.Parallel()
11
12 p := NewParams()
13
14 add := []struct {
15 in string
16 expected interface{}
17 valid bool
18 }{
19 {"f_o1o3-", 10.0, true},
20 {"deleteme", "", true},
21 {"*f0.o*", "", true},
22 {"t", true, true},
23 {"f", false, true},
24 {"b", []byte{0, 1}, true},
25 {"0foo", "", false},
26 {"mAj", "", false},
27 {"_foo", "", false},
28 {"foo", "é", false},
29 }
30
31 var b strings.Builder
32
33 for _, d := range add {
34 vParams := NewParams()
35 vParams.Add(d.in, d.expected)
36
37 b.Reset()
38
39 if valid := vParams.marshalSFV(&b) == nil; valid != d.valid {
40 t.Errorf("(%v, %v).isValid() = %v; %v expected", d.in, d.expected, valid, d.valid)
41 }
42
43 if d.valid {
44 p.Add(d.in, d.expected)
45 }
46 }
47
48 p.Add("f_o1o3-", 123.0)
49
50 newValue, _ := p.Get("f_o1o3-")
51 if newValue != 123.0 {
52 t.Errorf(`Add("f_o1o3-") must overwrite the existing value`)
53 }
54
55 if !p.Del("deleteme") {
56 t.Errorf(`Del("deleteme") must return true`)
57 }
58
59 if p.Del("deleteme") {
60 t.Errorf(`the second call to Del("deleteme") must return false`)
61 }
62
63 if v, ok := p.Get("*f0.o*"); v != "" || !ok {
64 t.Errorf(`Get("*f0.o*") = %v, %v; "", true expected`, v, ok)
65 }
66

Callers

nothing calls this directly

Calls 6

AddMethod · 0.95
marshalSFVMethod · 0.95
GetMethod · 0.95
DelMethod · 0.95
NamesMethod · 0.95
NewParamsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…