Browse Source

Tests: fix jslint issues

v0.7.4-release
Andreas Madsen 13 years ago
committed by Bert Belder
parent
commit
4865063924
  1. 4
      test/internet/test-dns.js
  2. 2
      test/message/throw_custom_error.js
  3. 2
      test/message/throw_non_error.js
  4. 14
      test/pummel/test-net-timeout2.js
  5. 2
      test/simple/test-assert.js
  6. 6
      test/simple/test-child-process-fork2.js
  7. 18
      test/simple/test-cluster-kill-workers.js
  8. 9
      test/simple/test-crypto-ecb.js
  9. 4
      test/simple/test-eval.js
  10. 6
      test/simple/test-fs-long-path.js
  11. 2
      test/simple/test-fs-mkdir.js
  12. 10
      test/simple/test-fs-symlink.js
  13. 10
      test/simple/test-fs-utimes.js
  14. 2
      test/simple/test-http-abort-before-end.js
  15. 6
      test/simple/test-http-res-write-end-dont-take-array.js
  16. 9
      test/simple/test-http-response-no-headers.js
  17. 15
      test/simple/test-init.js
  18. 13
      test/simple/test-module-load-list.js
  19. 2
      test/simple/test-net-connect-buffer.js
  20. 26
      test/simple/test-net-pipe-connect-errors.js
  21. 10
      test/simple/test-path.js
  22. 81
      test/simple/test-punycode.js
  23. 2
      test/simple/test-readdir.js
  24. 10
      test/simple/test-regress-GH-1899.js
  25. 15
      test/simple/test-regress-GH-877.js
  26. 23
      test/simple/test-repl-.save.load.js
  27. 4
      test/simple/test-setproctitle.js
  28. 12
      test/simple/test-stdin-pause-resume.js
  29. 2
      test/simple/test-tls-passphrase.js
  30. 6
      test/simple/test-tls-session-cache.js
  31. 3
      test/simple/test-tls-set-ciphers.js
  32. 2
      test/simple/test-tty-stdout-end.js
  33. 6
      test/simple/test-util-inspect.js
  34. 74
      test/simple/test-util.js
  35. 2
      test/simple/test-zlib-from-gzip.js
  36. 35
      test/simple/test-zlib-from-string.js
  37. 14
      test/simple/test-zlib-random-byte-pipes.js

4
test/internet/test-dns.js

