test.js 924 B

123456789101112131415161718192021222324252627
  1. var assert = require('better-assert');
  2. var expect = require('expect.js');
  3. var util = require('./index.js');
  4. describe('querystring test suite', function(){
  5. it('should parse a querystring and return an object', function () {
  6. // Single assignment
  7. var queryObj = util.decode("foo=bar");
  8. expect(queryObj.foo).to.be("bar");
  9. // Multiple assignments
  10. queryObj = util.decode("france=paris&germany=berlin");
  11. expect(queryObj.france).to.be("paris");
  12. expect(queryObj.germany).to.be("berlin");
  13. // Assignments containing non-alphanumeric characters
  14. queryObj = util.decode("india=new%20delhi");
  15. expect(queryObj.india).to.be("new delhi");
  16. });
  17. it('should construct a query string from an object', function () {
  18. expect(util.encode({ a: 'b' })).to.be('a=b');
  19. expect(util.encode({ a: 'b', c: 'd' })).to.be('a=b&c=d');
  20. expect(util.encode({ a: 'b', c: 'tobi rocks' })).to.be('a=b&c=tobi%20rocks');
  21. });
  22. });