Permalink
Browse files

use expect.js

  • Loading branch information...
1 parent 1e5ce17 commit d2c68e5a03bca1031222714db5d78704d23e6ca4 @tj committed Feb 29, 2012
Showing with 75 additions and 74 deletions.
  1. +1 −1 package.json
  2. +74 −73 test/parse.js
View
@@ -8,7 +8,7 @@
},
"devDependencies": {
"mocha": "*"
- , "should": "*"
+ , "expect.js": "*"
},
"author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
"main": "index",
View
@@ -1,45 +1,46 @@
-var qs = require('../');
+var qs = require('../')
+ , expect = require('expect.js');
describe('qs.parse()', function(){
it('should support the basics', function(){
- qs.parse('0=foo').should.eql({ '0': 'foo' });
+ expect(qs.parse('0=foo')).to.eql({ '0': 'foo' });
- qs.parse('foo=c++')
- .should.eql({ foo: 'c ' });
+ expect(qs.parse('foo=c++'))
+ .to.eql({ foo: 'c ' });
- qs.parse('a[>=]=23')
- .should.eql({ a: { '>=': '23' }});
+ expect(qs.parse('a[>=]=23'))
+ .to.eql({ a: { '>=': '23' }});
- qs.parse('a[<=>]==23')
- .should.eql({ a: { '<=>': '=23' }});
+ expect(qs.parse('a[<=>]==23'))
+ .to.eql({ a: { '<=>': '=23' }});
- qs.parse('a[==]=23')
- .should.eql({ a: { '==': '23' }});
+ expect(qs.parse('a[==]=23'))
+ .to.eql({ a: { '==': '23' }});
- qs.parse('foo')
- .should.eql({ foo: '' });
+ expect(qs.parse('foo'))
+ .to.eql({ foo: '' });
- qs.parse('foo=bar')
- .should.eql({ foo: 'bar' });
+ expect(qs.parse('foo=bar'))
+ .to.eql({ foo: 'bar' });
- qs.parse('foo%3Dbar=baz')
- .should.eql({ foo: 'bar=baz' });
+ expect(qs.parse('foo%3Dbar=baz'))
+ .to.eql({ foo: 'bar=baz' });
- qs.parse(' foo = bar = baz ')
- .should.eql({ ' foo ': ' bar = baz ' });
+ expect(qs.parse(' foo = bar = baz '))
+ .to.eql({ ' foo ': ' bar = baz ' });
- qs.parse('foo=bar=baz')
- .should.eql({ foo: 'bar=baz' });
+ expect(qs.parse('foo=bar=baz'))
+ .to.eql({ foo: 'bar=baz' });
- qs.parse('foo=bar&bar=baz')
- .should.eql({ foo: 'bar', bar: 'baz' });
+ expect(qs.parse('foo=bar&bar=baz'))
+ .to.eql({ foo: 'bar', bar: 'baz' });
- qs.parse('foo=bar&baz')
- .should.eql({ foo: 'bar', baz: '' });
+ expect(qs.parse('foo=bar&baz'))
+ .to.eql({ foo: 'bar', baz: '' });
- qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World')
- .should.eql({
+ expect(qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World'))
+ .to.eql({
cht: 'p3'
, chd: 't:60,40'
, chs: '250x100'
@@ -48,93 +49,93 @@ describe('qs.parse()', function(){
})
it('should support nesting', function(){
- qs.parse('ops[>=]=25')
- .should.eql({ ops: { '>=': '25' }});
+ expect(qs.parse('ops[>=]=25'))
+ .to.eql({ ops: { '>=': '25' }});
- qs.parse('user[name]=tj')
- .should.eql({ user: { name: 'tj' }});
+ expect(qs.parse('user[name]=tj'))
+ .to.eql({ user: { name: 'tj' }});
- qs.parse('user[name][first]=tj&user[name][last]=holowaychuk')
- .should.eql({ user: { name: { first: 'tj', last: 'holowaychuk' }}});
+ expect(qs.parse('user[name][first]=tj&user[name][last]=holowaychuk'))
+ .to.eql({ user: { name: { first: 'tj', last: 'holowaychuk' }}});
})
it('should support array notation', function(){
- qs.parse('images[]')
- .should.eql({ images: [] });
+ expect(qs.parse('images[]'))
+ .to.eql({ images: [] });
- qs.parse('user[]=tj')
- .should.eql({ user: ['tj'] });
+ expect(qs.parse('user[]=tj'))
+ .to.eql({ user: ['tj'] });
- qs.parse('user[]=tj&user[]=tobi&user[]=jane')
- .should.eql({ user: ['tj', 'tobi', 'jane'] });
+ expect(qs.parse('user[]=tj&user[]=tobi&user[]=jane'))
+ .to.eql({ user: ['tj', 'tobi', 'jane'] });
- qs.parse('user[names][]=tj&user[names][]=tyler')
- .should.eql({ user: { names: ['tj', 'tyler'] }});
+ expect(qs.parse('user[names][]=tj&user[names][]=tyler'))
+ .to.eql({ user: { names: ['tj', 'tyler'] }});
- qs.parse('user[names][]=tj&user[names][]=tyler&user[email]=tj@vision-media.ca')
- .should.eql({ user: { names: ['tj', 'tyler'], email: 'tj@vision-media.ca' }});
+ expect(qs.parse('user[names][]=tj&user[names][]=tyler&user[email]=tj@vision-media.ca'))
+ .to.eql({ user: { names: ['tj', 'tyler'], email: 'tj@vision-media.ca' }});
- qs.parse('items=a&items=b')
- .should.eql({ items: ['a', 'b'] });
+ expect(qs.parse('items=a&items=b'))
+ .to.eql({ items: ['a', 'b'] });
- qs.parse('user[names]=tj&user[names]=holowaychuk&user[names]=TJ')
- .should.eql({ user: { names: ['tj', 'holowaychuk', 'TJ'] }});
+ expect(qs.parse('user[names]=tj&user[names]=holowaychuk&user[names]=TJ'))
+ .to.eql({ user: { names: ['tj', 'holowaychuk', 'TJ'] }});
- qs.parse('user[name][first]=tj&user[name][first]=TJ')
- .should.eql({ user: { name: { first: ['tj', 'TJ'] }}});
+ expect(qs.parse('user[name][first]=tj&user[name][first]=TJ'))
+ .to.eql({ user: { name: { first: ['tj', 'TJ'] }}});
var o = qs.parse('existing[fcbaebfecc][name][last]=tj')
o.should.eql({ existing: { 'fcbaebfecc': { name: { last: 'tj' }}}})
Array.isArray(o.existing).should.be.false;
})
it('should support arrays with indexes', function(){
- qs.parse('foo[0]=bar&foo[1]=baz').should.eql({ foo: ['bar', 'baz'] });
- qs.parse('foo[1]=bar&foo[0]=baz').should.eql({ foo: ['baz', 'bar'] });
- qs.parse('foo[base64]=RAWR').should.eql({ foo: { base64: 'RAWR' }});
- qs.parse('foo[64base]=RAWR').should.eql({ foo: { '64base': 'RAWR' }});
+ expect(qs.parse('foo[0]=bar&foo[1]=baz')).to.eql({ foo: ['bar', 'baz'] });
+ expect(qs.parse('foo[1]=bar&foo[0]=baz')).to.eql({ foo: ['baz', 'bar'] });
+ expect(qs.parse('foo[base64]=RAWR')).to.eql({ foo: { base64: 'RAWR' }});
+ expect(qs.parse('foo[64base]=RAWR')).to.eql({ foo: { '64base': 'RAWR' }});
})
it('should expand to an array when dupliate keys are present', function(){
- qs.parse('items=bar&items=baz&items=raz')
- .should.eql({ items: ['bar', 'baz', 'raz'] });
+ expect(qs.parse('items=bar&items=baz&items=raz'))
+ .to.eql({ items: ['bar', 'baz', 'raz'] });
})
it('should support right-hand side brackets', function(){
- qs.parse('pets=["tobi"]')
- .should.eql({ pets: '["tobi"]' });
+ expect(qs.parse('pets=["tobi"]'))
+ .to.eql({ pets: '["tobi"]' });
- qs.parse('operators=[">=", "<="]')
- .should.eql({ operators: '[">=", "<="]' });
+ expect(qs.parse('operators=[">=", "<="]'))
+ .to.eql({ operators: '[">=", "<="]' });
- qs.parse('op[>=]=[1,2,3]')
- .should.eql({ op: { '>=': '[1,2,3]' }});
+ expect(qs.parse('op[>=]=[1,2,3]'))
+ .to.eql({ op: { '>=': '[1,2,3]' }});
- qs.parse('op[>=]=[1,2,3]&op[=]=[[[[1]]]]')
- .should.eql({ op: { '>=': '[1,2,3]', '=': '[[[[1]]]]' }});
+ expect(qs.parse('op[>=]=[1,2,3]&op[=]=[[[[1]]]]'))
+ .to.eql({ op: { '>=': '[1,2,3]', '=': '[[[[1]]]]' }});
})
it('should support empty values', function(){
- qs.parse('').should.eql({});
- qs.parse(undefined).should.eql({});
- qs.parse(null).should.eql({});
+ expect(qs.parse('')).to.eql({});
+ expect(qs.parse(undefined)).to.eql({});
+ expect(qs.parse(null)).to.eql({});
})
it('should transform arrays to objects', function(){
- qs.parse('foo[0]=bar&foo[bad]=baz').should.eql({ foo: { 0: "bar", bad: "baz" }});
- qs.parse('foo[bad]=baz&foo[0]=bar').should.eql({ foo: { 0: "bar", bad: "baz" }});
+ expect(qs.parse('foo[0]=bar&foo[bad]=baz')).to.eql({ foo: { 0: "bar", bad: "baz" }});
+ expect(qs.parse('foo[bad]=baz&foo[0]=bar')).to.eql({ foo: { 0: "bar", bad: "baz" }});
})
it('should support malformed uri chars', function(){
- qs.parse('{%:%}').should.eql({ '{%:%}': '' });
- qs.parse('foo=%:%}').should.eql({ 'foo': '%:%}' });
+ expect(qs.parse('{%:%}')).to.eql({ '{%:%}': '' });
+ expect(qs.parse('foo=%:%}')).to.eql({ 'foo': '%:%}' });
})
it('should support semi-parsed strings', function(){
- qs.parse({ 'user[name]': 'tobi' })
- .should.eql({ user: { name: 'tobi' }});
+ expect(qs.parse({ 'user[name]': 'tobi' }))
+ .to.eql({ user: { name: 'tobi' }});
- qs.parse({ 'user[name]': 'tobi', 'user[email][main]': 'tobi@lb.com' })
- .should.eql({ user: { name: 'tobi', email: { main: 'tobi@lb.com' } }});
+ expect(qs.parse({ 'user[name]': 'tobi', 'user[email][main]': 'tobi@lb.com' }))
+ .to.eql({ user: { name: 'tobi', email: { main: 'tobi@lb.com' } }});
})
})

0 comments on commit d2c68e5

Please sign in to comment.