6 var qs = require('../')
7 , should = require('should');
10 'test basics': function(){
11 qs.parse('0=foo').should.eql({ '0': 'foo' });
14 .should.eql({ foo: 'c ' });
17 .should.eql({ a: { '>=': '23' }});
19 qs.parse('a[<=>]==23')
20 .should.eql({ a: { '<=>': '=23' }});
23 .should.eql({ a: { '==': '23' }});
26 .should.eql({ foo: '' });
29 .should.eql({ foo: 'bar' });
31 qs.parse('foo%3Dbar=baz')
32 .should.eql({ foo: 'bar=baz' });
34 qs.parse(' foo = bar = baz ')
35 .should.eql({ ' foo ': ' bar = baz ' });
37 qs.parse('foo=bar=baz')
38 .should.eql({ foo: 'bar=baz' });
40 qs.parse('foo=bar&bar=baz')
41 .should.eql({ foo: 'bar', bar: 'baz' });
43 qs.parse('foo=bar&baz')
44 .should.eql({ foo: 'bar', baz: '' });
46 qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World')
55 'test nesting': function(){
56 qs.parse('ops[>=]=25')
57 .should.eql({ ops: { '>=': '25' }});
59 qs.parse('user[name]=tj')
60 .should.eql({ user: { name: 'tj' }});
62 qs.parse('user[name][first]=tj&user[name][last]=holowaychuk')
63 .should.eql({ user: { name: { first: 'tj', last: 'holowaychuk' }}});
66 'test escaping': function(){
67 qs.parse('foo=foo%20bar')
68 .should.eql({ foo: 'foo bar' });
71 'test arrays': function(){
73 .should.eql({ images: [] });
76 .should.eql({ user: ['tj'] });
78 qs.parse('user[]=tj&user[]=tobi&user[]=jane')
79 .should.eql({ user: ['tj', 'tobi', 'jane'] });
81 qs.parse('user[names][]=tj&user[names][]=tyler')
82 .should.eql({ user: { names: ['tj', 'tyler'] }});
84 qs.parse('user[names][]=tj&user[names][]=tyler&user[email]=tj@vision-media.ca')
85 .should.eql({ user: { names: ['tj', 'tyler'], email: 'tj@vision-media.ca' }});
87 qs.parse('items=a&items=b')
88 .should.eql({ items: ['a', 'b'] });
90 qs.parse('user[names]=tj&user[names]=holowaychuk&user[names]=TJ')
91 .should.eql({ user: { names: ['tj', 'holowaychuk', 'TJ'] }});
93 qs.parse('user[name][first]=tj&user[name][first]=TJ')
94 .should.eql({ user: { name: { first: ['tj', 'TJ'] }}});
97 'test right-hand brackets': function(){
98 qs.parse('pets=["tobi"]')
99 .should.eql({ pets: '["tobi"]' });
101 qs.parse('operators=[">=", "<="]')
102 .should.eql({ operators: '[">=", "<="]' });
104 qs.parse('op[>=]=[1,2,3]')
105 .should.eql({ op: { '>=': '[1,2,3]' }});
107 qs.parse('op[>=]=[1,2,3]&op[=]=[[[[1]]]]')
108 .should.eql({ op: { '>=': '[1,2,3]', '=': '[[[[1]]]]' }});
111 'test duplicates': function(){
112 qs.parse('items=bar&items=baz&items=raz')
113 .should.eql({ items: ['bar', 'baz', 'raz'] });
116 'test empty': function(){
117 qs.parse('').should.eql({});
118 qs.parse(undefined).should.eql({});
119 qs.parse(null).should.eql({});
122 // 'test complex': function(){
123 // qs.parse('users[][name][first]=tj&users[foo]=bar')
125 // users: [ { name: 'tj' }, { name: 'tobi' }, { foo: 'bar' }]
128 // qs.parse('users[][name][first]=tj&users[][name][first]=tobi')
130 // users: [ { name: 'tj' }, { name: 'tobi' }]