aboutsummaryrefslogtreecommitdiff
path: root/args_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-10-27 12:53:33 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-10-27 12:53:33 +0200
commitd70261286c1b3ae2a7d81d79d74097755bbf3c43 (patch)
treeb702da73e677d01d58d440a0f5f0b34823b762b8 /args_test.go
parentSmall fix in docs (diff)
downloadfasthttp-d70261286c1b3ae2a7d81d79d74097755bbf3c43.tar.gz
fasthttp-d70261286c1b3ae2a7d81d79d74097755bbf3c43.tar.bz2
fasthttp-d70261286c1b3ae2a7d81d79d74097755bbf3c43.zip
Added CopyTo, VisitAll and *Bytes* helper functions to Args, RequestHeader and ResponseHeader
Diffstat (limited to 'args_test.go')
-rw-r--r--args_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/args_test.go b/args_test.go
index c9eecf0..9a98a60 100644
--- a/args_test.go
+++ b/args_test.go
@@ -6,6 +6,61 @@ import (
"testing"
)
+func TestArgsCopyTo(t *testing.T) {
+ var a Args
+
+ // empty args
+ testCopyTo(t, &a)
+
+ a.Set("foo", "bar")
+ testCopyTo(t, &a)
+
+ a.Set("xxx", "yyy")
+ testCopyTo(t, &a)
+
+ a.Del("foo")
+ testCopyTo(t, &a)
+}
+
+func testCopyTo(t *testing.T, a *Args) {
+ keys := make(map[string]struct{})
+ a.VisitAll(func(k, v []byte) {
+ keys[string(k)] = struct{}{}
+ })
+
+ var b Args
+ a.CopyTo(&b)
+
+ b.VisitAll(func(k, v []byte) {
+ if _, ok := keys[string(k)]; !ok {
+ t.Fatalf("unexpected key %q after copying from %q", k, a.String())
+ }
+ delete(keys, string(k))
+ })
+ if len(keys) > 0 {
+ t.Fatalf("missing keys %#v after copying from %q", keys, a.String())
+ }
+}
+
+func TestArgsVisitAll(t *testing.T) {
+ var a Args
+ a.Set("foo", "bar")
+
+ i := 0
+ a.VisitAll(func(k, v []byte) {
+ if string(k) != "foo" {
+ t.Fatalf("unexpected key %q. Expected %q", k, "foo")
+ }
+ if string(v) != "bar" {
+ t.Fatalf("unexpected value %q. Expected %q", v, "bar")
+ }
+ i++
+ })
+ if i != 1 {
+ t.Fatalf("unexpected number of VisitAll calls: %d. Expected %d", i, 1)
+ }
+}
+
func TestArgsStringCompose(t *testing.T) {
var a Args
a.Set("foo", "bar")