summaryrefslogtreecommitdiffstats
path: root/emacs.d/lisp/jshint-mode/node_modules/formidable/test/integration
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-04-25 00:13:37 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2012-04-25 00:23:26 +0200
commitfdc1028cfd9e6563dbbe950cdd539559ce8d6353 (patch)
tree4b0ae3791baf59e94767dca01c71fd9828a69798 /emacs.d/lisp/jshint-mode/node_modules/formidable/test/integration
parent452a858fe4d70ec3521687dcbd1a8270f51b6f37 (diff)
downloaddotfiles-fdc1028cfd9e6563dbbe950cdd539559ce8d6353.tar.gz
dotfiles-fdc1028cfd9e6563dbbe950cdd539559ce8d6353.tar.xz
dotfiles-fdc1028cfd9e6563dbbe950cdd539559ce8d6353.zip
emacs: added some additional modes
Diffstat (limited to 'emacs.d/lisp/jshint-mode/node_modules/formidable/test/integration')
-rw-r--r--emacs.d/lisp/jshint-mode/node_modules/formidable/test/integration/test-multipart-parser.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/emacs.d/lisp/jshint-mode/node_modules/formidable/test/integration/test-multipart-parser.js b/emacs.d/lisp/jshint-mode/node_modules/formidable/test/integration/test-multipart-parser.js
new file mode 100644
index 0000000..df93bc7
--- /dev/null
+++ b/emacs.d/lisp/jshint-mode/node_modules/formidable/test/integration/test-multipart-parser.js
@@ -0,0 +1,80 @@
+var common = require('../common');
+var CHUNK_LENGTH = 10,
+ multipartParser = require(common.lib + '/multipart_parser'),
+ MultipartParser = multipartParser.MultipartParser,
+ parser = new MultipartParser(),
+ fixtures = require('../fixture/multipart'),
+ Buffer = require('buffer').Buffer;
+
+Object.keys(fixtures).forEach(function(name) {
+ var fixture = fixtures[name],
+ buffer = new Buffer(Buffer.byteLength(fixture.raw, 'binary')),
+ offset = 0,
+ chunk,
+ nparsed,
+
+ parts = [],
+ part = null,
+ headerField,
+ headerValue,
+ endCalled = '';
+
+ parser.initWithBoundary(fixture.boundary);
+ parser.onPartBegin = function() {
+ part = {headers: {}, data: ''};
+ parts.push(part);
+ headerField = '';
+ headerValue = '';
+ };
+
+ parser.onHeaderField = function(b, start, end) {
+ headerField += b.toString('ascii', start, end);
+ };
+
+ parser.onHeaderValue = function(b, start, end) {
+ headerValue += b.toString('ascii', start, end);
+ }
+
+ parser.onHeaderEnd = function() {
+ part.headers[headerField] = headerValue;
+ headerField = '';
+ headerValue = '';
+ };
+
+ parser.onPartData = function(b, start, end) {
+ var str = b.toString('ascii', start, end);
+ part.data += b.slice(start, end);
+ }
+
+ parser.onEnd = function() {
+ endCalled = true;
+ }
+
+ buffer.write(fixture.raw, 'binary', 0);
+
+ while (offset < buffer.length) {
+ if (offset + CHUNK_LENGTH < buffer.length) {
+ chunk = buffer.slice(offset, offset+CHUNK_LENGTH);
+ } else {
+ chunk = buffer.slice(offset, buffer.length);
+ }
+ offset = offset + CHUNK_LENGTH;
+
+ nparsed = parser.write(chunk);
+ if (nparsed != chunk.length) {
+ if (fixture.expectError) {
+ return;
+ }
+ puts('-- ERROR --');
+ p(chunk.toString('ascii'));
+ throw new Error(chunk.length+' bytes written, but only '+nparsed+' bytes parsed!');
+ }
+ }
+
+ if (fixture.expectError) {
+ throw new Error('expected parse error did not happen');
+ }
+
+ assert.ok(endCalled);
+ assert.deepEqual(parts, fixture.parts);
+});