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

Function TestMarshalDictionnary

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

AddMethod · 0.95
marshalSFVMethod · 0.95
GetMethod · 0.95
DelMethod · 0.95
NamesMethod · 0.95
NewDictionaryFunction · 0.85
NewItemFunction · 0.85
TokenTypeAlias · 0.85
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…