@ -383,11 +383,11 @@ TEST(function test_lookup_localhost_ipv4(done) {
var getaddrinfoCallbackCalled = false; var getaddrinfoCallbackCalled = false;
console.log("looking up nodejs.org..."); console.log('looking up nodejs.org...');
var req = process.binding('cares_wrap').getaddrinfo('nodejs.org'); var req = process.binding('cares_wrap').getaddrinfo('nodejs.org');
req.oncomplete = function(domains) { req.oncomplete = function(domains) {
console.log("nodejs.org = ", domains); console.log('nodejs.org = ', domains);
assert.ok(Array.isArray(domains)); assert.ok(Array.isArray(domains));
assert.ok(domains.length >= 1); assert.ok(domains.length >= 1);
assert.ok(typeof domains[0] == 'string'); assert.ok(typeof domains[0] == 'string');

2
test/message/throw_custom_error.js

@ -28,6 +28,6 @@ var assert = require('assert');
common.error('before'); common.error('before');
// custom error throwing // custom error throwing
throw { name: 'MyCustomError', message: 'This is a custom message' } throw { name: 'MyCustomError', message: 'This is a custom message' };
common.error('after'); common.error('after');

2
test/message/throw_non_error.js

@ -28,6 +28,6 @@ var assert = require('assert');
common.error('before'); common.error('before');
// custom error throwing // custom error throwing
throw { foo: 'bar' } throw { foo: 'bar' };
common.error('after'); common.error('after');

14
test/pummel/test-net-timeout2.js

@ -32,12 +32,12 @@ var counter = 0;
var server = net.createServer(function(socket) { var server = net.createServer(function(socket) {
socket.setTimeout((seconds / 2) * 1000, function() { socket.setTimeout((seconds / 2) * 1000, function() {
gotTimeout = true; gotTimeout = true;
console.log('timeout!!'); console.log('timeout!!');
socket.destroy(); socket.destroy();
process.exit(1); process.exit(1);
}); });
var interval = setInterval(function() { var interval = setInterval(function() {
counter++; counter++;
if (counter == seconds) { if (counter == seconds) {
@ -46,9 +46,9 @@ var server = net.createServer(function(socket) {
socket.destroy(); socket.destroy();
} }
if (socket.writable) { if (socket.writable) {
socket.write(Date.now()+'\n'); socket.write(Date.now() + '\n');
} }
}, 1000); }, 1000);
}); });

2
test/simple/test-assert.js

@ -197,7 +197,7 @@ threw = false;
try { try {
assert.throws( assert.throws(
function() { function() {
throw {} throw {};
}, },
Array Array
); );

6
test/simple/test-child-process-fork2.js

@ -47,12 +47,12 @@ server.listen(common.PORT, function() {
function makeConnections() { function makeConnections() {
for (var i = 0; i < N; i++) { for (var i = 0; i < N; i++) {
var socket = net.connect(common.PORT, function() { var socket = net.connect(common.PORT, function() {
console.log("CLIENT connected"); console.log('CLIENT connected');
}); });
socket.on("close", function() { socket.on('close', function() {
socketCloses++; socketCloses++;
console.log("CLIENT closed " + socketCloses); console.log('CLIENT closed ' + socketCloses);
if (socketCloses == N) { if (socketCloses == N) {
n.kill(); n.kill();
server.close(); server.close();

18
test/simple/test-cluster-kill-workers.js

@ -32,17 +32,17 @@ var fork = require('child_process').fork;
var isTestRunner = process.argv[2] != 'child'; var isTestRunner = process.argv[2] != 'child';
if (isTestRunner) { if (isTestRunner) {
console.log("starting master..."); console.log('starting master...');
var master = fork(__filename, [ 'child' ]); var master = fork(__filename, ['child']);
console.log("master pid =", master.pid); console.log('master pid =', master.pid);
var workerPID; var workerPID;
master.on("message", function(m) { master.on('message', function(m) {
console.log("got message from master:", m); console.log('got message from master:', m);
if (m.workerPID) { if (m.workerPID) {
console.log("worker pid =", m.workerPID); console.log('worker pid =', m.workerPID);
workerPID = m.workerPID; workerPID = m.workerPID;
} }
}); });
@ -56,13 +56,13 @@ if (isTestRunner) {
assert(workerPID > 0); assert(workerPID > 0);
try { try {
process.kill(workerPID, 0); process.kill(workerPID, 0);
} catch(e) { } catch (e) {
// workerPID is no longer running // workerPID is no longer running
console.log(e) console.log(e);
assert(e.code == 'ESRCH'); assert(e.code == 'ESRCH');
gotKillException = true; gotKillException = true;
} }
}) });
process.on('exit', function() { process.on('exit', function() {
assert(gotExit); assert(gotExit);

9
test/simple/test-crypto-ecb.js

@ -35,17 +35,16 @@ try {
// Testing whether EVP_CipherInit_ex is functioning correctly. // Testing whether EVP_CipherInit_ex is functioning correctly.
// Reference: bug#1997 // Reference: bug#1997
(function() (function() {
{
var encrypt = crypto.createCipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR', ''); var encrypt = crypto.createCipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR', '');
var hex = encrypt.update('Hello World!', 'ascii', 'hex'); var hex = encrypt.update('Hello World!', 'ascii', 'hex');
hex += encrypt.final('hex'); hex += encrypt.final('hex');
assert.equal(hex.toUpperCase(), '6D385F424AAB0CFBF0BB86E07FFB7D71'); assert.equal(hex.toUpperCase(), '6D385F424AAB0CFBF0BB86E07FFB7D71');
}()); }());
(function() (function() {
{ var decrypt = crypto.createDecipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR',
var decrypt = crypto.createDecipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR', ''); '');
var msg = decrypt.update('6D385F424AAB0CFBF0BB86E07FFB7D71', 'hex', 'ascii'); var msg = decrypt.update('6D385F424AAB0CFBF0BB86E07FFB7D71', 'hex', 'ascii');
msg += decrypt.final('ascii'); msg += decrypt.final('ascii');
assert.equal(msg, 'Hello World!'); assert.equal(msg, 'Hello World!');

4
test/simple/test-eval.js

@ -30,8 +30,8 @@ var exec = require('child_process').exec;
var success_count = 0; var success_count = 0;
var error_count = 0; var error_count = 0;
var cmd = [process.execPath, '-e', '"console.error(process.argv)"', 'foo', 'bar'] var cmd = [process.execPath, '-e', '"console.error(process.argv)"',
.join(' '); 'foo', 'bar'].join(' ');
var expected = util.format([process.execPath, 'foo', 'bar']) + '\n'; var expected = util.format([process.execPath, 'foo', 'bar']) + '\n';
var child = exec(cmd, function(err, stdout, stderr) { var child = exec(cmd, function(err, stdout, stderr) {
if (err) { if (err) {

6
test/simple/test-fs-long-path.js

@ -31,8 +31,10 @@ var fileNameLen = Math.max(260 - common.tmpDir.length - 1, 1);
var fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x')); var fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x'));
var fullPath = path.resolve(fileName); var fullPath = path.resolve(fileName);
console.log({ filenameLength: fileName.length, console.log({
fullPathLength: fullPath.length }); filenameLength: fileName.length,
fullPathLength: fullPath.length
});
fs.writeFile(fullPath, 'ok', function(err) { fs.writeFile(fullPath, 'ok', function(err) {
if (err) throw err; if (err) throw err;

2
test/simple/test-fs-mkdir.js

@ -81,4 +81,4 @@ function unlink(pathname) {
// Keep the event loop alive so the async mkdir() requests // Keep the event loop alive so the async mkdir() requests
// have a chance to run (since they don't ref the event loop). // have a chance to run (since they don't ref the event loop).
process.nextTick(function(){}); process.nextTick(function() {});

10
test/simple/test-fs-symlink.js

@ -38,8 +38,7 @@ var runtest = function(skip_symlinks) {
// Delete previously created link // Delete previously created link
try { try {
fs.unlinkSync(linkPath); fs.unlinkSync(linkPath);
} catch(e) } catch (e) {}
{}
fs.symlink(linkData, linkPath, function(err) { fs.symlink(linkData, linkPath, function(err) {
if (err) throw err; if (err) throw err;
@ -60,8 +59,7 @@ var runtest = function(skip_symlinks) {
// Delete previously created link // Delete previously created link
try { try {
fs.unlinkSync(dstPath); fs.unlinkSync(dstPath);
} catch(e) } catch (e) {}
{}
fs.link(srcPath, dstPath, function(err) { fs.link(srcPath, dstPath, function(err) {
if (err) throw err; if (err) throw err;
@ -71,12 +69,12 @@ var runtest = function(skip_symlinks) {
assert.equal(srcContent, dstContent); assert.equal(srcContent, dstContent);
completed++; completed++;
}); });
} };
if (is_windows) { if (is_windows) {
// On Windows, creating symlinks requires admin privileges. // On Windows, creating symlinks requires admin privileges.
// We'll only try to run symlink test if we have enough privileges. // We'll only try to run symlink test if we have enough privileges.
exec("whoami /priv", function(err, o) { exec('whoami /priv', function(err, o) {
if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) { if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) {
expected_tests = 1; expected_tests = 1;
runtest(true); runtest(true);

10
test/simple/test-fs-utimes.js

@ -68,7 +68,7 @@ function expect_ok(syscall, resource, err, atime, mtime) {
// the tests assume that __filename belongs to the user running the tests // the tests assume that __filename belongs to the user running the tests
// this should be a fairly safe assumption; testing against a temp file // this should be a fairly safe assumption; testing against a temp file
// would be even better though (node doesn't have such functionality yet) // would be even better though (node doesn't have such functionality yet)
function runTests(atime, mtime, callback) { function runTest(atime, mtime, callback) {
var fd, err; var fd, err;
// //
@ -144,10 +144,10 @@ function runTests(atime, mtime, callback) {
var stats = fs.statSync(__filename); var stats = fs.statSync(__filename);
runTests(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() { runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() {
runTests(new Date(), new Date(), function() { runTest(new Date(), new Date(), function() {
runTests(123456.789, 123456.789, function() { runTest(123456.789, 123456.789, function() {
runTests(stats.mtime, stats.mtime, function() { runTest(stats.mtime, stats.mtime, function() {
// done // done
}); });
}); });

2
test/simple/test-http-abort-before-end.js

@ -28,7 +28,7 @@ var server = http.createServer(function(req, res) {
}); });
server.listen(common.PORT, function() { server.listen(common.PORT, function() {
var req = http.request({method:'GET', host:'127.0.0.1', port:common.PORT}); var req = http.request({method: 'GET', host: '127.0.0.1', port: common.PORT});
req.on('error', function(ex) { req.on('error', function(ex) {
// https://github.com/joyent/node/issues/1399#issuecomment-2597359 // https://github.com/joyent/node/issues/1399#issuecomment-2597359

6
test/simple/test-http-res-write-end-dont-take-array.js

@ -25,7 +25,7 @@ var http = require('http');
var test = 1; var test = 1;
var server = http.createServer(function (req, res) { var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
if (test === 1) { if (test === 1) {
// write should accept string // write should accept string
@ -53,11 +53,11 @@ var server = http.createServer(function (req, res) {
server.listen(common.PORT, function() { server.listen(common.PORT, function() {
// just make a request, other tests handle responses // just make a request, other tests handle responses
http.get({port:common.PORT}, function() { http.get({port: common.PORT}, function() {
// lazy serial test, becuase we can only call end once per request // lazy serial test, becuase we can only call end once per request
test += 1; test += 1;
// do it again to test .end(Buffer); // do it again to test .end(Buffer);
http.get({port:common.PORT}, function() { http.get({port: common.PORT}, function() {
server.close(); server.close();
}); });
}); });

9
test/simple/test-http-response-no-headers.js

@ -27,8 +27,8 @@ var net = require('net');
var expected = { var expected = {
'0.9': 'I AM THE WALRUS', '0.9': 'I AM THE WALRUS',
'1.0': 'I AM THE WALRUS', '1.0': 'I AM THE WALRUS',
'1.1': '', '1.1': ''
} };
var gotExpected = false; var gotExpected = false;
@ -38,11 +38,12 @@ function test(httpVersion, callback) {
}); });
var server = net.createServer(function(conn) { var server = net.createServer(function(conn) {
var reply = 'HTTP/' + httpVersion + ' 200 OK\r\n\r\n' + expected[httpVersion]; var reply = 'HTTP/' + httpVersion + ' 200 OK\r\n\r\n' +
expected[httpVersion];
conn.write(reply, function() { conn.write(reply, function() {
conn.destroy(); conn.destroy();
}) });
}); });
server.listen(common.PORT, '127.0.0.1', function() { server.listen(common.PORT, '127.0.0.1', function() {

15
test/simple/test-init.js

@ -36,11 +36,13 @@
child.exec(process.execPath + ' test-init', {env: {'TEST_INIT': 1}}, child.exec(process.execPath + ' test-init', {env: {'TEST_INIT': 1}},
function(err, stdout, stderr) { function(err, stdout, stderr) {
assert.equal(stdout, 'Loaded successfully!', '`node test-init` failed!'); assert.equal(stdout, 'Loaded successfully!',
'`node test-init` failed!');
}); });
child.exec(process.execPath + ' test-init.js', {env: {'TEST_INIT': 1}}, child.exec(process.execPath + ' test-init.js', {env: {'TEST_INIT': 1}},
function(err, stdout, stderr) { function(err, stdout, stderr) {
assert.equal(stdout, 'Loaded successfully!', '`node test-init.js` failed!'); assert.equal(stdout, 'Loaded successfully!',
'`node test-init.js` failed!');
}); });
// test-init-index is in fixtures dir as requested by ry, so go there // test-init-index is in fixtures dir as requested by ry, so go there
@ -48,16 +50,19 @@
child.exec(process.execPath + ' test-init-index', {env: {'TEST_INIT': 1}}, child.exec(process.execPath + ' test-init-index', {env: {'TEST_INIT': 1}},
function(err, stdout, stderr) { function(err, stdout, stderr) {
assert.equal(stdout, 'Loaded successfully!', '`node test-init-index failed!'); assert.equal(stdout, 'Loaded successfully!',
'`node test-init-index failed!');
}); });
// ensures that `node fs` does not mistakenly load the native 'fs' module // ensures that `node fs` does not mistakenly load the native 'fs' module
// instead of the desired file and that the fs module loads as expected in node // instead of the desired file and that the fs module loads as
// expected in node
process.chdir(common.fixturesDir + '/test-init-native/'); process.chdir(common.fixturesDir + '/test-init-native/');
child.exec(process.execPath + ' fs', {env: {'TEST_INIT': 1}}, child.exec(process.execPath + ' fs', {env: {'TEST_INIT': 1}},
function(err, stdout, stderr) { function(err, stdout, stderr) {
assert.equal(stdout, 'fs loaded successfully', '`node fs` failed!'); assert.equal(stdout, 'fs loaded successfully',
'`node fs` failed!');
}); });
} }
})(); })();

13
test/simple/test-module-load-list.js

@ -24,19 +24,20 @@
// beginning of this file. // beginning of this file.
function assertEqual(x, y) { function assertEqual(x, y) {
if (x !== y) throw new Error("Expected '" + x + "' got '" + y + "'"); if (x !== y) throw new Error('Expected \'' + x + '\' got \'' + y + '\'');
} }
function checkExpected() { function checkExpected() {
var toCompare = Math.max(expected.length, process.moduleLoadList.length); var toCompare = Math.max(expected.length, process.moduleLoadList.length);
for (var i = 0; i < toCompare; i++) { for (var i = 0; i < toCompare; i++) {
if (expected[i] !== process.moduleLoadList[i]) { if (expected[i] !== process.moduleLoadList[i]) {
console.error("process.moduleLoadList[" + i + "] = " + process.moduleLoadList[i]); console.error('process.moduleLoadList[' + i + '] = ' +
console.error("expected[" + i + "] = " + expected[i]); process.moduleLoadList[i]);
console.error('expected[' + i + '] = ' + expected[i]);
console.error("process.moduleLoadList", process.moduleLoadList); console.error('process.moduleLoadList', process.moduleLoadList);
console.error("expected = ", expected); console.error('expected = ', expected);
throw new Error("mismatch"); throw new Error('mismatch');
} }
} }
} }

2
test/simple/test-net-connect-buffer.js

@ -85,7 +85,7 @@ tcp.listen(common.PORT, function() {
// Write a string that contains a multi-byte character sequence to test that // Write a string that contains a multi-byte character sequence to test that
// `bytesWritten` is incremented with the # of bytes, not # of characters. // `bytesWritten` is incremented with the # of bytes, not # of characters.
var a = "L'État, c'est "; var a = "L'État, c'est ";
var b = "moi"; var b = 'moi';
// We're still connecting at this point so the datagram is first pushed onto // We're still connecting at this point so the datagram is first pushed onto
// the connect queue. Make sure that it's not added to `bytesWritten` again // the connect queue. Make sure that it's not added to `bytesWritten` again

26
test/simple/test-net-pipe-connect-errors.js

@ -31,42 +31,40 @@ var accessErrorFired = false;
// Test if ENOTSOCK is fired when trying to connect to a file which is not // Test if ENOTSOCK is fired when trying to connect to a file which is not
// a socket. // a socket.
var notSocketClient = net.createConnection( var emptyTxt = path.join(common.fixturesDir, 'empty.txt');
path.join(common.fixturesDir, 'empty.txt'), var notSocketClient = net.createConnection(emptyTxt, function() {
function () { assert.ok(false);
assert.ok(false); });
}
);
notSocketClient.on('error', function (err) { notSocketClient.on('error', function(err) {
assert(err.code === 'ENOTSOCK' || err.code === 'ECONNREFUSED'); assert(err.code === 'ENOTSOCK' || err.code === 'ECONNREFUSED');
notSocketErrorFired = true; notSocketErrorFired = true;
}); });
// Trying to connect to not-existing socket should result in ENOENT error // Trying to connect to not-existing socket should result in ENOENT error
var noEntSocketClient = net.createConnection('no-ent-file', function () { var noEntSocketClient = net.createConnection('no-ent-file', function() {
assert.ok(false); assert.ok(false);
}); });
noEntSocketClient.on('error', function (err) { noEntSocketClient.on('error', function(err) {
assert.equal(err.code, 'ENOENT'); assert.equal(err.code, 'ENOENT');
noEntErrorFired = true; noEntErrorFired = true;
}); });
// Trying to connect to a socket one has no access to should result in EACCES // Trying to connect to a socket one has no access to should result in EACCES
var accessServer = net.createServer(function () { var accessServer = net.createServer(function() {
assert.ok(false); assert.ok(false);
}); });
accessServer.listen(common.PIPE, function () { accessServer.listen(common.PIPE, function() {
fs.chmodSync(common.PIPE, 0); fs.chmodSync(common.PIPE, 0);
var accessClient = net.createConnection(common.PIPE, function () { var accessClient = net.createConnection(common.PIPE, function() {
assert.ok(false); assert.ok(false);
}); });
accessClient.on('error', function (err) { accessClient.on('error', function(err) {
assert.equal(err.code, 'EACCES'); assert.equal(err.code, 'EACCES');
accessErrorFired = true; accessErrorFired = true;
accessServer.close(); accessServer.close();
@ -75,7 +73,7 @@ accessServer.listen(common.PIPE, function () {
// Assert that all error events were fired // Assert that all error events were fired
process.on('exit', function () { process.on('exit', function() {
assert.ok(notSocketErrorFired); assert.ok(notSocketErrorFired);
assert.ok(noEntErrorFired); assert.ok(noEntErrorFired);
assert.ok(accessErrorFired); assert.ok(accessErrorFired);

10
test/simple/test-path.js

@ -35,12 +35,14 @@ assert.equal(path.basename(f, '.js'), 'test-path');
// c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html // c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html
if (!isWindows) { if (!isWindows) {
var controlCharFilename = 'Icon' + String.fromCharCode(13); var controlCharFilename = 'Icon' + String.fromCharCode(13);
assert.equal(path.basename('/a/b/' + controlCharFilename), controlCharFilename); assert.equal(path.basename('/a/b/' + controlCharFilename),
controlCharFilename);
} }
assert.equal(path.extname(f), '.js'); assert.equal(path.extname(f), '.js');
assert.equal(path.dirname(f).substr(-11), isWindows ? 'test\\simple' : 'test/simple'); assert.equal(path.dirname(f).substr(-11),
isWindows ? 'test\\simple' : 'test/simple');
assert.equal(path.dirname('/a/b/'), '/a'); assert.equal(path.dirname('/a/b/'), '/a');
assert.equal(path.dirname('/a/b'), '/a'); assert.equal(path.dirname('/a/b'), '/a');
assert.equal(path.dirname('/a'), '/'); assert.equal(path.dirname('/a'), '/');
@ -237,7 +239,9 @@ var failures = [];
relativeTests.forEach(function(test) { relativeTests.forEach(function(test) {
var actual = path.relative(test[0], test[1]); var actual = path.relative(test[0], test[1]);
var expected = test[2]; var expected = test[2];
var message = 'path.relative(' + test.slice(0, 2).map(JSON.stringify).join(',') + ')' + var message = 'path.relative(' +
test.slice(0, 2).map(JSON.stringify).join(',') +
')' +
'\n expect=' + JSON.stringify(expected) + '\n expect=' + JSON.stringify(expected) +
'\n actual=' + JSON.stringify(actual); '\n actual=' + JSON.stringify(actual);
if (actual !== expected) failures.push('\n' + message); if (actual !== expected) failures.push('\n' + message);

81
test/simple/test-punycode.js

@ -62,101 +62,102 @@ assert.equal(punycode.decode('wgv71a119e'), '日本語');
var tests = { var tests = {
// (A) Arabic (Egyptian) // (A) Arabic (Egyptian)
'egbpdaj6bu4bxfgehfvwxn': 'egbpdaj6bu4bxfgehfvwxn':
'\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' + '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' +
'\u0634\u0639\u0631\u0628\u064A\u061F', '\u0634\u0639\u0631\u0628\u064A\u061F',
// (B) Chinese (simplified) // (B) Chinese (simplified)
'ihqwcrb4cv8a8dqg056pqjye': 'ihqwcrb4cv8a8dqg056pqjye':
'\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587', '\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587',
// (C) Chinese (traditional) // (C) Chinese (traditional)
'ihqwctvzc91f659drss3x8bo0yb': 'ihqwctvzc91f659drss3x8bo0yb':
'\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587', '\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587',
// (D) Czech: Pro<ccaron>prost<ecaron>nemluv<iacute><ccaron>esky // (D) Czech: Pro<ccaron>prost<ecaron>nemluv<iacute><ccaron>esky
'Proprostnemluvesky-uyb24dma41a': 'Proprostnemluvesky-uyb24dma41a':
'\u0050\u0072\u006F\u010D\u0070\u0072\u006F\u0073\u0074\u011B\u006E' + '\u0050\u0072\u006F\u010D\u0070\u0072\u006F\u0073\u0074\u011B\u006E' +
'\u0065\u006D\u006C\u0075\u0076\u00ED\u010D\u0065\u0073\u006B\u0079', '\u0065\u006D\u006C\u0075\u0076\u00ED\u010D\u0065\u0073\u006B\u0079',
// (E) Hebrew // (E) Hebrew
'4dbcagdahymbxekheh6e0a7fei0b': '4dbcagdahymbxekheh6e0a7fei0b':
'\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC\u05D0' + '\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC\u05D0' +
'\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA', '\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA',
// (F) Hindi (Devanagari) // (F) Hindi (Devanagari)
'i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd': 'i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd':
'\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926\u0940' + '\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926\u0940' +
'\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C\u094B' + '\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C\u094B' +
'\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902', '\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902',
// (G) Japanese (kanji and hiragana) // (G) Japanese (kanji and hiragana)
'n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa': 'n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa':
'\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71\u3057' + '\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71\u3057' +
'\u3066\u304F\u308C\u306A\u3044\u306E\u304B', '\u3066\u304F\u308C\u306A\u3044\u306E\u304B',
// (H) Korean (Hangul syllables) // (H) Korean (Hangul syllables)
'989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c': '989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c':
'\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C\uAD6D' + '\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C\uAD6D' +
'\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098\uC88B' + '\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098\uC88B' +
'\uC744\uAE4C', '\uC744\uAE4C',
// (I) Russian (Cyrillic) // (I) Russian (Cyrillic)
/* XXX disabled, fails - possibly a bug in the RFC /* XXX disabled, fails - possibly a bug in the RFC
'b1abfaaepdrnnbgefbaDotcwatmq2g4l': 'b1abfaaepdrnnbgefbaDotcwatmq2g4l':
'\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D\u0438' + '\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D\u0438' +
'\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F\u043E' + '\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F\u043E' +
'\u0440\u0443\u0441\u0441\u043A\u0438', '\u0440\u0443\u0441\u0441\u043A\u0438',
*/ */
// (J) Spanish: Porqu<eacute>nopuedensimplementehablarenEspa<ntilde>ol // (J) Spanish: Porqu<eacute>nopuedensimplementehablarenEspa<ntilde>ol
'PorqunopuedensimplementehablarenEspaol-fmd56a': 'PorqunopuedensimplementehablarenEspaol-fmd56a':
'\u0050\u006F\u0072\u0071\u0075\u00E9\u006E\u006F\u0070\u0075\u0065' + '\u0050\u006F\u0072\u0071\u0075\u00E9\u006E\u006F\u0070\u0075\u0065' +
'\u0064\u0065\u006E\u0073\u0069\u006D\u0070\u006C\u0065\u006D\u0065' + '\u0064\u0065\u006E\u0073\u0069\u006D\u0070\u006C\u0065\u006D\u0065' +
'\u006E\u0074\u0065\u0068\u0061\u0062\u006C\u0061\u0072\u0065\u006E' + '\u006E\u0074\u0065\u0068\u0061\u0062\u006C\u0061\u0072\u0065\u006E' +
'\u0045\u0073\u0070\u0061\u00F1\u006F\u006C', '\u0045\u0073\u0070\u0061\u00F1\u006F\u006C',
// (K) Vietnamese: T<adotbelow>isaoh<odotbelow>kh<ocirc>ngth<ecirchookabove>ch<ihookabove>n<oacute>iti<ecircacute>ngVi<ecircdotbelow>t // (K) Vietnamese: T<adotbelow>isaoh<odotbelow>kh<ocirc>ngth
// <ecirchookabove>ch<ihookabove>n<oacute>iti<ecircacute>ngVi<ecircdotbelow>t
'TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g': 'TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g':
'\u0054\u1EA1\u0069\u0073\u0061\u006F\u0068\u1ECD\u006B\u0068\u00F4' + '\u0054\u1EA1\u0069\u0073\u0061\u006F\u0068\u1ECD\u006B\u0068\u00F4' +
'\u006E\u0067\u0074\u0068\u1EC3\u0063\u0068\u1EC9\u006E\u00F3\u0069' + '\u006E\u0067\u0074\u0068\u1EC3\u0063\u0068\u1EC9\u006E\u00F3\u0069' +
'\u0074\u0069\u1EBF\u006E\u0067\u0056\u0069\u1EC7\u0074', '\u0074\u0069\u1EBF\u006E\u0067\u0056\u0069\u1EC7\u0074',
// (L) 3<nen>B<gumi><kinpachi><sensei> // (L) 3<nen>B<gumi><kinpachi><sensei>
'3B-ww4c5e180e575a65lsy2b': '3B-ww4c5e180e575a65lsy2b':
'\u0033\u5E74\u0042\u7D44\u91D1\u516B\u5148\u751F', '\u0033\u5E74\u0042\u7D44\u91D1\u516B\u5148\u751F',
// (M) <amuro><namie>-with-SUPER-MONKEYS // (M) <amuro><namie>-with-SUPER-MONKEYS
'-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n': '-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n':
'\u5B89\u5BA4\u5948\u7F8E\u6075\u002D\u0077\u0069\u0074\u0068\u002D' + '\u5B89\u5BA4\u5948\u7F8E\u6075\u002D\u0077\u0069\u0074\u0068\u002D' +
'\u0053\u0055\u0050\u0045\u0052\u002D\u004D\u004F\u004E\u004B\u0045' + '\u0053\u0055\u0050\u0045\u0052\u002D\u004D\u004F\u004E\u004B\u0045' +
'\u0059\u0053', '\u0059\u0053',
// (N) Hello-Another-Way-<sorezore><no><basho> // (N) Hello-Another-Way-<sorezore><no><basho>
'Hello-Another-Way--fc4qua05auwb3674vfr0b': 'Hello-Another-Way--fc4qua05auwb3674vfr0b':
'\u0048\u0065\u006C\u006C\u006F\u002D\u0041\u006E\u006F\u0074\u0068' + '\u0048\u0065\u006C\u006C\u006F\u002D\u0041\u006E\u006F\u0074\u0068' +
'\u0065\u0072\u002D\u0057\u0061\u0079\u002D\u305D\u308C\u305E\u308C' + '\u0065\u0072\u002D\u0057\u0061\u0079\u002D\u305D\u308C\u305E\u308C' +
'\u306E\u5834\u6240', '\u306E\u5834\u6240',
// (O) <hitotsu><yane><no><shita>2 // (O) <hitotsu><yane><no><shita>2
'2-u9tlzr9756bt3uc0v': '2-u9tlzr9756bt3uc0v':
'\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B\u0032', '\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B\u0032',
// (P) Maji<de>Koi<suru>5<byou><mae> // (P) Maji<de>Koi<suru>5<byou><mae>
'MajiKoi5-783gue6qz075azm5e': 'MajiKoi5-783gue6qz075azm5e':
'\u004D\u0061\u006A\u0069\u3067\u004B\u006F\u0069\u3059\u308B\u0035' + '\u004D\u0061\u006A\u0069\u3067\u004B\u006F\u0069\u3059\u308B\u0035' +
'\u79D2\u524D', '\u79D2\u524D',
// (Q) <pafii>de<runba> // (Q) <pafii>de<runba>
'de-jg4avhby1noc0d': 'de-jg4avhby1noc0d':
'\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0', '\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0',
// (R) <sono><supiido><de> // (R) <sono><supiido><de>
'd9juau41awczczp': 'd9juau41awczczp':
'\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067', '\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067',
// (S) -> $1.00 <- // (S) -> $1.00 <-
'-> $1.00 <--': '-> $1.00 <--':
'\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C\u002D' '\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C\u002D'
}; };
var errors = 0; var errors = 0;

2
test/simple/test-readdir.js

@ -66,7 +66,7 @@ process.on('exit', function() {
var has_caught = false; var has_caught = false;
try { try {
fs.readdirSync(__filename) fs.readdirSync(__filename);
} }
catch (e) { catch (e) {
has_caught = true; has_caught = true;

10
test/simple/test-regress-GH-1899.js

@ -20,18 +20,20 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
var path = require('path'); var path = require('path');
var assert = require('assert') var assert = require('assert');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var common = require('../common'); var common = require('../common');
var child = spawn(process.argv[0], [path.join(common.fixturesDir, 'GH-1899-output.js')]); var child = spawn(process.argv[0], [
path.join(common.fixturesDir, 'GH-1899-output.js')
]);
var output = ''; var output = '';
child.stdout.on('data', function (data) { child.stdout.on('data', function(data) {
output += data; output += data;
}); });
child.on('exit', function (code, signal) { child.on('exit', function(code, signal) {
assert.equal(code, 0); assert.equal(code, 0);
assert.equal(output, 'hello, world!\n'); assert.equal(output, 'hello, world!\n');
}); });

15
test/simple/test-regress-GH-877.js

@ -35,6 +35,8 @@ var server = http.createServer(function(req, res) {
res.end('Hello World\n'); res.end('Hello World\n');
}); });
var addrString = '127.0.0.1:' + common.PORT;
server.listen(common.PORT, '127.0.0.1', function() { server.listen(common.PORT, '127.0.0.1', function() {
for (var i = 0; i < N; i++) { for (var i = 0; i < N; i++) {
var options = { var options = {
@ -50,12 +52,15 @@ server.listen(common.PORT, '127.0.0.1', function() {
assert.equal(req.agent, agent); assert.equal(req.agent, agent);
console.log('Socket: ' + agent.sockets['127.0.0.1:' + common.PORT].length + console.log('Socket: ' + agent.sockets[addrString].length + '/' +
'/' + agent.maxSockets + agent.maxSockets + ' queued: ' + (agent.requests[addrString] ?
' queued: ' + (agent.requests['127.0.0.1:' + common.PORT] ? agent.requests['127.0.0.1:' + common.PORT].length : 0)); agent.requests['127.0.0.1:' + common.PORT].length : 0));
var agentRequests = agent.requests[addrString] ?
agent.requests[addrString].length : 0;
if (maxQueued < (agent.requests['127.0.0.1:' + common.PORT] ? agent.requests['127.0.0.1:' + common.PORT].length : 0)) { if (maxQueued < agentRequests) {
maxQueued = (agent.requests['127.0.0.1:' + common.PORT] ? agent.requests['127.0.0.1:' + common.PORT].length : 0); maxQueued = agentRequests;
} }
} }
}); });

23
test/simple/test-repl-.save.load.js

@ -29,9 +29,9 @@ var repl = require('repl');
// A stream to push an array into a REPL // A stream to push an array into a REPL
function ArrayStream() { function ArrayStream() {
this.run = function (data) { this.run = function(data) {
var self = this; var self = this;
data.forEach(function (line) { data.forEach(function(line) {
self.emit('data', line); self.emit('data', line);
}); });
} }
@ -39,10 +39,10 @@ function ArrayStream() {
util.inherits(ArrayStream, require('stream').Stream); util.inherits(ArrayStream, require('stream').Stream);
ArrayStream.prototype.readable = true; ArrayStream.prototype.readable = true;
ArrayStream.prototype.writable = true; ArrayStream.prototype.writable = true;
ArrayStream.prototype.resume = function () {}; ArrayStream.prototype.resume = function() {};
ArrayStream.prototype.write = function () {}; ArrayStream.prototype.write = function() {};
var works = [ [ 'inner.one' ], 'inner.o' ]; var works = [['inner.one'], 'inner.o'];
var putIn = new ArrayStream(); var putIn = new ArrayStream();
var testMe = repl.start('', putIn); var testMe = repl.start('', putIn);
@ -61,13 +61,11 @@ putIn.run(testFile);
putIn.run(['.save ' + saveFileName]); putIn.run(['.save ' + saveFileName]);
// the file should have what I wrote // the file should have what I wrote
assert.equal( assert.equal(fs.readFileSync(saveFileName, 'utf8'), testFile.join('\n') + '\n');
fs.readFileSync(saveFileName, 'utf8'),
testFile.join('\n') + '\n');
// make sure that the REPL data is "correct" // make sure that the REPL data is "correct"
// so when I load it back I know I'm good // so when I load it back I know I'm good
testMe.complete('inner.o', function (error, data) { testMe.complete('inner.o', function(error, data) {
assert.deepEqual(data, works); assert.deepEqual(data, works);
}); });
@ -78,7 +76,7 @@ putIn.run(['.clear']);
putIn.run(['.load ' + saveFileName]); putIn.run(['.load ' + saveFileName]);
// make sure that the REPL data is "correct" // make sure that the REPL data is "correct"
testMe.complete('inner.o', function (error, data) { testMe.complete('inner.o', function(error, data) {
assert.deepEqual(data, works); assert.deepEqual(data, works);
}); });
@ -90,12 +88,11 @@ var loadFile = join(common.tmpDir, 'file.does.not.exist');
// shold not break // shold not break
putIn.write = function(data) { putIn.write = function(data) {
// make sure I get a failed to load message and not some crazy error // make sure I get a failed to load message and not some crazy error
assert.equal(data, assert.equal(data, 'Failed to load:' + loadFile + '\n');
'Failed to load:' + loadFile + '\n');
// eat me to avoid work // eat me to avoid work
putIn.write = function() {}; putIn.write = function() {};
}; };
putIn.run(['.load ' +loadFile]); putIn.run(['.load ' + loadFile]);
//TODO how do I do a failed .save test? //TODO how do I do a failed .save test?

4
test/simple/test-setproctitle.js

@ -23,14 +23,14 @@
// FIXME add sunos support // FIXME add sunos support
if ('linux freebsd'.indexOf(process.platform) === -1) { if ('linux freebsd'.indexOf(process.platform) === -1) {
console.error("Skipping test, platform not supported."); console.error('Skipping test, platform not supported.');
process.exit(); process.exit();
} }
var assert = require('assert'); var assert = require('assert');
var exec = require('child_process').exec; var exec = require('child_process').exec;
var title = "testTestTESTtest123123123123123123HiHaiJo"; var title = 'testTestTESTtest123123123123123123HiHaiJo';
assert.notEqual(process.title, title); assert.notEqual(process.title, title);
process.title = title; process.title = title;

12
test/simple/test-stdin-pause-resume.js

@ -19,19 +19,19 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
console.error("before opening stdin"); console.error('before opening stdin');
process.stdin.resume(); process.stdin.resume();
console.error("stdin opened"); console.error('stdin opened');
setTimeout(function() { setTimeout(function() {
console.error("pausing stdin"); console.error('pausing stdin');
process.stdin.pause(); process.stdin.pause();
setTimeout(function() { setTimeout(function() {
console.error("opening again"); console.error('opening again');
process.stdin.resume(); process.stdin.resume();
setTimeout(function() { setTimeout(function() {
console.error("pausing again"); console.error('pausing again');
process.stdin.pause(); process.stdin.pause();
console.error("should exit now"); console.error('should exit now');
}, 1); }, 1);
}, 1); }, 1);
}, 1); }, 1);

2
test/simple/test-tls-passphrase.js

@ -37,7 +37,7 @@ var server = tls.Server({
key: key, key: key,
passphrase: 'passphrase', passphrase: 'passphrase',
cert: cert, cert: cert,
ca: [ cert ], ca: [cert],
requestCert: true, requestCert: true,
rejectUnauthorized: true rejectUnauthorized: true
}, function(s) { }, function(s) {

6
test/simple/test-tls-session-cache.js

@ -20,12 +20,12 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
if (!process.versions.openssl) { if (!process.versions.openssl) {
console.error("Skipping because node compiled without OpenSSL."); console.error('Skipping because node compiled without OpenSSL.');
process.exit(0); process.exit(0);
} }
require('child_process').exec('openssl version', function(err) { require('child_process').exec('openssl version', function(err) {
if (err !== null) { if (err !== null) {
console.error("Skipping because openssl command is not available."); console.error('Skipping because openssl command is not available.');
process.exit(0); process.exit(0);
} }
doTest(); doTest();
@ -46,7 +46,7 @@ function doTest() {
var options = { var options = {
key: key, key: key,
cert: cert, cert: cert,
ca: [ cert ], ca: [cert],
requestCert: true requestCert: true
}; };
var requestCount = 0; var requestCount = 0;

3
test/simple/test-tls-set-ciphers.js

@ -51,7 +51,8 @@ var server = tls.createServer(options, function(conn) {
}); });
server.listen(common.PORT, '127.0.0.1', function() { server.listen(common.PORT, '127.0.0.1', function() {
var cmd = 'openssl s_client -cipher NULL-MD5 -connect 127.0.0.1:' + common.PORT; var cmd = 'openssl s_client -cipher NULL-MD5 -connect 127.0.0.1:' +
common.PORT;
exec(cmd, function(err, stdout, stderr) { exec(cmd, function(err, stdout, stderr) {
if (err) throw err; if (err) throw err;

2
test/simple/test-tty-stdout-end.js

@ -27,7 +27,7 @@ var exceptionCaught = false;
try { try {
process.stdout.end(); process.stdout.end();
} catch(e) { } catch (e) {
exceptionCaught = true; exceptionCaught = true;
assert.ok(common.isError(e)); assert.ok(common.isError(e));
assert.equal('process.stdout cannot be closed', e.message); assert.equal('process.stdout cannot be closed', e.message);

6
test/simple/test-util-inspect.js

@ -61,16 +61,16 @@ assert.ok(ex.indexOf('[type]') != -1);
// GH-1941 // GH-1941
// should not throw: // should not throw:
assert.equal(util.inspect(Object.create(Date.prototype)), '{}') assert.equal(util.inspect(Object.create(Date.prototype)), '{}');
// GH-1944 // GH-1944
assert.doesNotThrow(function () { assert.doesNotThrow(function() {
var d = new Date(); var d = new Date();
d.toUTCString = null; d.toUTCString = null;
util.inspect(d); util.inspect(d);
}); });
assert.doesNotThrow(function () { assert.doesNotThrow(function() {
var r = /regexp/; var r = /regexp/;
r.toString = null; r.toString = null;
util.inspect(r); util.inspect(r);

74
test/simple/test-util.js

@ -26,46 +26,46 @@ var util = require('util');
var context = require('vm').runInNewContext; var context = require('vm').runInNewContext;
// isArray // isArray
assert.equal(true, util.isArray([])) assert.equal(true, util.isArray([]));
assert.equal(true, util.isArray(Array())) assert.equal(true, util.isArray(Array()));
assert.equal(true, util.isArray(new Array())) assert.equal(true, util.isArray(new Array()));
assert.equal(true, util.isArray(new Array(5))) assert.equal(true, util.isArray(new Array(5)));
assert.equal(true, util.isArray(new Array('with', 'some', 'entries'))) assert.equal(true, util.isArray(new Array('with', 'some', 'entries')));
assert.equal(true, util.isArray(context('Array')())) assert.equal(true, util.isArray(context('Array')()));
assert.equal(false, util.isArray({})) assert.equal(false, util.isArray({}));
assert.equal(false, util.isArray({ push: function () {} })) assert.equal(false, util.isArray({ push: function() {} }));
assert.equal(false, util.isArray(/regexp/)) assert.equal(false, util.isArray(/regexp/));
assert.equal(false, util.isArray(new Error)) assert.equal(false, util.isArray(new Error));
assert.equal(false, util.isArray(Object.create(Array.prototype))) assert.equal(false, util.isArray(Object.create(Array.prototype)));
// isRegExp // isRegExp
assert.equal(true, util.isRegExp(/regexp/)) assert.equal(true, util.isRegExp(/regexp/));
assert.equal(true, util.isRegExp(RegExp())) assert.equal(true, util.isRegExp(RegExp()));
assert.equal(true, util.isRegExp(new RegExp())) assert.equal(true, util.isRegExp(new RegExp()));
assert.equal(true, util.isRegExp(context('RegExp')())) assert.equal(true, util.isRegExp(context('RegExp')()));
assert.equal(false, util.isRegExp({})) assert.equal(false, util.isRegExp({}));
assert.equal(false, util.isRegExp([])) assert.equal(false, util.isRegExp([]));
assert.equal(false, util.isRegExp(new Date())) assert.equal(false, util.isRegExp(new Date()));
assert.equal(false, util.isRegExp(Object.create(RegExp.prototype))) assert.equal(false, util.isRegExp(Object.create(RegExp.prototype)));
// isDate // isDate
assert.equal(true, util.isDate(new Date())) assert.equal(true, util.isDate(new Date()));
assert.equal(true, util.isDate(new Date(0))) assert.equal(true, util.isDate(new Date(0)));
assert.equal(true, util.isDate(new (context('Date')))) assert.equal(true, util.isDate(new (context('Date'))));
assert.equal(false, util.isDate(Date())) assert.equal(false, util.isDate(Date()));
assert.equal(false, util.isDate({})) assert.equal(false, util.isDate({}));
assert.equal(false, util.isDate([])) assert.equal(false, util.isDate([]));
assert.equal(false, util.isDate(new Error)) assert.equal(false, util.isDate(new Error));
assert.equal(false, util.isDate(Object.create(Date.prototype))) assert.equal(false, util.isDate(Object.create(Date.prototype)));
// isError // isError
assert.equal(true, util.isError(new Error)) assert.equal(true, util.isError(new Error));
assert.equal(true, util.isError(new TypeError)) assert.equal(true, util.isError(new TypeError));
assert.equal(true, util.isError(new SyntaxError)) assert.equal(true, util.isError(new SyntaxError));
assert.equal(true, util.isError(new (context('Error')))) assert.equal(true, util.isError(new (context('Error'))));
assert.equal(true, util.isError(new (context('TypeError')))) assert.equal(true, util.isError(new (context('TypeError'))));
assert.equal(true, util.isError(new (context('SyntaxError')))) assert.equal(true, util.isError(new (context('SyntaxError'))));
assert.equal(false, util.isError({})) assert.equal(false, util.isError({}));
assert.equal(false, util.isError({ name: 'Error', message: '' })) assert.equal(false, util.isError({ name: 'Error', message: '' }));
assert.equal(false, util.isError([])) assert.equal(false, util.isError([]));
assert.equal(false, util.isError(Object.create(Error.prototype))) assert.equal(false, util.isError(Object.create(Error.prototype)));

2
test/simple/test-zlib-from-gzip.js

@ -43,6 +43,6 @@ out.on('close', function() {
var actual = fs.readFileSync(outputFile); var actual = fs.readFileSync(outputFile);
assert.equal(actual.length, expect.length, 'length should match'); assert.equal(actual.length, expect.length, 'length should match');
for (var i = 0, l = actual.length; i < l; i++) { for (var i = 0, l = actual.length; i < l; i++) {
assert.equal(actual[i], expect[i], 'byte['+i+']'); assert.equal(actual[i], expect[i], 'byte[' + i + ']');
} }
}); });

35
test/simple/test-zlib-from-string.js

@ -25,12 +25,31 @@ var common = require('../common.js');
var assert = require('assert'); var assert = require('assert');
var zlib = require('zlib'); var zlib = require('zlib');
var inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi faucibus, purus at gravida dictum, libero arcu convallis lacus, in commodo libero metus eu nisi. Nullam commodo, neque nec porta placerat, nisi est fermentum augue, vitae gravida tellus sapien sit amet tellus. Aenean non diam orci. Proin quis elit turpis. Suspendisse non diam ipsum. Suspendisse nec ullamcorper odio. Vestibulum arcu mi, sodales non suscipit id, ultrices ut massa. Sed ac sem sit amet arcu malesuada fermentum. Nunc sed. '; var inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing el' +
var expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpmXAKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkDlKWLJWkncJG5403HQXAkT3Jw29B9uIEmToMukglZ0vS6ociBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491LofoAbWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+RSQsGoC7dn2t/xjhduTA1NWyQIZR0pbHwMDatnD+crPqKSqGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqqqfKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOHaFE4RdpnGavKtrB5xzfO/Ll9'; 'it. Morbi faucibus, purus at gravida dictum, libero arcu convallis la' +
var expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN496pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajNPk6QOUpYslaSdwkbnjTcdBcCRPcnDb0H24gSZOgy6SCVnS9LqhyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYrLj3Uuh+gBtaHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCwagLt2fa3/GOF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9hN9ory+qqp8oG00yF7c5mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2sHnHNzRtagj5AQAA'; 'cus, in commodo libero metus eu nisi. Nullam commodo, neque nec porta' +
' placerat, nisi est fermentum augue, vitae gravida tellus sapien sit ' +
'amet tellus. Aenean non diam orci. Proin quis elit turpis. Suspendiss' +
'e non diam ipsum. Suspendisse nec ullamcorper odio. Vestibulum arcu m' +
'i, sodales non suscipit id, ultrices ut massa. Sed ac sem sit amet ar' +
'cu malesuada fermentum. Nunc sed. ';
var expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpm' +
'XAKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkDlKWLJWkncJG5403HQXAkT3' +
'Jw29B9uIEmToMukglZ0vS6ociBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491Lofo' +
'AbWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+RSQsGoC7dn2t/xjhduTA1N' +
'WyQIZR0pbHwMDatnD+crPqKSqGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqq' +
'qfKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOHaFE4RdpnGavKtrB5xzfO/Ll9';
var expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN' +
'496pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajNPk6QOUpYslaSdwkbnjT' +
'cdBcCRPcnDb0H24gSZOgy6SCVnS9LqhyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYr' +
'Lj3Uuh+gBtaHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCwagLt2fa3/G' +
'OF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9h' +
'N9ory+qqp8oG00yF7c5mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2s' +
'HnHNzRtagj5AQAA';
zlib.deflate(inputString, function(err, buffer) { zlib.deflate(inputString, function(err, buffer) {
assert.equal(buffer.toString('base64'), expectedBase64Deflate, 'deflate encoded string should match'); assert.equal(buffer.toString('base64'), expectedBase64Deflate,
'deflate encoded string should match');
}); });
zlib.gzip(inputString, function(err, buffer) { zlib.gzip(inputString, function(err, buffer) {
@ -40,7 +59,7 @@ zlib.gzip(inputString, function(err, buffer) {
// However, decrypting it should definitely yield the same // However, decrypting it should definitely yield the same
// result that we're expecting, and this should match what we get // result that we're expecting, and this should match what we get
// from inflating the known valid deflate data. // from inflating the known valid deflate data.
zlib.gunzip(buffer, function (err, gunzipped) { zlib.gunzip(buffer, function(err, gunzipped) {
assert.equal(gunzipped.toString(), inputString, assert.equal(gunzipped.toString(), inputString,
'Should get original string after gzip/gunzip'); 'Should get original string after gzip/gunzip');
}); });
@ -48,10 +67,12 @@ zlib.gzip(inputString, function(err, buffer) {
var buffer = new Buffer(expectedBase64Deflate, 'base64'); var buffer = new Buffer(expectedBase64Deflate, 'base64');
zlib.unzip(buffer, function(err, buffer) { zlib.unzip(buffer, function(err, buffer) {
assert.equal(buffer.toString(), inputString, 'decoded inflated string should match'); assert.equal(buffer.toString(), inputString,
'decoded inflated string should match');
}); });
buffer = new Buffer(expectedBase64Gzip, 'base64'); buffer = new Buffer(expectedBase64Gzip, 'base64');
zlib.unzip(buffer, function(err, buffer) { zlib.unzip(buffer, function(err, buffer) {
assert.equal(buffer.toString(), inputString, 'decoded gunzipped string should match'); assert.equal(buffer.toString(), inputString,
'decoded gunzipped string should match');
}); });

14
test/simple/test-zlib-random-byte-pipes.js

@ -29,7 +29,7 @@ var zlib = require('zlib');
// emit random bytes, and keep a shasum // emit random bytes, and keep a shasum
function RandomReadStream (opt) { function RandomReadStream(opt) {
Stream.call(this); Stream.call(this);
this.readable = true; this.readable = true;
@ -67,7 +67,7 @@ RandomReadStream.prototype.resume = function() {
// console.error("rrs resume"); // console.error("rrs resume");
this._paused = false; this._paused = false;
this.emit('resume'); this.emit('resume');
this._process() this._process();
}; };
RandomReadStream.prototype._process = function() { RandomReadStream.prototype._process = function() {
@ -91,9 +91,9 @@ RandomReadStream.prototype._process = function() {
if (jitter) { if (jitter) {
block += Math.ceil(Math.random() * jitter - (jitter / 2)); block += Math.ceil(Math.random() * jitter - (jitter / 2));
} }
block = Math.min(block, this._remaining) block = Math.min(block, this._remaining);
var buf = new Buffer(block); var buf = new Buffer(block);
for (var i = 0; i < block; i ++) { for (var i = 0; i < block; i++) {
buf[i] = Math.random() * 256; buf[i] = Math.random() * 256;
} }
@ -110,7 +110,7 @@ RandomReadStream.prototype._process = function() {
// a filter that just verifies a shasum // a filter that just verifies a shasum
function HashStream () { function HashStream() {
Stream.call(this); Stream.call(this);
this.readable = this.writable = true; this.readable = this.writable = true;
@ -152,7 +152,7 @@ var gunz = zlib.createGunzip();
inp.pipe(gzip).pipe(gunz).pipe(out); inp.pipe(gzip).pipe(gunz).pipe(out);
var didSomething = false; var didSomething = false;
out.on('data', function (c) { out.on('data', function(c) {
didSomething = true; didSomething = true;
console.error('hash=%s', c); console.error('hash=%s', c);
assert.equal(c, inp._hash, 'hashes should match'); assert.equal(c, inp._hash, 'hashes should match');
@ -160,4 +160,4 @@ out.on('data', function (c) {
process.on('exit', function() { process.on('exit', function() {
assert(didSomething, 'should have done something'); assert(didSomething, 'should have done something');
}) });

Loading…
Cancel
Save