aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--args.go28
-rw-r--r--args_test.go47
2 files changed, 75 insertions, 0 deletions
diff --git a/args.go b/args.go
index f0e967b..5098727 100644
--- a/args.go
+++ b/args.go
@@ -141,6 +141,34 @@ func (a *Args) DelBytes(key []byte) {
a.args = delAllArgs(a.args, b2s(key))
}
+// Add adds 'key=value' argument.
+//
+// Multiple values for the same key may be added.
+func (a *Args) Add(key, value string) {
+ a.args = appendArg(a.args, key, value)
+}
+
+// AddBytesK adds 'key=value' argument.
+//
+// Multiple values for the same key may be added.
+func (a *Args) AddBytesK(key []byte, value string) {
+ a.args = appendArg(a.args, b2s(key), value)
+}
+
+// AddBytesV adds 'key=value' argument.
+//
+// Multiple values for the same key may be added.
+func (a *Args) AddBytesV(key string, value []byte) {
+ a.args = appendArg(a.args, key, b2s(value))
+}
+
+// AddBytesKV adds 'key=value' argument.
+//
+// Multiple values for the same key may be added.
+func (a *Args) AddBytesKV(key, value []byte) {
+ a.args = appendArg(a.args, b2s(key), b2s(value))
+}
+
// Set sets 'key=value' argument.
func (a *Args) Set(key, value string) {
a.args = setArg(a.args, key, value)
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)
}