-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse_test.go
More file actions
93 lines (89 loc) · 2.54 KB
/
Copy pathparse_test.go
File metadata and controls
93 lines (89 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package goqs
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDecodeQueryFormats(t *testing.T) {
tests := []struct {
name string
query string
expected map[string]interface{}
}{
{
name: "Empty query",
query: "",
expected: map[string]interface{}{},
},
{
name: "Simple string parameter",
query: "name=John",
expected: map[string]interface{}{"name": "John"},
},
{
name: "Multiple parameters",
query: "a=1&b=hello&c=true",
expected: map[string]interface{}{"a": "1", "b": "hello", "c": "true"},
},
{
name: "Array parameters",
query: "arr[]=1&arr[]=2",
expected: map[string]interface{}{"arr": []interface{}{"1", "2"}},
},
{
name: "Nested object parameters",
query: "user[name]=Alice&user[age]=30",
expected: map[string]interface{}{"user": map[string]interface{}{"name": "Alice", "age": "30"}},
},
{
name: "Numeric index parameters",
query: "a[1]=1&a[2]=2&a[3]=3",
expected: map[string]interface{}{"a": []interface{}{"1", "2", "3"}},
},
{
name: "Numeric index parameters with empty indexes",
query: "a[]=1&a[]=2&a[]=3",
expected: map[string]interface{}{"a": []interface{}{"1", "2", "3"}},
},
{
name: "Numeric index parameters with some empty index",
query: "a[0]=1&a[1]=2&a[]=3",
expected: map[string]interface{}{"a": []interface{}{"1", "2", "3"}},
},
{
name: "Empty value parameter",
query: "empty=",
expected: map[string]interface{}{"empty": ""},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res, err := Parse(tt.query, &ParseOptions{
AllowDots: false,
AllowEmptyArrays: false,
AllowPrototypes: false,
ParseNumbers: false,
AllowSparse: false,
ArrayLimit: 20,
Charset: "utf-8",
CharsetSentinel: false,
Comma: false,
DecodeDotInKeys: false,
Decoder: nil,
Delimiter: "&",
Depth: 10,
Duplicates: "combine",
IgnoreQueryPrefix: false,
InterpretNumericEntities: false,
ParameterLimit: 1000,
ParseArrays: true,
PlainObjects: false,
StrictDepth: false,
StrictNullHandling: true,
AllowNilArrayValues: false,
ThrowOnLimitExceeded: false,
})
assert.NoError(t, err)
assert.Equal(t, tt.expected, res)
})
}
}