aboutsummaryrefslogtreecommitdiff
path: root/args_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-03-29 16:49:42 +0300
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-03-29 16:49:42 +0300
commite9207dac9e5e98cffe8d72a5482602a0e4a8b78d (patch)
treea8a627202584e45c979f25c1b3ab29f8b547f8b9 /args_test.go
parentEliminated bufKV member from Args struct. This shaves off 16 bytes from Reque... (diff)
downloadfasthttp-e9207dac9e5e98cffe8d72a5482602a0e4a8b78d.tar.gz
fasthttp-e9207dac9e5e98cffe8d72a5482602a0e4a8b78d.tar.bz2
fasthttp-e9207dac9e5e98cffe8d72a5482602a0e4a8b78d.zip
Added Args.Add()
Diffstat (limited to 'args_test.go')
-rw-r--r--args_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/args_test.go b/args_test.go
index 5e88c4c..de6e95a 100644
--- a/args_test.go
+++ b/args_test.go
@@ -8,6 +8,53 @@ import (
"time"
)
+func TestArgsAdd(t *testing.T) {
+ var a Args
+ a.Add("foo", "bar")
+ a.Add("foo", "baz")
+ a.Add("foo", "1")
+ a.Add("ba", "23")
+ if a.Len() != 4 {
+ t.Fatalf("unexpected number of elements: %d. Expecting 4", a.Len())
+ }
+ s := a.String()
+ expectedS := "foo=bar&foo=baz&foo=1&ba=23"
+ if s != expectedS {
+ t.Fatalf("unexpected result: %q. Expecting %q", s, expectedS)
+ }
+
+ var a1 Args
+ a1.Parse(s)
+ if a1.Len() != 4 {
+ t.Fatalf("unexpected number of elements: %d. Expecting 4", a.Len())
+ }
+
+ var barFound, bazFound, oneFound, baFound bool
+ a1.VisitAll(func(k, v []byte) {
+ switch string(k) {
+ case "foo":
+ switch string(v) {
+ case "bar":
+ barFound = true
+ case "baz":
+ bazFound = true
+ case "1":
+ oneFound = true
+ default:
+ t.Fatalf("unexpected value %q", v)
+ }
+ case "ba":
+ if string(v) != "23" {
+ t.Fatalf("unexpected value: %q. Expecting %q", v, "23")
+ }
+ baFound = true
+ }
+ })
+ if !barFound || !bazFound || !oneFound || !baFound {
+ t.Fatalf("something is missing: %v, %v, %v, %v", barFound, bazFound, oneFound, baFound)
+ }
+}
+
func TestArgsAcquireReleaseSequential(t *testing.T) {
testArgsAcquireRelease(t)
}