]> git.cworth.org Git - obsolete/notmuch-web/blob - node_modules/express/node_modules/qs/test/querystring.test.js
Install the "express" node module via npm
[obsolete/notmuch-web] / node_modules / express / node_modules / qs / test / querystring.test.js
1
2 /**
3  * Module dependencies.
4  */
5
6 var qs = require('../')
7   , should = require('should');
8
9 module.exports = {
10   'test basics': function(){
11     qs.parse('0=foo').should.eql({ '0': 'foo' });
12
13     qs.parse('foo=c++')
14       .should.eql({ foo: 'c  ' });
15
16     qs.parse('a[>=]=23')
17       .should.eql({ a: { '>=': '23' }});
18
19     qs.parse('a[<=>]==23')
20       .should.eql({ a: { '<=>': '=23' }});
21
22     qs.parse('a[==]=23')
23       .should.eql({ a: { '==': '23' }});
24
25     qs.parse('foo')
26       .should.eql({ foo: '' });
27
28     qs.parse('foo=bar')
29       .should.eql({ foo: 'bar' });
30
31     qs.parse('foo%3Dbar=baz')
32       .should.eql({ foo: 'bar=baz' });
33
34     qs.parse(' foo = bar = baz ')
35       .should.eql({ ' foo ': ' bar = baz ' });
36
37     qs.parse('foo=bar=baz')
38       .should.eql({ foo: 'bar=baz' });
39
40     qs.parse('foo=bar&bar=baz')
41       .should.eql({ foo: 'bar', bar: 'baz' });
42
43     qs.parse('foo=bar&baz')
44       .should.eql({ foo: 'bar', baz: '' });
45
46     qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World')
47       .should.eql({
48           cht: 'p3'
49         , chd: 't:60,40'
50         , chs: '250x100'
51         , chl: 'Hello|World'
52       });
53   },
54   
55   'test nesting': function(){
56     qs.parse('ops[>=]=25')
57       .should.eql({ ops: { '>=': '25' }});
58
59     qs.parse('user[name]=tj')
60       .should.eql({ user: { name: 'tj' }});
61
62     qs.parse('user[name][first]=tj&user[name][last]=holowaychuk')
63       .should.eql({ user: { name: { first: 'tj', last: 'holowaychuk' }}});
64   },
65   
66   'test escaping': function(){
67     qs.parse('foo=foo%20bar')
68       .should.eql({ foo: 'foo bar' });
69   },
70   
71   'test arrays': function(){
72     qs.parse('images[]')
73       .should.eql({ images: [] });
74
75     qs.parse('user[]=tj')
76       .should.eql({ user: ['tj'] });
77
78     qs.parse('user[]=tj&user[]=tobi&user[]=jane')
79       .should.eql({ user: ['tj', 'tobi', 'jane'] });
80
81     qs.parse('user[names][]=tj&user[names][]=tyler')
82       .should.eql({ user: { names: ['tj', 'tyler'] }});
83
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' }});
86
87     qs.parse('items=a&items=b')
88       .should.eql({ items: ['a', 'b'] });
89
90     qs.parse('user[names]=tj&user[names]=holowaychuk&user[names]=TJ')
91       .should.eql({ user: { names: ['tj', 'holowaychuk', 'TJ'] }});
92
93     qs.parse('user[name][first]=tj&user[name][first]=TJ')
94       .should.eql({ user: { name: { first: ['tj', 'TJ'] }}});
95   },
96   
97   'test right-hand brackets': function(){
98     qs.parse('pets=["tobi"]')
99       .should.eql({ pets: '["tobi"]' });
100
101     qs.parse('operators=[">=", "<="]')
102       .should.eql({ operators: '[">=", "<="]' });
103
104     qs.parse('op[>=]=[1,2,3]')
105       .should.eql({ op: { '>=': '[1,2,3]' }});
106
107     qs.parse('op[>=]=[1,2,3]&op[=]=[[[[1]]]]')
108           .should.eql({ op: { '>=': '[1,2,3]', '=': '[[[[1]]]]' }});
109   },
110   
111   'test duplicates': function(){
112     qs.parse('items=bar&items=baz&items=raz')
113       .should.eql({ items: ['bar', 'baz', 'raz'] });
114   },
115
116   'test empty': function(){
117     qs.parse('').should.eql({});
118     qs.parse(undefined).should.eql({});
119     qs.parse(null).should.eql({});
120   }
121   
122   // 'test complex': function(){
123   //   qs.parse('users[][name][first]=tj&users[foo]=bar')
124   //     .should.eql({
125   //       users: [ { name: 'tj' }, { name: 'tobi' }, { foo: 'bar' }]
126   //     });
127   // 
128   //   qs.parse('users[][name][first]=tj&users[][name][first]=tobi')
129   //     .should.eql({
130   //       users: [ { name: 'tj' }, { name: 'tobi' }]
131   //     });
132   // }
133 };