Skip to content

Commit 4751fc0

Browse files
dreyksljharb
authored andcommitted
[Tests] parse: add passing arrayFormat tests
1 parent df0cb44 commit 4751fc0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/parse.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ test('parse()', function (t) {
3232
st.end();
3333
});
3434

35+
t.test('arrayFormat: brackets allows only explicit arrays', function (st) {
36+
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
37+
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'brackets' }), { a: 'b,c' });
38+
st.end();
39+
});
40+
41+
t.test('arrayFormat: indices allows only indexed arrays', function (st) {
42+
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
43+
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'indices' }), { a: 'b,c' });
44+
st.end();
45+
});
46+
47+
t.test('arrayFormat: repeat allows only repeated values', function (st) {
48+
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'repeat' }), { a: 'b,c' });
49+
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
50+
st.end();
51+
});
52+
3553
t.test('allows enabling dot notation', function (st) {
3654
st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' });
3755
st.deepEqual(qs.parse('a.b=c', { allowDots: true }), { a: { b: 'c' } });

0 commit comments

Comments
 (0)