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.

45 lines
1.1 KiB

  1. var common = require('../common');
  2. var QuerystringParser = require(common.lib + '/querystring_parser').QuerystringParser,
  3. Buffer = require('buffer').Buffer,
  4. gently,
  5. parser;
  6. function test(test) {
  7. gently = new Gently();
  8. parser = new QuerystringParser();
  9. test();
  10. gently.verify(test.name);
  11. }
  12. test(function constructor() {
  13. assert.equal(parser.buffer, '');
  14. assert.equal(parser.constructor.name, 'QuerystringParser');
  15. });
  16. test(function write() {
  17. var a = new Buffer('a=1');
  18. assert.equal(parser.write(a), a.length);
  19. var b = new Buffer('&b=2');
  20. parser.write(b);
  21. assert.equal(parser.buffer, a + b);
  22. });
  23. test(function end() {
  24. var FIELDS = {a: ['b', {c: 'd'}], e: 'f'};
  25. gently.expect(GENTLY.hijacked.querystring, 'parse', function(str) {
  26. assert.equal(str, parser.buffer);
  27. return FIELDS;
  28. });
  29. gently.expect(parser, 'onField', Object.keys(FIELDS).length, function(key, val) {
  30. assert.deepEqual(FIELDS[key], val);
  31. });
  32. gently.expect(parser, 'onEnd');
  33. parser.buffer = 'my buffer';
  34. parser.end();
  35. assert.equal(parser.buffer, '');
  36. });