MCPcopy
hub / github.com/valyala/fasthttp / TestArgsAdd

Function TestArgsAdd

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

Source from the content-addressed store, hash-verified

36}
37
38func TestArgsAdd(t *testing.T) {
39 t.Parallel()
40
41 var a Args
42 a.Add("foo", "bar")
43 a.Add("foo", "baz")
44 a.Add("foo", "1")
45 a.Add("ba", "23")
46 a.Add("foo", "")
47 a.AddNoValue("foo")
48 if a.Len() != 6 {
49 t.Fatalf("unexpected number of elements: %d. Expecting 6", a.Len())
50 }
51 s := a.String()
52 expectedS := "foo=bar&foo=baz&foo=1&ba=23&foo=&foo"
53 if s != expectedS {
54 t.Fatalf("unexpected result: %q. Expecting %q", s, expectedS)
55 }
56
57 a.Sort(bytes.Compare)
58 ss := a.String()
59 expectedSS := "ba=23&foo=&foo&foo=1&foo=bar&foo=baz"
60 if ss != expectedSS {
61 t.Fatalf("unexpected result: %q. Expecting %q", ss, expectedSS)
62 }
63
64 var a1 Args
65 a1.Parse(s)
66 if a1.Len() != 6 {
67 t.Fatalf("unexpected number of elements: %d. Expecting 6", a.Len())
68 }
69
70 var barFound, bazFound, oneFound, emptyFound1, emptyFound2, baFound bool
71 for k, v := range a1.All() {
72 switch string(k) {
73 case "foo":
74 switch string(v) {
75 case "bar":
76 barFound = true
77 case "baz":
78 bazFound = true
79 case "1":
80 oneFound = true
81 case "":
82 if emptyFound1 {
83 emptyFound2 = true
84 } else {
85 emptyFound1 = true
86 }
87 default:
88 t.Fatalf("unexpected value %q", v)
89 }
90 case "ba":
91 if string(v) != "23" {
92 t.Fatalf("unexpected value: %q. Expecting %q", v, "23")
93 }
94 baFound = true
95 default:

Callers

nothing calls this directly

Calls 7

AddMethod · 0.95
AddNoValueMethod · 0.95
LenMethod · 0.95
StringMethod · 0.95
SortMethod · 0.95
ParseMethod · 0.95
AllMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…