aboutsummaryrefslogtreecommitdiff
path: root/bytesconv_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2017-06-19 18:35:07 +0300
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2017-06-19 18:35:07 +0300
commitc0de95e84b2841e58541a63983621f294d3112f8 (patch)
tree153819512c519cdbe7eaa76506e8e0cfe4de9909 /bytesconv_test.go
parentCompress responses only if their content-type starts with text/ or application/ (diff)
downloadfasthttp-c0de95e84b2841e58541a63983621f294d3112f8.tar.gz
fasthttp-c0de95e84b2841e58541a63983621f294d3112f8.tar.bz2
fasthttp-c0de95e84b2841e58541a63983621f294d3112f8.zip
Added AppendUnquotedArg - the complementary function to AppendQuotedArg
Diffstat (limited to 'bytesconv_test.go')
-rw-r--r--bytesconv_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/bytesconv_test.go b/bytesconv_test.go
index fde6f26..b5da44d 100644
--- a/bytesconv_test.go
+++ b/bytesconv_test.go
@@ -257,3 +257,44 @@ func testParseUintSuccess(t *testing.T, s string, expectedN int) {
t.Fatalf("Unexpected value %d. Expected %d. num=%q", n, expectedN, s)
}
}
+
+func TestAppendUnquotedArg(t *testing.T) {
+ testAppendUnquotedArg(t, "", "")
+ testAppendUnquotedArg(t, "abc", "abc")
+ testAppendUnquotedArg(t, "тест.abc", "тест.abc")
+ testAppendUnquotedArg(t, "%D1%82%D0%B5%D1%81%D1%82%20%=&;:", "тест %=&;:")
+}
+
+func testAppendUnquotedArg(t *testing.T, s, expectedS string) {
+ // test appending to nil
+ result := AppendUnquotedArg(nil, []byte(s))
+ if string(result) != expectedS {
+ t.Fatalf("Unexpected AppendUnquotedArg(%q)=%q, want %q", s, result, expectedS)
+ }
+
+ // test appending to prefix
+ prefix := "prefix"
+ dst := []byte(prefix)
+ dst = AppendUnquotedArg(dst, []byte(s))
+ if !bytes.HasPrefix(dst, []byte(prefix)) {
+ t.Fatalf("Unexpected prefix for AppendUnquotedArg(%q)=%q, want %q", s, dst, prefix)
+ }
+ result = dst[len(prefix):]
+ if string(result) != expectedS {
+ t.Fatalf("Unexpected AppendUnquotedArg(%q)=%q, want %q", s, result, expectedS)
+ }
+
+ // test in-place appending
+ result = []byte(s)
+ result = AppendUnquotedArg(result[:0], result)
+ if string(result) != expectedS {
+ t.Fatalf("Unexpected AppendUnquotedArg(%q)=%q, want %q", s, result, expectedS)
+ }
+
+ // verify AppendQuotedArg <-> AppendUnquotedArg conversion
+ quotedS := AppendQuotedArg(nil, []byte(s))
+ unquotedS := AppendUnquotedArg(nil, quotedS)
+ if s != string(unquotedS) {
+ t.Fatalf("Unexpected AppendUnquotedArg(AppendQuotedArg(%q))=%q, want %q", s, unquotedS, s)
+ }
+}