You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
951 B

7 years ago
  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. });