Skip to content

Commit

Permalink
add failing tests for arrayFormat for parse
Browse files Browse the repository at this point in the history
  • Loading branch information
dreyks committed Sep 8, 2019
1 parent befc9d6 commit 136b204
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,31 @@ test('parse()', function (t) {

t.test('arrayFormat: brackets allows only explicit arrays', function (st) {
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'brackets' }), { 'a[0]': 'b', 'a[1]': 'c' });
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'brackets' }), { a: 'b,c' });
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'brackets' }), { a: 'c' });
st.end();
});

t.test('arrayFormat: indices allows only indexed arrays', function (st) {
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'indices' }), { 'a[]': 'c' });
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'indices' }), { a: 'b,c' });
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'indices' }), { a: 'c' });
st.end();
});

t.test('arrayFormat: comma allows only comma-separated arrays', function (st) {
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'comma' }), { 'a[]': 'c' });
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'comma' }), { 'a[0]': 'b', 'a[1]': 'c' });
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'comma' }), { a: 'c' });
st.end();
});

t.test('arrayFormat: repeat allows only repeated values', function (st) {
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'repeat' }), { 'a[]': 'c' });
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'repeat' }), { 'a[0]': 'b', 'a[1]': 'c' });
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'repeat' }), { a: 'b,c' });
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
st.end();
Expand Down

0 comments on commit 136b204

Please sign in to comment.