summaryrefslogtreecommitdiffstats
path: root/emacs.d/lisp/jshint-mode/node_modules/formidable/test/simple/test-querystring-parser.js
blob: 54d3e2d55d9c3a27c6c615c1a9a41ca9935864ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var common = require('../common');
var QuerystringParser = require(common.lib + '/querystring_parser').QuerystringParser,
    Buffer = require('buffer').Buffer,
    gently,
    parser;

function test(test) {
  gently = new Gently();
  parser = new QuerystringParser();
  test();
  gently.verify(test.name);
}

test(function constructor() {
  assert.equal(parser.buffer, '');
  assert.equal(parser.constructor.name, 'QuerystringParser');
});

test(function write() {
  var a = new Buffer('a=1');
  assert.equal(parser.write(a), a.length);

  var b = new Buffer('&b=2');
  parser.write(b);
  assert.equal(parser.buffer, a + b);
});

test(function end() {
  var FIELDS = {a: ['b', {c: 'd'}], e: 'f'};

  gently.expect(GENTLY.hijacked.querystring, 'parse', function(str) {
    assert.equal(str, parser.buffer);
    return FIELDS;
  });

  gently.expect(parser, 'onField', Object.keys(FIELDS).length, function(key, val) {
    assert.deepEqual(FIELDS[key], val);
  });

  gently.expect(parser, 'onEnd');

  parser.buffer = 'my buffer';
  parser.end();
  assert.equal(parser.buffer, '');
});