...
1
2
3
4
5
6
7
8
9
10
11
12
13 package chttp
14
15 import (
16 "testing"
17 )
18
19 func TestEncodeDocID(t *testing.T) {
20 tests := []struct {
21 Input string
22 Expected string
23 }{
24 {Input: "foo", Expected: "foo"},
25 {Input: "foo/bar", Expected: "foo%2Fbar"},
26 {Input: "_design/foo", Expected: "_design/foo"},
27 {Input: "_design/foo/bar", Expected: "_design/foo%2Fbar"},
28 {Input: "foo@bar.com", Expected: "foo%40bar.com"},
29 {Input: "foo+bar@baz.com", Expected: "foo%2Bbar%40baz.com"},
30 {Input: "Is this a valid ID?", Expected: "Is%20this%20a%20valid%20ID%3F"},
31 {Input: "nón-English-çharacters", Expected: "n%C3%B3n-English-%C3%A7haracters"},
32 {Input: "foo+bar & páces?!*,", Expected: "foo%2Bbar%20%26%20p%C3%A1ces%3F%21%2A%2C"},
33 {Input: "kivik$1234", Expected: "kivik%241234"},
34 {Input: "_users", Expected: "_users"},
35 }
36 for _, test := range tests {
37 result := EncodeDocID(test.Input)
38 if result != test.Expected {
39 t.Errorf("Unexpected encoded DocID from %s\n\tExpected: %s\n\t Actual: %s\n", test.Input, test.Expected, result)
40 }
41 }
42 }
43
View as plain text