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.

50 lines
1.5 KiB

  1. var common = require('../common');
  2. var multipartParser = require(common.lib + '/multipart_parser'),
  3. MultipartParser = multipartParser.MultipartParser,
  4. events = require('events'),
  5. Buffer = require('buffer').Buffer,
  6. parser;
  7. function test(test) {
  8. parser = new MultipartParser();
  9. test();
  10. }
  11. test(function constructor() {
  12. assert.equal(parser.boundary, null);
  13. assert.equal(parser.state, 0);
  14. assert.equal(parser.flags, 0);
  15. assert.equal(parser.boundaryChars, null);
  16. assert.equal(parser.index, null);
  17. assert.equal(parser.lookbehind, null);
  18. assert.equal(parser.constructor.name, 'MultipartParser');
  19. });
  20. test(function initWithBoundary() {
  21. var boundary = 'abc';
  22. parser.initWithBoundary(boundary);
  23. assert.deepEqual(Array.prototype.slice.call(parser.boundary), [13, 10, 45, 45, 97, 98, 99]);
  24. assert.equal(parser.state, multipartParser.START);
  25. assert.deepEqual(parser.boundaryChars, {10: true, 13: true, 45: true, 97: true, 98: true, 99: true});
  26. });
  27. test(function parserError() {
  28. var boundary = 'abc',
  29. buffer = new Buffer(5);
  30. parser.initWithBoundary(boundary);
  31. buffer.write('--ad', 'ascii', 0);
  32. assert.equal(parser.write(buffer), 5);
  33. });
  34. test(function end() {
  35. (function testError() {
  36. assert.equal(parser.end().message, 'MultipartParser.end(): stream ended unexpectedly: ' + parser.explain());
  37. })();
  38. (function testRegular() {
  39. parser.state = multipartParser.END;
  40. assert.strictEqual(parser.end(), undefined);
  41. })();
  42. });