From 0ce9cbab291fb533d158407471f8cc277293a27a Mon Sep 17 00:00:00 2001 From: Oleg Efimov Date: Sun, 5 Dec 2010 01:45:52 +0300 Subject: [PATCH] GJSLint continue --- test/common.js | 12 +- test/simple/test-memory-usage.js | 4 +- test/simple/test-module-loading.js | 116 ++++++------ test/simple/test-net-binary.js | 65 ++++--- test/simple/test-net-can-reset-timeout.js | 20 +- test/simple/test-net-connect-buffer.js | 32 ++-- .../test-net-connect-handle-econnrefused.js | 10 +- test/simple/test-net-eaddrinuse.js | 4 +- test/simple/test-net-isip.js | 30 +-- test/simple/test-net-keepalive.js | 10 +- test/simple/test-net-pingpong.js | 46 ++--- test/simple/test-net-reconnect.js | 35 ++-- test/simple/test-net-server-bind.js | 14 +- .../simple/test-net-server-max-connections.js | 39 ++-- test/simple/test-next-tick-errors.js | 2 +- test/simple/test-next-tick-ordering2.js | 2 +- test/simple/test-next-tick.js | 14 +- test/simple/test-path.js | 95 +++++----- test/simple/test-pipe-head.js | 5 +- test/simple/test-pipe.js | 48 ++--- test/simple/test-pump-file2tcp-noexist.js | 22 +-- test/simple/test-pump-file2tcp.js | 16 +- test/simple/test-querystring.js | 177 +++++++++--------- test/simple/test-readdir.js | 29 ++- .../test-regression-object-prototype.js | 2 +- test/simple/test-repl.js | 149 ++++++++------- test/simple/test-require-resolve.js | 20 +- test/simple/test-script-new.js | 34 ++-- test/simple/test-script-static-new.js | 26 +-- test/simple/test-script-static-this.js | 20 +- test/simple/test-script-this.js | 20 +- test/simple/test-securepair-client.js | 50 ++--- test/simple/test-securepair-server.js | 22 +-- test/simple/test-sendfd.js | 11 +- test/simple/test-sigint-infinite-loop.js | 16 +- test/simple/test-signal-handler.js | 20 +- test/simple/test-stdin-from-file.js | 19 +- test/simple/test-stdout-to-file.js | 27 ++- 38 files changed, 660 insertions(+), 623 deletions(-) diff --git a/test/common.js b/test/common.js index 3e88c7c4b2..68369a9c44 100644 --- a/test/common.js +++ b/test/common.js @@ -1,14 +1,14 @@ -var path = require("path"); +var path = require('path'); exports.testDir = path.dirname(__filename); -exports.fixturesDir = path.join(exports.testDir, "fixtures"); -exports.libDir = path.join(exports.testDir, "../lib"); -exports.tmpDir = path.join(exports.testDir, "tmp"); +exports.fixturesDir = path.join(exports.testDir, 'fixtures'); +exports.libDir = path.join(exports.testDir, '../lib'); +exports.tmpDir = path.join(exports.testDir, 'tmp'); exports.PORT = 12346; exports.assert = require('assert'); -var util = require("util"); +var util = require('util'); for (var i in util) exports[i] = util[i]; //for (var i in exports) global[i] = exports[i]; @@ -18,7 +18,7 @@ function protoCtrChain (o) { return result.join(); } -exports.indirectInstanceOf = function (obj, cls) { +exports.indirectInstanceOf = function(obj, cls) { if (obj instanceof cls) { return true; } var clsChain = protoCtrChain(cls.prototype); var objChain = protoCtrChain(obj); diff --git a/test/simple/test-memory-usage.js b/test/simple/test-memory-usage.js index 806b0f7815..de6d6c890c 100644 --- a/test/simple/test-memory-usage.js +++ b/test/simple/test-memory-usage.js @@ -3,5 +3,5 @@ var assert = require('assert'); var r = process.memoryUsage(); console.log(common.inspect(r)); -assert.equal(true, r["rss"] > 0); -assert.equal(true, r["vsize"] > 0); +assert.equal(true, r['rss'] > 0); +assert.equal(true, r['vsize'] > 0); diff --git a/test/simple/test-module-loading.js b/test/simple/test-module-loading.js index 500e7ef9e5..a9aaf3a69b 100644 --- a/test/simple/test-module-loading.js +++ b/test/simple/test-module-loading.js @@ -1,160 +1,162 @@ var common = require('../common'); var assert = require('assert'); -var path = require('path'), - fs = require('fs'); +var path = require('path'); +var fs = require('fs'); -common.debug("load test-module-loading.js"); +common.debug('load test-module-loading.js'); // require a file with a request that includes the extension -var a_js = require("../fixtures/a.js"); +var a_js = require('../fixtures/a.js'); assert.equal(42, a_js.number); // require a file without any extensions -var foo_no_ext = require("../fixtures/foo"); -assert.equal("ok", foo_no_ext.foo); +var foo_no_ext = require('../fixtures/foo'); +assert.equal('ok', foo_no_ext.foo); -var a = require("../fixtures/a"); -var c = require("../fixtures/b/c"); -var d = require("../fixtures/b/d"); -var d2 = require("../fixtures/b/d"); +var a = require('../fixtures/a'); +var c = require('../fixtures/b/c'); +var d = require('../fixtures/b/d'); +var d2 = require('../fixtures/b/d'); // Absolute -var d3 = require(path.join(__dirname, "../fixtures/b/d")); +var d3 = require(path.join(__dirname, '../fixtures/b/d')); // Relative -var d4 = require("../fixtures/b/d"); +var d4 = require('../fixtures/b/d'); -assert.equal(false, false, "testing the test program."); +assert.equal(false, false, 'testing the test program.'); assert.equal(true, common.indirectInstanceOf(a.A, Function)); -assert.equal("A", a.A()); +assert.equal('A', a.A()); assert.equal(true, common.indirectInstanceOf(a.C, Function)); -assert.equal("C", a.C()); +assert.equal('C', a.C()); assert.equal(true, common.indirectInstanceOf(a.D, Function)); -assert.equal("D", a.D()); +assert.equal('D', a.D()); assert.equal(true, common.indirectInstanceOf(d.D, Function)); -assert.equal("D", d.D()); +assert.equal('D', d.D()); assert.equal(true, common.indirectInstanceOf(d2.D, Function)); -assert.equal("D", d2.D()); +assert.equal('D', d2.D()); assert.equal(true, common.indirectInstanceOf(d3.D, Function)); -assert.equal("D", d3.D()); +assert.equal('D', d3.D()); assert.equal(true, common.indirectInstanceOf(d4.D, Function)); -assert.equal("D", d4.D()); +assert.equal('D', d4.D()); assert.ok((new a.SomeClass) instanceof c.SomeClass); -common.debug("test index.js modules ids and relative loading") -var one = require("../fixtures/nested-index/one"), - two = require("../fixtures/nested-index/two"); +common.debug('test index.js modules ids and relative loading'); +var one = require('../fixtures/nested-index/one'), + two = require('../fixtures/nested-index/two'); assert.notEqual(one.hello, two.hello); -common.debug("test cycles containing a .. path"); -var root = require("../fixtures/cycles/root"), - foo = require("../fixtures/cycles/folder/foo"); +common.debug('test cycles containing a .. path'); +var root = require('../fixtures/cycles/root'), + foo = require('../fixtures/cycles/folder/foo'); assert.equal(root.foo, foo); assert.equal(root.sayHello(), root.hello); -common.debug("test name clashes"); +common.debug('test name clashes'); // this one exists and should import the local module -var my_path = require("./path"); +var my_path = require('./path'); assert.ok(common.indirectInstanceOf(my_path.path_func, Function)); // this one does not exist and should throw -assert.throws(function() { require("./utils")}); +assert.throws(function() { require('./utils')}); var errorThrown = false; try { - require("../fixtures/throws_error"); + require('../fixtures/throws_error'); } catch (e) { errorThrown = true; - assert.equal("blah", e.message); + assert.equal('blah', e.message); } assert.equal(require('path').dirname(__filename), __dirname); common.debug('load custom file types with extensions'); -require.extensions['.test'] = function (module, filename) { +require.extensions['.test'] = function(module, filename) { var content = fs.readFileSync(filename).toString(); - assert.equal("this is custom source\n", content); - content = content.replace("this is custom source", "exports.test = 'passed'"); + assert.equal('this is custom source\n', content); + content = content.replace('this is custom source', + 'exports.test = \'passed\''); module._compile(content, filename); }; -assert.equal(require('../fixtures/registerExt').test, "passed"); +assert.equal(require('../fixtures/registerExt').test, 'passed'); // unknown extension, load as .js -assert.equal(require('../fixtures/registerExt.hello.world').test, "passed"); +assert.equal(require('../fixtures/registerExt.hello.world').test, 'passed'); common.debug('load custom file types that return non-strings'); -require.extensions['.test'] = function (module, filename) { +require.extensions['.test'] = function(module, filename) { module.exports = { custom: 'passed' }; }; assert.equal(require('../fixtures/registerExt2').custom, 'passed'); -common.debug("load modules by absolute id, then change require.paths, and load another module with the same absolute id."); +common.debug('load modules by absolute id, then change require.paths, ' + + 'and load another module with the same absolute id.'); // this will throw if it fails. -var foo = require("../fixtures/require-path/p1/foo"); +var foo = require('../fixtures/require-path/p1/foo'); process.assert(foo.bar.expect === foo.bar.actual); assert.equal(require('../fixtures/foo').foo, 'ok', - 'require module with no extension'); + 'require module with no extension'); // Should not attempt to load a directory try { - require("../fixtures/empty"); -} catch(err) { - assert.equal(err.message, "Cannot find module '../fixtures/empty'"); + require('../fixtures/empty'); +} catch (err) { + assert.equal(err.message, 'Cannot find module \'../fixtures/empty\''); } // Check load order is as expected common.debug('load order'); var loadOrder = '../fixtures/module-load-order/', - msg = "Load order incorrect."; + msg = 'Load order incorrect.'; require.extensions['.reg'] = require.extensions['.js']; require.extensions['.reg2'] = require.extensions['.js']; -assert.equal(require(loadOrder + 'file1').file1, 'file1', msg); -assert.equal(require(loadOrder + 'file2').file2, 'file2.js', msg); +assert.equal(require(loadOrder + 'file1').file1, 'file1', msg); +assert.equal(require(loadOrder + 'file2').file2, 'file2.js', msg); try { require(loadOrder + 'file3'); } catch (e) { // Not a real .node module, but we know we require'd the right thing. assert.ok(e.message.match(/file3\.node/)); } -assert.equal(require(loadOrder + 'file4').file4, 'file4.reg', msg); -assert.equal(require(loadOrder + 'file5').file5, 'file5.reg2', msg); -assert.equal(require(loadOrder + 'file6').file6, 'file6/index.js', msg); +assert.equal(require(loadOrder + 'file4').file4, 'file4.reg', msg); +assert.equal(require(loadOrder + 'file5').file5, 'file5.reg2', msg); +assert.equal(require(loadOrder + 'file6').file6, 'file6/index.js', msg); try { require(loadOrder + 'file7'); } catch (e) { assert.ok(e.message.match(/file7\/index\.node/)); } -assert.equal(require(loadOrder + 'file8').file8, 'file8/index.reg', msg); +assert.equal(require(loadOrder + 'file8').file8, 'file8/index.reg', msg); assert.equal(require(loadOrder + 'file9').file9, 'file9/index.reg2', msg); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.ok(common.indirectInstanceOf(a.A, Function)); - assert.equal("A done", a.A()); + assert.equal('A done', a.A()); assert.ok(common.indirectInstanceOf(a.C, Function)); - assert.equal("C done", a.C()); + assert.equal('C done', a.C()); assert.ok(common.indirectInstanceOf(a.D, Function)); - assert.equal("D done", a.D()); + assert.equal('D done', a.D()); assert.ok(common.indirectInstanceOf(d.D, Function)); - assert.equal("D done", d.D()); + assert.equal('D done', d.D()); assert.ok(common.indirectInstanceOf(d2.D, Function)); - assert.equal("D done", d2.D()); + assert.equal('D done', d2.D()); assert.equal(true, errorThrown); - console.log("exit"); + console.log('exit'); }); diff --git a/test/simple/test-net-binary.js b/test/simple/test-net-binary.js index 7b5abf5fd1..5e56213136 100644 --- a/test/simple/test-net-binary.js +++ b/test/simple/test-net-binary.js @@ -2,47 +2,46 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); -var binaryString = ""; +var binaryString = ''; for (var i = 255; i >= 0; i--) { - var s = "'\\" + i.toString(8) + "'"; + var s = '\'\\' + i.toString(8) + '\''; var S = eval(s); - common.error( s - + " " - + JSON.stringify(S) - + " " - + JSON.stringify(String.fromCharCode(i)) - + " " - + S.charCodeAt(0) - ); + common.error(s + + ' ' + + JSON.stringify(S) + + ' ' + + JSON.stringify(String.fromCharCode(i)) + + ' ' + + S.charCodeAt(0)); process.assert(S.charCodeAt(0) == i); process.assert(S == String.fromCharCode(i)); binaryString += S; } // safe constructor -var echoServer = net.Server(function (connection) { - connection.setEncoding("binary"); - connection.addListener("data", function (chunk) { - common.error("recved: " + JSON.stringify(chunk)); - connection.write(chunk, "binary"); +var echoServer = net.Server(function(connection) { + connection.setEncoding('binary'); + connection.addListener('data', function(chunk) { + common.error('recved: ' + JSON.stringify(chunk)); + connection.write(chunk, 'binary'); }); - connection.addListener("end", function () { + connection.addListener('end', function() { connection.end(); }); }); echoServer.listen(common.PORT); -var recv = ""; +var recv = ''; -echoServer.addListener("listening", function() { +echoServer.addListener('listening', function() { var j = 0; var c = net.createConnection(common.PORT); - c.setEncoding("binary"); - c.addListener("data", function (chunk) { + c.setEncoding('binary'); + c.addListener('data', function(chunk) { if (j < 256) { - common.error("write " + j); - c.write(String.fromCharCode(j), "binary"); + common.error('write ' + j); + c.write(String.fromCharCode(j), 'binary'); j++; } else { c.end(); @@ -50,28 +49,28 @@ echoServer.addListener("listening", function() { recv += chunk; }); - c.addListener("connect", function () { - c.write(binaryString, "binary"); + c.addListener('connect', function() { + c.write(binaryString, 'binary'); }); - c.addListener("close", function () { + c.addListener('close', function() { console.dir(recv); echoServer.close(); }); }); -process.addListener("exit", function () { - console.log("recv: " + JSON.stringify(recv)); +process.addListener('exit', function() { + console.log('recv: ' + JSON.stringify(recv)); - assert.equal(2*256, recv.length); + assert.equal(2 * 256, recv.length); - var a = recv.split(""); + var a = recv.split(''); - var first = a.slice(0,256).reverse().join(""); - console.log("first: " + JSON.stringify(first)); + var first = a.slice(0, 256).reverse().join(''); + console.log('first: ' + JSON.stringify(first)); - var second = a.slice(256,2*256).join(""); - console.log("second: " + JSON.stringify(second)); + var second = a.slice(256, 2 * 256).join(''); + console.log('second: ' + JSON.stringify(second)); assert.equal(first, second); }); diff --git a/test/simple/test-net-can-reset-timeout.js b/test/simple/test-net-can-reset-timeout.js index db0d68a4b4..c1b46ac53e 100644 --- a/test/simple/test-net-can-reset-timeout.js +++ b/test/simple/test-net-can-reset-timeout.js @@ -4,20 +4,20 @@ var assert = require('assert'); var timeoutCount = 0; -var server = net.createServer(function(stream){ +var server = net.createServer(function(stream) { stream.setTimeout(100); - stream.on('timeout', function () { - console.log("timeout"); + stream.on('timeout', function() { + console.log('timeout'); // try to reset the timeout. - stream.write("WHAT."); + stream.write('WHAT.'); // don't worry, the socket didn't *really* time out, we're just thinking // it did. timeoutCount += 1; }); - stream.on('end', function () { - console.log("server side end"); + stream.on('end', function() { + console.log('server side end'); stream.end(); }); }); @@ -25,17 +25,17 @@ var server = net.createServer(function(stream){ server.listen(common.PORT, function() { var c = net.createConnection(common.PORT); - c.on('data', function () { + c.on('data', function() { c.end(); }); - c.on('end', function () { - console.log("client side end"); + c.on('end', function() { + console.log('client side end'); server.close(); }); }); -process.on('exit', function () { +process.on('exit', function() { assert.equal(1, timeoutCount); }); diff --git a/test/simple/test-net-connect-buffer.js b/test/simple/test-net-connect-buffer.js index 80198bea08..f4cada937a 100644 --- a/test/simple/test-net-connect-buffer.js +++ b/test/simple/test-net-connect-buffer.js @@ -4,44 +4,44 @@ var net = require('net'); var tcpPort = common.PORT; -var tcp = net.Server(function (s) { +var tcp = net.Server(function(s) { tcp.close(); - console.log("tcp server connection"); + console.log('tcp server connection'); - var buf = ""; - s.on('data', function (d) { + var buf = ''; + s.on('data', function(d) { buf += d; }); - s.on('end', function () { - assert.equal("foobar", buf); - console.log("tcp socket disconnect"); + s.on('end', function() { + assert.equal('foobar', buf); + console.log('tcp socket disconnect'); s.end(); }); - s.on('error', function (e) { - console.log("tcp server-side error: " + e.message); + s.on('error', function(e) { + console.log('tcp server-side error: ' + e.message); process.exit(1); }); }); tcp.listen(tcpPort, startClient); -function startClient () { +function startClient() { var socket = net.Stream(); - console.log("Connecting to socket"); + console.log('Connecting to socket'); socket.connect(tcpPort); - socket.on('connect', function () { + socket.on('connect', function() { console.log('socket connected'); }); - assert.equal("opening", socket.readyState); + assert.equal('opening', socket.readyState); - assert.equal(false, socket.write("foo")); - socket.end("bar"); + assert.equal(false, socket.write('foo')); + socket.end('bar'); - assert.equal("opening", socket.readyState); + assert.equal('opening', socket.readyState); } diff --git a/test/simple/test-net-connect-handle-econnrefused.js b/test/simple/test-net-connect-handle-econnrefused.js index e311e13756..6f2720f4d8 100644 --- a/test/simple/test-net-connect-handle-econnrefused.js +++ b/test/simple/test-net-connect-handle-econnrefused.js @@ -6,19 +6,19 @@ var assert = require('assert'); // Hopefully nothing is running on common.PORT var c = net.createConnection(common.PORT); -c.on('connect', function () { - console.error("connected?!"); +c.on('connect', function() { + console.error('connected?!'); assert.ok(false); }) var gotError = false; -c.on('error', function (e) { - console.error("couldn't connect."); +c.on('error', function(e) { + console.error('couldn\'t connect.'); gotError = true; assert.equal(require('constants').ECONNREFUSED, e.errno); }); -process.on('exit', function () { +process.on('exit', function() { assert.ok(gotError); }); diff --git a/test/simple/test-net-eaddrinuse.js b/test/simple/test-net-eaddrinuse.js index 38428c14c7..85f5942baf 100644 --- a/test/simple/test-net-eaddrinuse.js +++ b/test/simple/test-net-eaddrinuse.js @@ -2,9 +2,9 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); -var server1 = net.createServer(function (socket) { +var server1 = net.createServer(function(socket) { }); -var server2 = net.createServer(function (socket) { +var server2 = net.createServer(function(socket) { }); server1.listen(common.PORT); server2.addListener('error', function(error) { diff --git a/test/simple/test-net-isip.js b/test/simple/test-net-isip.js index 178a09e015..92ebaaf76d 100644 --- a/test/simple/test-net-isip.js +++ b/test/simple/test-net-isip.js @@ -2,21 +2,21 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); -assert.equal(net.isIP("127.0.0.1"), 4); -assert.equal(net.isIP("x127.0.0.1"), 0); -assert.equal(net.isIP("example.com"), 0); -assert.equal(net.isIP("0000:0000:0000:0000:0000:0000:0000:0000"), 6); -assert.equal(net.isIP("0000:0000:0000:0000:0000:0000:0000:0000::0000"), 0); -assert.equal(net.isIP("1050:0:0:0:5:600:300c:326b"), 6); -assert.equal(net.isIP("2001:252:0:1::2008:6"), 6); -assert.equal(net.isIP("2001:dead:beef:1::2008:6"), 6); -assert.equal(net.isIP("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 6); +assert.equal(net.isIP('127.0.0.1'), 4); +assert.equal(net.isIP('x127.0.0.1'), 0); +assert.equal(net.isIP('example.com'), 0); +assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:0000:0000'), 6); +assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:0000:0000::0000'), 0); +assert.equal(net.isIP('1050:0:0:0:5:600:300c:326b'), 6); +assert.equal(net.isIP('2001:252:0:1::2008:6'), 6); +assert.equal(net.isIP('2001:dead:beef:1::2008:6'), 6); +assert.equal(net.isIP('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'), 6); -assert.equal(net.isIPv4("127.0.0.1"), true); -assert.equal(net.isIPv4("example.com"), false); -assert.equal(net.isIPv4("2001:252:0:1::2008:6"), false); +assert.equal(net.isIPv4('127.0.0.1'), true); +assert.equal(net.isIPv4('example.com'), false); +assert.equal(net.isIPv4('2001:252:0:1::2008:6'), false); -assert.equal(net.isIPv6("127.0.0.1"), false); -assert.equal(net.isIPv4("example.com"), false); -assert.equal(net.isIPv6("2001:252:0:1::2008:6"), true); +assert.equal(net.isIPv6('127.0.0.1'), false); +assert.equal(net.isIPv4('example.com'), false); +assert.equal(net.isIPv6('2001:252:0:1::2008:6'), true); diff --git a/test/simple/test-net-keepalive.js b/test/simple/test-net-keepalive.js index 04a0506746..0a7be45ee0 100644 --- a/test/simple/test-net-keepalive.js +++ b/test/simple/test-net-keepalive.js @@ -3,26 +3,26 @@ var assert = require('assert'); var net = require('net'); var serverConnection; -var echoServer = net.createServer(function (connection) { +var echoServer = net.createServer(function(connection) { serverConnection = connection; connection.setTimeout(0); assert.notEqual(connection.setKeepAlive,undefined); // send a keepalive packet after 1000 ms connection.setKeepAlive(true,1000); - connection.addListener("end", function () { + connection.addListener('end', function() { connection.end(); }); }); echoServer.listen(common.PORT); -echoServer.addListener("listening", function() { +echoServer.addListener('listening', function() { var clientConnection = net.createConnection(common.PORT); clientConnection.setTimeout(0); setTimeout( function() { // make sure both connections are still open - assert.equal(serverConnection.readyState,"open"); - assert.equal(clientConnection.readyState,"open"); + assert.equal(serverConnection.readyState,'open'); + assert.equal(clientConnection.readyState,'open'); serverConnection.end(); clientConnection.end(); echoServer.close(); diff --git a/test/simple/test-net-pingpong.js b/test/simple/test-net-pingpong.js index 8898868196..4415f27bcb 100644 --- a/test/simple/test-net-pingpong.js +++ b/test/simple/test-net-pingpong.js @@ -10,8 +10,8 @@ function pingPongTest (port, host) { var count = 0; var sent_final_ping = false; - var server = net.createServer({ allowHalfOpen: true }, function (socket) { - console.log("connection: " + socket.remoteAddress); + var server = net.createServer({ allowHalfOpen: true }, function(socket) { + console.log('connection: ' + socket.remoteAddress); assert.equal(server, socket.server); assert.equal(1, server.connections); @@ -19,27 +19,27 @@ function pingPongTest (port, host) { socket.timeout = 0; socket.setEncoding('utf8'); - socket.addListener("data", function (data) { - console.log("server got: " + data); + socket.addListener('data', function(data) { + console.log('server got: ' + data); assert.equal(true, socket.writable); assert.equal(true, socket.readable); assert.equal(true, count <= N); if (/PING/.exec(data)) { - socket.write("PONG"); + socket.write('PONG'); } }); - socket.addListener("end", function () { + socket.addListener('end', function() { assert.equal(true, socket.writable); // because allowHalfOpen assert.equal(false, socket.readable); socket.end(); }); - socket.addListener("error", function (e) { + socket.addListener('error', function(e) { throw e; }); - socket.addListener("close", function () { + socket.addListener('close', function() { console.log('server socket.endd'); assert.equal(false, socket.writable); assert.equal(false, socket.readable); @@ -48,22 +48,22 @@ function pingPongTest (port, host) { }); - server.listen(port, host, function () { - console.log("server listening on " + port + " " + host); + server.listen(port, host, function() { + console.log('server listening on ' + port + ' ' + host); var client = net.createConnection(port, host); client.setEncoding('ascii'); - client.addListener("connect", function () { + client.addListener('connect', function() { assert.equal(true, client.readable); assert.equal(true, client.writable); - client.write("PING"); + client.write('PING'); }); - client.addListener("data", function (data) { - console.log("client got: " + data); + client.addListener('data', function(data) { + console.log('client got: ' + data); - assert.equal("PONG", data); + assert.equal('PONG', data); count += 1; if (sent_final_ping) { @@ -76,34 +76,34 @@ function pingPongTest (port, host) { } if (count < N) { - client.write("PING"); + client.write('PING'); } else { sent_final_ping = true; - client.write("PING"); + client.write('PING'); client.end(); } }); - client.addListener("close", function () { + client.addListener('close', function() { console.log('client.endd'); assert.equal(N+1, count); assert.equal(true, sent_final_ping); tests_run += 1; }); - client.addListener("error", function (e) { + client.addListener('error', function(e) { throw e; }); }); } /* All are run at once, so run on different ports */ -pingPongTest(20989, "localhost"); +pingPongTest(20989, 'localhost'); pingPongTest(20988); -pingPongTest(20997, "::1"); -pingPongTest("/tmp/pingpong.sock"); +pingPongTest(20997, '::1'); +pingPongTest('/tmp/pingpong.sock'); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(4, tests_run); console.log('done'); }); diff --git a/test/simple/test-net-reconnect.js b/test/simple/test-net-reconnect.js index 8e4e7eab85..02194d585a 100644 --- a/test/simple/test-net-reconnect.js +++ b/test/simple/test-net-reconnect.js @@ -1,46 +1,47 @@ var common = require('../common'); var assert = require('assert'); + var net = require('net'); -var N = 50; +var N = 50; var c = 0; var client_recv_count = 0; var disconnect_count = 0; -var server = net.createServer(function (socket) { - socket.addListener("connect", function () { - socket.write("hello\r\n"); +var server = net.createServer(function(socket) { + socket.addListener('connect', function() { + socket.write('hello\r\n'); }); - socket.addListener("end", function () { + socket.addListener('end', function() { socket.end(); }); - socket.addListener("close", function (had_error) { - //console.log("server had_error: " + JSON.stringify(had_error)); + socket.addListener('close', function(had_error) { + //console.log('server had_error: ' + JSON.stringify(had_error)); assert.equal(false, had_error); }); }); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { console.log('listening'); var client = net.createConnection(common.PORT); - client.setEncoding("UTF8"); + client.setEncoding('UTF8'); - client.addListener("connect", function () { - console.log("client connected."); + client.addListener('connect', function() { + console.log('client connected.'); }); - client.addListener("data", function (chunk) { + client.addListener('data', function(chunk) { client_recv_count += 1; - console.log("client_recv_count " + client_recv_count); - assert.equal("hello\r\n", chunk); + console.log('client_recv_count ' + client_recv_count); + assert.equal('hello\r\n', chunk); client.end(); }); - client.addListener("close", function (had_error) { - console.log("disconnect"); + client.addListener('close', function(had_error) { + console.log('disconnect'); assert.equal(false, had_error); if (disconnect_count++ < N) client.connect(common.PORT); // reconnect @@ -49,7 +50,7 @@ server.listen(common.PORT, function () { }); }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(N+1, disconnect_count); assert.equal(N+1, client_recv_count); }); diff --git a/test/simple/test-net-server-bind.js b/test/simple/test-net-server-bind.js index 62d6d6a2d5..2ed2e5577f 100644 --- a/test/simple/test-net-server-bind.js +++ b/test/simple/test-net-server-bind.js @@ -6,11 +6,11 @@ var net = require('net'); // With only a callback, server should get a port assigned by the OS var address0; -var server0 = net.createServer(function (socket) { }); +var server0 = net.createServer(function(socket) { }); server0.listen(function() { address0 = server0.address(); - console.log("address0 %j", address0); + console.log('address0 %j', address0); server0.close(); }); @@ -22,9 +22,9 @@ var server1 = net.createServer(function(socket) { }); server1.listen(common.PORT); -setTimeout(function () { +setTimeout(function() { address1 = server1.address() - console.log("address1 %j", address1); + console.log('address1 %j', address1); server1.close(); }, 100); @@ -34,15 +34,15 @@ setTimeout(function () { var address2; var server2 = net.createServer(function(socket) { }); -server2.listen(common.PORT+1, function () { +server2.listen(common.PORT+1, function() { address2 = server2.address() - console.log("address2 %j", address2); + console.log('address2 %j', address2); server2.close(); }); -process.on('exit', function () { +process.on('exit', function() { assert.ok(address0.port > 100); assert.equal(common.PORT, address1.port); assert.equal(common.PORT+1, address2.port); diff --git a/test/simple/test-net-server-max-connections.js b/test/simple/test-net-server-max-connections.js index 2b1bc295f5..f404ad5f3d 100644 --- a/test/simple/test-net-server-max-connections.js +++ b/test/simple/test-net-server-max-connections.js @@ -1,5 +1,6 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); + var net = require('net'); // This test creates 200 connections to a server and sets the server's @@ -13,13 +14,13 @@ var count = 0; var closes = 0; var waits = []; -var server = net.createServer(function (connection) { - console.error("connect %d", count++); - connection.write("hello"); - waits.push(function () { connection.end(); }); +var server = net.createServer(function(connection) { + console.error('connect %d', count++); + connection.write('hello'); + waits.push(function() { connection.end(); }); }); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { for (var i = 0; i < N; i++) { makeConnection(i); } @@ -27,37 +28,37 @@ server.listen(common.PORT, function () { server.maxConnections = N/2; -console.error("server.maxConnections = %d", server.maxConnections); +console.error('server.maxConnections = %d', server.maxConnections); function makeConnection (index) { - setTimeout(function () { + setTimeout(function() { var c = net.createConnection(common.PORT); var gotData = false; - c.on('end', function () { c.end(); }); + c.on('end', function() { c.end(); }); - c.on('data', function (b) { + c.on('data', function(b) { gotData = true; assert.ok(0 < b.length); }); - c.on('error', function (e) { - console.error("error %d: %s", index, e); + c.on('error', function(e) { + console.error('error %d: %s', index, e); }); - c.on('close', function () { - console.error("closed %d", index); + c.on('close', function() { + console.error('closed %d', index); closes++; if (closes < N/2) { assert.ok(server.maxConnections <= index, - index + " was one of the first closed connections but shouldnt have been"); + index + ' was one of the first closed connections but shouldnt have been'); } if (closes === N/2) { var cb; - console.error("calling wait callback."); + console.error('calling wait callback.'); while (cb = waits.shift()) { cb(); } @@ -65,15 +66,15 @@ function makeConnection (index) { } if (index < server.maxConnections) { - assert.equal(true, gotData, index + " didn't get data, but should have"); + assert.equal(true, gotData, index + ' didn\'t get data, but should have'); } else { - assert.equal(false, gotData, index + " got data, but shouldn't have"); + assert.equal(false, gotData, index + ' got data, but shouldn\'t have'); } }); }, index); } -process.on('exit', function () { +process.on('exit', function() { assert.equal(N, closes); }); diff --git a/test/simple/test-next-tick-errors.js b/test/simple/test-next-tick-errors.js index eec4546214..9188548c6d 100644 --- a/test/simple/test-next-tick-errors.js +++ b/test/simple/test-next-tick-errors.js @@ -31,6 +31,6 @@ process.addListener('uncaughtException', function() { }); process.addListener('exit', function() { - assert.deepEqual(['A','B','C'], order); + assert.deepEqual(['A', 'B', 'C'], order); }); diff --git a/test/simple/test-next-tick-ordering2.js b/test/simple/test-next-tick-ordering2.js index 33badf8642..20bf352cbd 100644 --- a/test/simple/test-next-tick-ordering2.js +++ b/test/simple/test-next-tick-ordering2.js @@ -10,7 +10,7 @@ process.nextTick(function() { process.nextTick(function() { order.push('nextTick'); }); -}) +}); process.addListener('exit', function() { assert.deepEqual(order, ['nextTick', 'setTimeout']); diff --git a/test/simple/test-next-tick.js b/test/simple/test-next-tick.js index 049cb98a31..45c6e96d72 100644 --- a/test/simple/test-next-tick.js +++ b/test/simple/test-next-tick.js @@ -3,27 +3,27 @@ var assert = require('assert'); var complete = 0; -process.nextTick(function () { +process.nextTick(function() { complete++; - process.nextTick(function () { + process.nextTick(function() { complete++; - process.nextTick(function () { + process.nextTick(function() { complete++; }); }); }); -setTimeout(function () { - process.nextTick(function () { +setTimeout(function() { + process.nextTick(function() { complete++; }); }, 50); -process.nextTick(function () { +process.nextTick(function() { complete++; }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.equal(5, complete); }); diff --git a/test/simple/test-path.js b/test/simple/test-path.js index f97fd15edf..cb78071c2c 100644 --- a/test/simple/test-path.js +++ b/test/simple/test-path.js @@ -1,41 +1,42 @@ -var path = require("path"); var common = require('../common'); var assert = require('assert'); +var path = require('path'); + var f = __filename; -assert.equal(path.basename(f), "test-path.js"); -assert.equal(path.basename(f, ".js"), "test-path"); -assert.equal(path.extname(f), ".js"); -assert.equal(path.dirname(f).substr(-11), "test/simple"); -assert.equal(path.dirname("/a/b/"), "/a"); -assert.equal(path.dirname("/a/b"), "/a"); -assert.equal(path.dirname("/a"), "/"); -assert.equal(path.dirname("/"), "/"); -path.exists(f, function (y) { assert.equal(y, true) }); +assert.equal(path.basename(f), 'test-path.js'); +assert.equal(path.basename(f, '.js'), 'test-path'); +assert.equal(path.extname(f), '.js'); +assert.equal(path.dirname(f).substr(-11), 'test/simple'); +assert.equal(path.dirname('/a/b/'), '/a'); +assert.equal(path.dirname('/a/b'), '/a'); +assert.equal(path.dirname('/a'), '/'); +assert.equal(path.dirname('/'), '/'); +path.exists(f, function(y) { assert.equal(y, true) }); assert.equal(path.existsSync(f), true); -assert.equal(path.extname(""), ""); -assert.equal(path.extname("/path/to/file"), ""); -assert.equal(path.extname("/path/to/file.ext"), ".ext"); -assert.equal(path.extname("/path.to/file.ext"), ".ext"); -assert.equal(path.extname("/path.to/file"), ""); -assert.equal(path.extname("/path.to/.file"), ""); -assert.equal(path.extname("/path.to/.file.ext"), ".ext"); -assert.equal(path.extname("/path/to/f.ext"), ".ext"); -assert.equal(path.extname("/path/to/..ext"), ".ext"); -assert.equal(path.extname("file"), ""); -assert.equal(path.extname("file.ext"), ".ext"); -assert.equal(path.extname(".file"), ""); -assert.equal(path.extname(".file.ext"), ".ext"); -assert.equal(path.extname("/file"), ""); -assert.equal(path.extname("/file.ext"), ".ext"); -assert.equal(path.extname("/.file"), ""); -assert.equal(path.extname("/.file.ext"), ".ext"); -assert.equal(path.extname(".path/file.ext"), ".ext"); -assert.equal(path.extname("file.ext.ext"), ".ext"); -assert.equal(path.extname("file."), "."); +assert.equal(path.extname(''), ''); +assert.equal(path.extname('/path/to/file'), ''); +assert.equal(path.extname('/path/to/file.ext'), '.ext'); +assert.equal(path.extname('/path.to/file.ext'), '.ext'); +assert.equal(path.extname('/path.to/file'), ''); +assert.equal(path.extname('/path.to/.file'), ''); +assert.equal(path.extname('/path.to/.file.ext'), '.ext'); +assert.equal(path.extname('/path/to/f.ext'), '.ext'); +assert.equal(path.extname('/path/to/..ext'), '.ext'); +assert.equal(path.extname('file'), ''); +assert.equal(path.extname('file.ext'), '.ext'); +assert.equal(path.extname('.file'), ''); +assert.equal(path.extname('.file.ext'), '.ext'); +assert.equal(path.extname('/file'), ''); +assert.equal(path.extname('/file.ext'), '.ext'); +assert.equal(path.extname('/.file'), ''); +assert.equal(path.extname('/.file.ext'), '.ext'); +assert.equal(path.extname('.path/file.ext'), '.ext'); +assert.equal(path.extname('file.ext.ext'), '.ext'); +assert.equal(path.extname('file.'), '.'); // path.join tests var failures = []; @@ -91,30 +92,30 @@ var joinTests = // filtration of non-strings. ,[['x', true, 7, 'y', null, {} ], 'x/y' ] ]; -joinTests.forEach(function (test) { +joinTests.forEach(function(test) { var actual = path.join.apply(path, test[0]); var expected = test[1]; - var message = "path.join("+test[0].map(JSON.stringify).join(",")+")" - + "\n expect="+JSON.stringify(expected) - + "\n actual="+JSON.stringify(actual); - if (actual !== expected) failures.push("\n"+message); + var message = 'path.join('+test[0].map(JSON.stringify).join(',')+')' + + '\n expect='+JSON.stringify(expected) + + '\n actual='+JSON.stringify(actual); + if (actual !== expected) failures.push('\n'+message); // assert.equal(actual, expected, message); }); -assert.equal(failures.length, 0, failures.join("")) +assert.equal(failures.length, 0, failures.join('')) -assert.equal(path.normalize("./fixtures///b/../b/c.js"), "fixtures/b/c.js"); -assert.equal(path.normalize("./fixtures///b/../b/c.js",true), "fixtures///b/c.js"); -assert.equal(path.normalize("/foo/../../../bar"), "/bar"); +assert.equal(path.normalize('./fixtures///b/../b/c.js'), 'fixtures/b/c.js'); +assert.equal(path.normalize('./fixtures///b/../b/c.js',true), 'fixtures///b/c.js'); +assert.equal(path.normalize('/foo/../../../bar'), '/bar'); -assert.deepEqual(path.normalizeArray(["fixtures","b","","..","b","c.js"]), ["fixtures","b","c.js"]); -assert.deepEqual(path.normalizeArray(["fixtures","","b","..","b","c.js"], true), ["fixtures","","b","c.js"]); +assert.deepEqual(path.normalizeArray(['fixtures','b','','..','b','c.js']), ['fixtures','b','c.js']); +assert.deepEqual(path.normalizeArray(['fixtures','','b','..','b','c.js'], true), ['fixtures','','b','c.js']); -assert.equal(path.normalize("a//b//../b", true), "a//b/b"); -assert.equal(path.normalize("a//b//../b"), "a/b"); +assert.equal(path.normalize('a//b//../b', true), 'a//b/b'); +assert.equal(path.normalize('a//b//../b'), 'a/b'); -assert.equal(path.normalize("a//b//./c", true), "a//b//c"); -assert.equal(path.normalize("a//b//./c"), "a/b/c"); -assert.equal(path.normalize("a//b//.", true), "a//b/"); -assert.equal(path.normalize("a//b//."), "a/b"); +assert.equal(path.normalize('a//b//./c', true), 'a//b//c'); +assert.equal(path.normalize('a//b//./c'), 'a/b/c'); +assert.equal(path.normalize('a//b//.', true), 'a//b/'); +assert.equal(path.normalize('a//b//.'), 'a/b'); diff --git a/test/simple/test-pipe-head.js b/test/simple/test-pipe-head.js index 3a79e9bb0f..5fe595de7f 100644 --- a/test/simple/test-pipe-head.js +++ b/test/simple/test-pipe-head.js @@ -1,5 +1,6 @@ var common = require('../common'); var assert = require('assert'); + var exec = require('child_process').exec; var join = require('path').join; @@ -10,7 +11,7 @@ var cmd = nodePath + ' ' + script + ' | head -2'; var finished = false; -exec(cmd, function (err, stdout, stderr) { +exec(cmd, function(err, stdout, stderr) { if (err) throw err; var lines = stdout.split('\n'); assert.equal(3, lines.length); @@ -18,6 +19,6 @@ exec(cmd, function (err, stdout, stderr) { }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.ok(finished); }); diff --git a/test/simple/test-pipe.js b/test/simple/test-pipe.js index 75db48eabb..f52a875ce6 100644 --- a/test/simple/test-pipe.js +++ b/test/simple/test-pipe.js @@ -3,7 +3,7 @@ var assert = require('assert'); var http = require('http'); var net = require('net'); -var webPort = common.PORT +var webPort = common.PORT; var tcpPort = webPort + 1; var listenCount = 0; @@ -17,33 +17,33 @@ var bufferSize = 5 * 1024 * 1024; */ var buffer = Buffer(bufferSize); for (var i = 0; i < buffer.length; i++) { - buffer[i] = parseInt(Math.random()*10000) % 256; + buffer[i] = parseInt(Math.random() * 10000) % 256; } -var web = http.Server(function (req, res) { +var web = http.Server(function(req, res) { web.close(); console.log(req.headers); var socket = net.Stream(); socket.connect(tcpPort); - - socket.on('connect', function () { + + socket.on('connect', function() { console.log('socket connected'); }); req.pipe(socket); - req.on('end', function () { + req.on('end', function() { res.writeHead(200); - res.write("thanks"); + res.write('thanks'); res.end(); - console.log("response with 'thanks'"); + console.log('response with \'thanks\''); }); - req.connection.on('error', function (e) { - console.log("http server-side error: " + e.message); + req.connection.on('error', function(e) { + console.log('http server-side error: ' + e.message); process.exit(1); }); }); @@ -51,15 +51,15 @@ web.listen(webPort, startClient); -var tcp = net.Server(function (s) { +var tcp = net.Server(function(s) { tcp.close(); - console.log("tcp server connection"); + console.log('tcp server connection'); var i = 0; - s.on('data', function (d) { - process.stdout.write("."); + s.on('data', function(d) { + process.stdout.write('.'); tcpLengthSeen += d.length; for (var j = 0; j < d.length; j++) { assert.equal(buffer[i], d[j]); @@ -67,41 +67,41 @@ var tcp = net.Server(function (s) { } }); - s.on('end', function () { - console.log("tcp socket disconnect"); + s.on('end', function() { + console.log('tcp socket disconnect'); s.end(); }); - s.on('error', function (e) { - console.log("tcp server-side error: " + e.message); + s.on('error', function(e) { + console.log('tcp server-side error: ' + e.message); process.exit(1); }); }); tcp.listen(tcpPort, startClient); -function startClient () { +function startClient() { listenCount++; if (listenCount < 2) return; - console.log("Making request"); + console.log('Making request'); var client = http.createClient(common.PORT); var req = client.request('GET', '/', { 'content-length': buffer.length }); req.write(buffer); req.end(); - req.on('response', function (res) { + req.on('response', function(res) { console.log('Got response'); res.setEncoding('utf8'); - res.on('data', function (string) { - assert.equal("thanks", string); + res.on('data', function(string) { + assert.equal('thanks', string); gotThanks = true; }); }); } -process.on('exit', function () { +process.on('exit', function() { assert.ok(gotThanks); assert.equal(bufferSize, tcpLengthSeen); }); diff --git a/test/simple/test-pump-file2tcp-noexist.js b/test/simple/test-pump-file2tcp-noexist.js index b2f608e4a9..d7b59b150c 100644 --- a/test/simple/test-pump-file2tcp-noexist.js +++ b/test/simple/test-pump-file2tcp-noexist.js @@ -9,34 +9,34 @@ var fn = path.join(common.fixturesDir, 'does_not_exist.txt'); var got_error = false; var conn_closed = false; -var server = net.createServer(function (stream) { +var server = net.createServer(function(stream) { common.error('pump!'); - util.pump(fs.createReadStream(fn), stream, function (err) { - common.error("util.pump's callback fired"); + util.pump(fs.createReadStream(fn), stream, function(err) { + common.error('util.pump\'s callback fired'); if (err) { got_error = true; } else { - common.debug("util.pump's callback fired with no error"); - common.debug("this shouldn't happen as the file doesn't exist..."); + common.debug('util.pump\'s callback fired with no error'); + common.debug('this shouldn\'t happen as the file doesn\'t exist...'); assert.equal(true, false); } server.close(); }); }); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var conn = net.createConnection(common.PORT); conn.setEncoding('utf8'); - conn.addListener("data", function (chunk) { + conn.addListener('data', function(chunk) { common.error('recv data! nchars = ' + chunk.length); buffer += chunk; }); - conn.addListener("end", function () { + conn.addListener('end', function() { conn.end(); }); - conn.addListener("close", function () { + conn.addListener('close', function() { common.error('client connection close'); conn_closed = true; }); @@ -44,8 +44,8 @@ server.listen(common.PORT, function () { var buffer = ''; -process.addListener('exit', function () { +process.addListener('exit', function() { assert.equal(true, got_error); assert.equal(true, conn_closed); - console.log("exiting"); + console.log('exiting'); }); diff --git a/test/simple/test-pump-file2tcp.js b/test/simple/test-pump-file2tcp.js index 9622b861cc..56eba6da53 100644 --- a/test/simple/test-pump-file2tcp.js +++ b/test/simple/test-pump-file2tcp.js @@ -8,27 +8,27 @@ var fn = path.join(common.fixturesDir, 'elipses.txt'); var expected = fs.readFileSync(fn, 'utf8'); -var server = net.createServer(function (stream) { +var server = net.createServer(function(stream) { common.error('pump!'); - util.pump(fs.createReadStream(fn), stream, function () { + util.pump(fs.createReadStream(fn), stream, function() { common.error('server stream close'); common.error('server close'); server.close(); }); }); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var conn = net.createConnection(common.PORT); conn.setEncoding('utf8'); - conn.addListener("data", function (chunk) { + conn.addListener('data', function(chunk) { common.error('recv data! nchars = ' + chunk.length); buffer += chunk; }); - conn.addListener("end", function () { + conn.addListener('end', function() { conn.end(); }); - conn.addListener("close", function () { + conn.addListener('close', function() { common.error('client connection close'); }); }); @@ -36,9 +36,9 @@ server.listen(common.PORT, function () { var buffer = ''; var count = 0; -server.addListener('listening', function () { +server.addListener('listening', function() { }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.equal(expected, buffer); }); diff --git a/test/simple/test-querystring.js b/test/simple/test-querystring.js index c84ebcb1fc..0327191d70 100644 --- a/test/simple/test-querystring.js +++ b/test/simple/test-querystring.js @@ -1,154 +1,163 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); // test using assert -var qs = require("querystring"); +var qs = require('querystring'); -// folding block. -{ +// folding block, commented to pass gjslint +// {{{ // [ wonkyQS, canonicalQS, obj ] var qsTestCases = [ - ["foo=918854443121279438895193", "foo=918854443121279438895193", {"foo": "918854443121279438895193"}], - ["foo=bar", "foo=bar", {"foo" : "bar"}], - ["foo=bar&foo=quux", "foo=bar&foo=quux", {"foo" : ["bar", "quux"]}], - ["foo=1&bar=2", "foo=1&bar=2", {"foo" : "1", "bar" : "2"}], - ["my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F", "my%20weird%20field=q1!2%22'w%245%267%2Fz8)%3F", {"my weird field" : "q1!2\"'w$5&7/z8)?" }], - ["foo%3Dbaz=bar", "foo%3Dbaz=bar", {"foo=baz" : "bar"}], - ["foo=baz=bar", "foo=baz%3Dbar", {"foo" : "baz=bar"}], - [ "str=foo&arr=1&arr=2&arr=3&somenull=&undef=", "str=foo&arr=1&arr=2&arr=3&somenull=&undef=", { - "str":"foo", - "arr":["1","2","3"], - "somenull":"", - "undef":"" - }], - [" foo = bar ", "%20foo%20=%20bar%20", {" foo ":" bar "}], - ["foo=%zx", "foo=%25zx", {"foo":"%zx"}], - ["foo=%EF%BF%BD", "foo=%EF%BF%BD", {"foo" : "\ufffd" }] + ['foo=918854443121279438895193', + 'foo=918854443121279438895193', + {'foo': '918854443121279438895193'}], + ['foo=bar', 'foo=bar', {'foo': 'bar'}], + ['foo=bar&foo=quux', 'foo=bar&foo=quux', {'foo': ['bar', 'quux']}], + ['foo=1&bar=2', 'foo=1&bar=2', {'foo': '1', 'bar': '2'}], + ['my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F', + 'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F', + {'my weird field': 'q1!2"\'w$5&7/z8)?' }], + ['foo%3Dbaz=bar', 'foo%3Dbaz=bar', {'foo=baz': 'bar'}], + ['foo=baz=bar', 'foo=baz%3Dbar', {'foo': 'baz=bar'}], + ['str=foo&arr=1&arr=2&arr=3&somenull=&undef=', + 'str=foo&arr=1&arr=2&arr=3&somenull=&undef=', + { 'str': 'foo', + 'arr': ['1', '2', '3'], + 'somenull': '', + 'undef': ''}], + [' foo = bar ', '%20foo%20=%20bar%20', {' foo ': ' bar '}], + ['foo=%zx', 'foo=%25zx', {'foo': '%zx'}], + ['foo=%EF%BF%BD', 'foo=%EF%BF%BD', {'foo': '\ufffd' }] ]; // [ wonkyQS, canonicalQS, obj ] var qsColonTestCases = [ - ["foo:bar", "foo:bar", {"foo":"bar"}], - ["foo:bar;foo:quux", "foo:bar;foo:quux", {"foo" : ["bar", "quux"]}], - ["foo:1&bar:2;baz:quux", "foo:1%26bar%3A2;baz:quux", {"foo":"1&bar:2", "baz":"quux"}], - ["foo%3Abaz:bar", "foo%3Abaz:bar", {"foo:baz":"bar"}], - ["foo:baz:bar", "foo:baz%3Abar", {"foo":"baz:bar"}] + ['foo:bar', 'foo:bar', {'foo': 'bar'}], + ['foo:bar;foo:quux', 'foo:bar;foo:quux', {'foo': ['bar', 'quux']}], + ['foo:1&bar:2;baz:quux', + 'foo:1%26bar%3A2;baz:quux', + {'foo': '1&bar:2', 'baz': 'quux'}], + ['foo%3Abaz:bar', 'foo%3Abaz:bar', {'foo:baz': 'bar'}], + ['foo:baz:bar', 'foo:baz%3Abar', {'foo': 'baz:bar'}] ]; -// [ wonkyObj, qs, canonicalObj ] -var extendedFunction = function () {}; -extendedFunction.prototype = {a:"b"}; +// [wonkyObj, qs, canonicalObj] +var extendedFunction = function() {}; +extendedFunction.prototype = {a: 'b'}; var qsWeirdObjects = [ - [ {regexp:/./g}, "regexp=", {"regexp":""} ], - [ {regexp: new RegExp(".", "g")}, "regexp=", {"regexp":""} ], - [ {fn:function () {}}, "fn=", {"fn":""}], - [ {fn:new Function("")}, "fn=", {"fn":""} ], - [ {math:Math}, "math=", {"math":""} ], - [ {e:extendedFunction}, "e=", {"e":""} ], - [ {d:new Date()}, "d=", {"d":""} ], - [ {d:Date}, "d=", {"d":""} ], - [ {f:new Boolean(false), t:new Boolean(true)}, "f=&t=", {"f":"", "t":""} ], - [ {f:false, t:true}, "f=false&t=true", {"f":"false", "t":"true"} ], - [ {n:null}, "n=", {"n":""} ], - [ {nan:NaN}, "nan=", {"nan":""} ], - [ {inf:Infinity}, "inf=", {"inf":""} ] + [{regexp: /./g}, 'regexp=', {'regexp': ''}], + [{regexp: new RegExp('.', 'g')}, 'regexp=', {'regexp': ''}], + [{fn: function() {}}, 'fn=', {'fn': ''}], + [{fn: new Function('')}, 'fn=', {'fn': ''}], + [{math: Math}, 'math=', {'math': ''}], + [{e: extendedFunction}, 'e=', {'e': ''}], + [{d: new Date()}, 'd=', {'d': ''}], + [{d: Date}, 'd=', {'d': ''}], + [{f: new Boolean(false), t: new Boolean(true)}, 'f=&t=', {'f': '', 't': ''}], + [{f: false, t: true}, 'f=false&t=true', {'f': 'false', 't': 'true'}], + [{n: null}, 'n=', {'n': ''}], + [{nan: NaN}, 'nan=', {'nan': ''}], + [{inf: Infinity}, 'inf=', {'inf': ''}] ]; -} +// }}} var Script = require('vm').Script; -var foreignObject = Script.runInContext('({"foo": ["bar", "baz"]})', Script.createContext()); +var foreignObject = Script.runInContext('({"foo": ["bar", "baz"]})', + Script.createContext()); var qsNoMungeTestCases = [ - ["", {}], - ["foo=bar&foo=baz", {"foo": ["bar", "baz"]}], - ["foo=bar&foo=baz", foreignObject], - ["blah=burp", {"blah": "burp"}], - ["gragh=1&gragh=3&goo=2", {"gragh": ["1", "3"], "goo": "2"}], - ["frappucino=muffin&goat%5B%5D=scone&pond=moose", - {"frappucino": "muffin", "goat[]": "scone", "pond": "moose"}], - ["trololol=yes&lololo=no", {"trololol": "yes", "lololo": "no"}] + ['', {}], + ['foo=bar&foo=baz', {'foo': ['bar', 'baz']}], + ['foo=bar&foo=baz', foreignObject], + ['blah=burp', {'blah': 'burp'}], + ['gragh=1&gragh=3&goo=2', {'gragh': ['1', '3'], 'goo': '2'}], + ['frappucino=muffin&goat%5B%5D=scone&pond=moose', + {'frappucino': 'muffin', 'goat[]': 'scone', 'pond': 'moose'}], + ['trololol=yes&lololo=no', {'trololol': 'yes', 'lololo': 'no'}] ]; -assert.strictEqual("918854443121279438895193", qs.parse("id=918854443121279438895193").id); +assert.strictEqual('918854443121279438895193', + qs.parse('id=918854443121279438895193').id); // test that the canonical qs is parsed properly. -qsTestCases.forEach(function (testCase) { +qsTestCases.forEach(function(testCase) { assert.deepEqual(testCase[2], qs.parse(testCase[0])); }); // test that the colon test cases can do the same -qsColonTestCases.forEach(function (testCase) { - assert.deepEqual(testCase[2], qs.parse(testCase[0], ";", ":")); +qsColonTestCases.forEach(function(testCase) { + assert.deepEqual(testCase[2], qs.parse(testCase[0], ';', ':')); }); // test the weird objects, that they get parsed properly -qsWeirdObjects.forEach(function (testCase) { +qsWeirdObjects.forEach(function(testCase) { assert.deepEqual(testCase[2], qs.parse(testCase[1])); }); -qsNoMungeTestCases.forEach(function (testCase) { - assert.deepEqual(testCase[0], qs.stringify(testCase[1], "&", "=", false)); +qsNoMungeTestCases.forEach(function(testCase) { + assert.deepEqual(testCase[0], qs.stringify(testCase[1], '&', '=', false)); }); // test the nested qs-in-qs case -(function(){ - var f = qs.parse("a=b&q=x%3Dy%26y%3Dz"); - f.q = qs.parse(f.q); - assert.deepEqual(f, { a : "b", q : { x : "y", y : "z" } }); +(function() { + var f = qs.parse('a=b&q=x%3Dy%26y%3Dz'); + f.q = qs.parse(f.q); + assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } }); })(); // nested in colon -(function(){ - var f = qs.parse("a:b;q:x%3Ay%3By%3Az", ";", ":"); - f.q = qs.parse(f.q, ";", ":"); - assert.deepEqual(f, { a : "b", q : { x : "y", y : "z" } }); +(function() { + var f = qs.parse('a:b;q:x%3Ay%3By%3Az', ';', ':'); + f.q = qs.parse(f.q, ';', ':'); + assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } }); })(); // now test stringifying // basic -qsTestCases.forEach(function (testCase) { +qsTestCases.forEach(function(testCase) { assert.equal(testCase[1], qs.stringify(testCase[2])); }); -qsColonTestCases.forEach(function (testCase) { - assert.equal(testCase[1], qs.stringify(testCase[2], ";", ":")); +qsColonTestCases.forEach(function(testCase) { + assert.equal(testCase[1], qs.stringify(testCase[2], ';', ':')); }); -qsWeirdObjects.forEach(function (testCase) { +qsWeirdObjects.forEach(function(testCase) { assert.equal(testCase[1], qs.stringify(testCase[0])); }); // nested var f = qs.stringify({ - a : "b", - q : qs.stringify({ - x : "y", - y : "z" + a: 'b', + q: qs.stringify({ + x: 'y', + y: 'z' }) }); -assert.equal(f, "a=b&q=x%3Dy%26y%3Dz"); +assert.equal(f, 'a=b&q=x%3Dy%26y%3Dz'); -assert.doesNotThrow(function () { +assert.doesNotThrow(function() { qs.parse(undefined); }); // nested in colon var f = qs.stringify({ - a : "b", - q : qs.stringify({ - x : "y", - y : "z" - }, ";", ":") -}, ";", ":"); -assert.equal(f, "a:b;q:x%3Ay%3By%3Az"); + a: 'b', + q: qs.stringify({ + x: 'y', + y: 'z' + }, ';', ':') +}, ';', ':'); +assert.equal(f, 'a:b;q:x%3Ay%3By%3Az'); assert.deepEqual({}, qs.parse()); -var b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb%0d%ac%a2%2f%9d%eb%d8%a2%e6') +var b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb' + + '%0d%ac%a2%2f%9d%eb%d8%a2%e6'); // assert.equal(0xd3, b[0]); assert.equal(0xf2, b[1]); diff --git a/test/simple/test-readdir.js b/test/simple/test-readdir.js index 739790248f..a2041d4cde 100644 --- a/test/simple/test-readdir.js +++ b/test/simple/test-readdir.js @@ -4,17 +4,16 @@ var path = require('path'); var fs = require('fs'); var got_error = false, - readdirDir = path.join(common.fixturesDir, "readdir") + readdirDir = path.join(common.fixturesDir, 'readdir'); -var files = ['are' - , 'dir' - , 'empty' - , 'files' - , 'for' - , 'just' - , 'testing.js' - , 'these' - ]; +var files = ['are', + 'dir', + 'empty', + 'files', + 'for', + 'just', + 'testing.js', + 'these']; console.log('readdirSync ' + readdirDir); @@ -23,10 +22,10 @@ console.dir(f); assert.deepEqual(files, f.sort()); -console.log("readdir " + readdirDir); -fs.readdir(readdirDir, function (err, f) { +console.log('readdir ' + readdirDir); +fs.readdir(readdirDir, function(err, f) { if (err) { - console.log("error"); + console.log('error'); got_error = true; } else { console.dir(f); @@ -34,7 +33,7 @@ fs.readdir(readdirDir, function (err, f) { } }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(false, got_error); - console.log("exit"); + console.log('exit'); }); diff --git a/test/simple/test-regression-object-prototype.js b/test/simple/test-regression-object-prototype.js index 4491afaae0..17fe1727d3 100644 --- a/test/simple/test-regression-object-prototype.js +++ b/test/simple/test-regression-object-prototype.js @@ -1,6 +1,6 @@ //console.log('puts before'); -Object.prototype.xadsadsdasasdxx = function () { +Object.prototype.xadsadsdasasdxx = function() { }; console.log('puts after'); diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js index 7d47ad2791..294eb23c77 100644 --- a/test/simple/test-repl.js +++ b/test/simple/test-repl.js @@ -3,30 +3,30 @@ var assert = require('assert'); common.globalCheck = false; -var net = require("net"), - repl = require("repl"), - message = "Read, Eval, Print Loop", - unix_socket_path = "/tmp/node-repl-sock", - prompt_unix = "node via Unix socket> ", - prompt_tcp = "node via TCP socket> ", - prompt_multiline = "... ", - server_tcp, server_unix, client_tcp, client_unix, timer; +var net = require('net'), + repl = require('repl'), + message = 'Read, Eval, Print Loop', + unix_socket_path = '/tmp/node-repl-sock', + prompt_unix = 'node via Unix socket> ', + prompt_tcp = 'node via TCP socket> ', + prompt_multiline = '... ', + server_tcp, server_unix, client_tcp, client_unix, timer; // absolute path to test/fixtures/a.js -var moduleFilename = require("path").join(common.fixturesDir, "a"); +var moduleFilename = require('path').join(common.fixturesDir, 'a'); common.error('repl test'); // function for REPL to run -invoke_me = function (arg) { - return "invoked " + arg; +invoke_me = function(arg) { + return 'invoked ' + arg; }; function send_expect(list) { if (list.length > 0) { var cur = list.shift(); - common.error("sending " + JSON.stringify(cur.send)); + common.error('sending ' + JSON.stringify(cur.send)); cur.client.expect = cur.expect; cur.client.list = list; @@ -44,111 +44,121 @@ function clean_up() { function error_test() { // The other stuff is done so reuse unix socket - var read_buffer = ""; + var read_buffer = ''; client_unix.removeAllListeners('data'); - client_unix.addListener('data', function (data) { + client_unix.addListener('data', function(data) { read_buffer += data.toString('ascii', 0, data.length); - common.error("Unix data: " + JSON.stringify(read_buffer) + ", expecting " + - (client_unix.expect.exec ? client_unix.expect : - JSON.stringify(client_unix.expect))); + common.error('Unix data: ' + JSON.stringify(read_buffer) + ', expecting ' + + (client_unix.expect.exec ? + client_unix.expect : + JSON.stringify(client_unix.expect))); if (read_buffer.indexOf(prompt_unix) !== -1) { assert.ok(read_buffer.match(client_unix.expect)); - common.error("match"); - read_buffer = ""; + common.error('match'); + read_buffer = ''; if (client_unix.list && client_unix.list.length > 0) { send_expect(client_unix.list); } else { - common.error("End of Error test, running TCP test."); + common.error('End of Error test, running TCP test.'); tcp_test(); } } else if (read_buffer === prompt_multiline) { // Check that you meant to send a multiline test assert.strictEqual(prompt_multiline, client_unix.expect); - read_buffer = ""; + read_buffer = ''; if (client_unix.list && client_unix.list.length > 0) { send_expect(client_unix.list); } else { - common.error("End of Error test, running TCP test.\n"); + common.error('End of Error test, running TCP test.\n'); tcp_test(); } } else { - common.error("didn't see prompt yet, buffering."); + common.error('didn\'t see prompt yet, buffering.'); } }); send_expect([ // Uncaught error throws and prints out - { client: client_unix, send: "throw new Error('test error');", expect: /^Error: test error/ }, + { client: client_unix, send: 'throw new Error(\'test error\');', + expect: /^Error: test error/ }, // Common syntax error is treated as multiline command - { client: client_unix, send: "function test_func() {", expect: prompt_multiline }, + { client: client_unix, send: 'function test_func() {', + expect: prompt_multiline }, // You can recover with the .break command - { client: client_unix, send: ".break", expect: prompt_unix }, + { client: client_unix, send: '.break', + expect: prompt_unix }, // Can parse valid JSON - { client: client_unix, send: "JSON.parse('{\"valid\": \"json\"}');", expect: "{ valid: 'json' }"}, - // invalid input to JSON.parse error is special case of syntax error, should throw - { client: client_unix, send: "JSON.parse('{invalid: \\'json\\'}');", - expect: /^SyntaxError: Unexpected token ILLEGAL/ } + { client: client_unix, send: 'JSON.parse(\'{"valid": "json"}\');', + expect: '{ valid: \'json\' }'}, + // invalid input to JSON.parse error is special case of syntax error, + // should throw + { client: client_unix, send: 'JSON.parse(\'{invalid: \\\'json\\\'}\');', + expect: /^SyntaxError: Unexpected token ILLEGAL/ } ]); } function tcp_test() { - server_tcp = net.createServer(function (socket) { + server_tcp = net.createServer(function(socket) { assert.strictEqual(server_tcp, socket.server); assert.strictEqual(server_tcp.type, 'tcp4'); - socket.addListener("end", function () { + socket.addListener('end', function() { socket.end(); }); repl.start(prompt_tcp, socket); }); - server_tcp.listen(common.PORT, function () { - var read_buffer = ""; + server_tcp.listen(common.PORT, function() { + var read_buffer = ''; client_tcp = net.createConnection(common.PORT); - client_tcp.addListener('connect', function () { + client_tcp.addListener('connect', function() { assert.equal(true, client_tcp.readable); assert.equal(true, client_tcp.writable); send_expect([ - { client: client_tcp, send: "", expect: prompt_tcp }, - { client: client_tcp, send: "invoke_me(333)\n", expect: ('\'' + "invoked 333" + '\'\n' + prompt_tcp) }, - { client: client_tcp, send: "a += 1\n", expect: ("12346" + '\n' + prompt_tcp) }, + { client: client_tcp, send: '', + expect: prompt_tcp }, + { client: client_tcp, send: 'invoke_me(333)\n', + expect: ('\'' + 'invoked 333' + '\'\n' + prompt_tcp) }, + { client: client_tcp, send: 'a += 1\n', + expect: ('12346' + '\n' + prompt_tcp) }, { client: client_tcp, - send: "require('" + moduleFilename + "').number\n", - expect: ("42" + '\n' + prompt_tcp) } + send: 'require(\'' + moduleFilename + '\').number\n', + expect: ('42' + '\n' + prompt_tcp) } ]); }); - client_tcp.addListener('data', function (data) { + client_tcp.addListener('data', function(data) { read_buffer += data.toString('ascii', 0, data.length); - common.error("TCP data: " + JSON.stringify(read_buffer) + ", expecting " + JSON.stringify(client_tcp.expect)); + common.error('TCP data: ' + JSON.stringify(read_buffer) + + ', expecting ' + JSON.stringify(client_tcp.expect)); if (read_buffer.indexOf(prompt_tcp) !== -1) { assert.strictEqual(client_tcp.expect, read_buffer); - common.error("match"); - read_buffer = ""; + common.error('match'); + read_buffer = ''; if (client_tcp.list && client_tcp.list.length > 0) { send_expect(client_tcp.list); } else { - common.error("End of TCP test.\n"); + common.error('End of TCP test.\n'); clean_up(); } } else { - common.error("didn't see prompt yet, buffering"); + common.error('didn\'t see prompt yet, buffering'); } }); - client_tcp.addListener("error", function (e) { + client_tcp.addListener('error', function(e) { throw e; }); - client_tcp.addListener("close", function () { + client_tcp.addListener('close', function() { server_tcp.close(); }); }); @@ -156,57 +166,62 @@ function tcp_test() { } function unix_test() { - server_unix = net.createServer(function (socket) { + server_unix = net.createServer(function(socket) { assert.strictEqual(server_unix, socket.server); assert.strictEqual(server_unix.type, 'unix'); - socket.addListener("end", function () { + socket.addListener('end', function() { socket.end(); }); repl.start(prompt_unix, socket).context.message = message; }); - server_unix.addListener('listening', function () { - var read_buffer = ""; + server_unix.addListener('listening', function() { + var read_buffer = ''; client_unix = net.createConnection(unix_socket_path); - client_unix.addListener('connect', function () { + client_unix.addListener('connect', function() { assert.equal(true, client_unix.readable); assert.equal(true, client_unix.writable); send_expect([ - { client: client_unix, send: "", expect: prompt_unix }, - { client: client_unix, send: "message\n", expect: ('\'' + message + '\'\n' + prompt_unix) }, - { client: client_unix, send: "invoke_me(987)\n", expect: ('\'' + "invoked 987" + '\'\n' + prompt_unix) }, - { client: client_unix, send: "a = 12345\n", expect: ("12345" + '\n' + prompt_unix) } + { client: client_unix, send: '', + expect: prompt_unix }, + { client: client_unix, send: 'message\n', + expect: ('\'' + message + '\'\n' + prompt_unix) }, + { client: client_unix, send: 'invoke_me(987)\n', + expect: ('\'' + 'invoked 987' + '\'\n' + prompt_unix) }, + { client: client_unix, send: 'a = 12345\n', + expect: ('12345' + '\n' + prompt_unix) } ]); }); - client_unix.addListener('data', function (data) { + client_unix.addListener('data', function(data) { read_buffer += data.toString('ascii', 0, data.length); - common.error("Unix data: " + JSON.stringify(read_buffer) + ", expecting " + JSON.stringify(client_unix.expect)); + common.error('Unix data: ' + JSON.stringify(read_buffer) + + ', expecting ' + JSON.stringify(client_unix.expect)); if (read_buffer.indexOf(prompt_unix) !== -1) { assert.strictEqual(client_unix.expect, read_buffer); - common.error("match"); - read_buffer = ""; + common.error('match'); + read_buffer = ''; if (client_unix.list && client_unix.list.length > 0) { send_expect(client_unix.list); } else { - common.error("End of Unix test, running Error test.\n"); + common.error('End of Unix test, running Error test.\n'); process.nextTick(error_test); } } else { - common.error("didn't see prompt yet, buffering."); + common.error('didn\'t see prompt yet, buffering.'); } }); - client_unix.addListener("error", function (e) { + client_unix.addListener('error', function(e) { throw e; }); - client_unix.addListener("close", function () { + client_unix.addListener('close', function() { server_unix.close(); }); }); @@ -216,6 +231,6 @@ function unix_test() { unix_test(); -timer = setTimeout(function () { - assert.fail("Timeout"); +timer = setTimeout(function() { + assert.fail('Timeout'); }, 1000); diff --git a/test/simple/test-require-resolve.js b/test/simple/test-require-resolve.js index 37bb284606..171478f7fb 100644 --- a/test/simple/test-require-resolve.js +++ b/test/simple/test-require-resolve.js @@ -1,14 +1,14 @@ -var common = require("../common"); +var common = require('../common'); var fixturesDir = common.fixturesDir; var assert = common.assert; -var path = require("path"); +var path = require('path'); -assert.equal(path.join(__dirname, "../fixtures/a.js"), - require.resolve("../fixtures/a")); -assert.equal(path.join(fixturesDir, "a.js"), - require.resolve(path.join(fixturesDir, "a"))); -assert.equal(path.join(fixturesDir, "nested-index", "one", "index.js"), - require.resolve("../fixtures/nested-index/one")); -assert.equal("path", require.resolve("path")); +assert.equal(path.join(__dirname, '../fixtures/a.js'), + require.resolve('../fixtures/a')); +assert.equal(path.join(fixturesDir, 'a.js'), + require.resolve(path.join(fixturesDir, 'a'))); +assert.equal(path.join(fixturesDir, 'nested-index', 'one', 'index.js'), + require.resolve('../fixtures/nested-index/one')); +assert.equal('path', require.resolve('path')); -console.log("ok"); +console.log('ok'); diff --git a/test/simple/test-script-new.js b/test/simple/test-script-new.js index 29041df5b8..e513126f29 100644 --- a/test/simple/test-script-new.js +++ b/test/simple/test-script-new.js @@ -5,7 +5,7 @@ var Script = require('vm').Script; common.globalCheck = false; common.debug('run a string'); -var script = new Script('"passed";'); +var script = new Script('\'passed\';'); common.debug('script created'); var result1 = script.runInNewContext(); var result2 = script.runInNewContext(); @@ -13,7 +13,7 @@ assert.equal('passed', result1); assert.equal('passed', result2); common.debug('thrown error'); -script = new Script('throw new Error("test");'); +script = new Script('throw new Error(\'test\');'); assert.throws(function() { script.runInNewContext(); }); @@ -40,33 +40,33 @@ script.runInNewContext(); assert.equal(5, hello); -common.debug("pass values in and out"); -code = "foo = 1;" - + "bar = 2;" - + "if (baz !== 3) throw new Error('test fail');"; +common.debug('pass values in and out'); +code = 'foo = 1;' + + 'bar = 2;' + + 'if (baz !== 3) throw new Error(\'test fail\');'; foo = 2; -obj = { foo : 0, baz : 3 }; +obj = { foo: 0, baz: 3 }; script = new Script(code); var baz = script.runInNewContext(obj); assert.equal(1, obj.foo); assert.equal(2, obj.bar); assert.equal(2, foo); -common.debug("call a function by reference"); -script = new Script("f()"); -function changeFoo () { foo = 100 } -script.runInNewContext({ f : changeFoo }); +common.debug('call a function by reference'); +script = new Script('f()'); +function changeFoo() { foo = 100 } +script.runInNewContext({ f: changeFoo }); assert.equal(foo, 100); -common.debug("modify an object by reference"); -script = new Script("f.a = 2"); -var f = { a : 1 }; -script.runInNewContext({ f : f }); +common.debug('modify an object by reference'); +script = new Script('f.a = 2'); +var f = { a: 1 }; +script.runInNewContext({ f: f }); assert.equal(f.a, 2); -common.debug("invalid this"); +common.debug('invalid this'); assert.throws(function() { - script.runInNewContext.call('"hello";'); + script.runInNewContext.call('\'hello\';'); }); diff --git a/test/simple/test-script-static-new.js b/test/simple/test-script-static-new.js index 426029dce8..502e0a8d47 100644 --- a/test/simple/test-script-static-new.js +++ b/test/simple/test-script-static-new.js @@ -5,12 +5,12 @@ var Script = require('vm').Script; common.globalCheck = false; common.debug('run a string'); -var result = Script.runInNewContext('"passed";'); +var result = Script.runInNewContext('\'passed\';'); assert.equal('passed', result); common.debug('thrown error'); assert.throws(function() { - Script.runInNewContext('throw new Error("test");'); + Script.runInNewContext('throw new Error(\'test\');'); }); hello = 5; @@ -18,24 +18,24 @@ Script.runInNewContext('hello = 2'); assert.equal(5, hello); -common.debug("pass values in and out"); -code = "foo = 1;" - + "bar = 2;" - + "if (baz !== 3) throw new Error('test fail');"; +common.debug('pass values in and out'); +code = 'foo = 1;' + + 'bar = 2;' + + 'if (baz !== 3) throw new Error(\'test fail\');'; foo = 2; -obj = { foo : 0, baz : 3 }; +obj = { foo: 0, baz: 3 }; var baz = Script.runInNewContext(code, obj); assert.equal(1, obj.foo); assert.equal(2, obj.bar); assert.equal(2, foo); -common.debug("call a function by reference"); -function changeFoo () { foo = 100 } -Script.runInNewContext("f()", { f : changeFoo }); +common.debug('call a function by reference'); +function changeFoo() { foo = 100 } +Script.runInNewContext('f()', { f: changeFoo }); assert.equal(foo, 100); -common.debug("modify an object by reference"); -var f = { a : 1 }; -Script.runInNewContext("f.a = 2", { f : f }); +common.debug('modify an object by reference'); +var f = { a: 1 }; +Script.runInNewContext('f.a = 2', { f: f }); assert.equal(f.a, 2); diff --git a/test/simple/test-script-static-this.js b/test/simple/test-script-static-this.js index 302ea65270..e46c4c7536 100644 --- a/test/simple/test-script-static-this.js +++ b/test/simple/test-script-static-this.js @@ -5,12 +5,12 @@ var Script = require('vm').Script; common.globalCheck = false; common.debug('run a string'); -var result = Script.runInThisContext('"passed";'); +var result = Script.runInThisContext('\'passed\';'); assert.equal('passed', result); common.debug('thrown error'); assert.throws(function() { - Script.runInThisContext('throw new Error("test");'); + Script.runInThisContext('throw new Error(\'test\');'); }); hello = 5; @@ -18,18 +18,18 @@ Script.runInThisContext('hello = 2'); assert.equal(2, hello); -common.debug("pass values"); -code = "foo = 1;" - + "bar = 2;" - + "if (typeof baz !== 'undefined') throw new Error('test fail');"; +common.debug('pass values'); +code = 'foo = 1;' + + 'bar = 2;' + + 'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');'; foo = 2; -obj = { foo : 0, baz : 3 }; +obj = { foo: 0, baz: 3 }; var baz = Script.runInThisContext(code); assert.equal(0, obj.foo); assert.equal(2, bar); assert.equal(1, foo); -common.debug("call a function"); -f = function () { foo = 100 }; -Script.runInThisContext("f()"); +common.debug('call a function'); +f = function() { foo = 100 }; +Script.runInThisContext('f()'); assert.equal(100, foo); diff --git a/test/simple/test-script-this.js b/test/simple/test-script-this.js index 677f68b386..c82c7e20ff 100644 --- a/test/simple/test-script-this.js +++ b/test/simple/test-script-this.js @@ -5,12 +5,12 @@ var Script = require('vm').Script; common.globalCheck = false; common.debug('run a string'); -var script = new Script('"passed";'); +var script = new Script('\'passed\';'); var result = script.runInThisContext(script); assert.equal('passed', result); common.debug('thrown error'); -script = new Script('throw new Error("test");'); +script = new Script('throw new Error(\'test\');'); assert.throws(function() { script.runInThisContext(script); }); @@ -21,20 +21,20 @@ script.runInThisContext(script); assert.equal(2, hello); -common.debug("pass values"); -code = "foo = 1;" - + "bar = 2;" - + "if (typeof baz !== 'undefined') throw new Error('test fail');"; +common.debug('pass values'); +code = 'foo = 1;' + + 'bar = 2;' + + 'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');'; foo = 2; -obj = { foo : 0, baz : 3 }; +obj = { foo: 0, baz: 3 }; script = new Script(code); script.runInThisContext(script); assert.equal(0, obj.foo); assert.equal(2, bar); assert.equal(1, foo); -common.debug("call a function"); -f = function () { foo = 100 }; -script = new Script("f()"); +common.debug('call a function'); +f = function() { foo = 100 }; +script = new Script('f()'); script.runInThisContext(script); assert.equal(100, foo); diff --git a/test/simple/test-securepair-client.js b/test/simple/test-securepair-client.js index 511c712ed7..1e48e23453 100644 --- a/test/simple/test-securepair-client.js +++ b/test/simple/test-securepair-client.js @@ -14,10 +14,10 @@ var PORT = common.PORT + 5; var connections = 0; -var keyfn = join(common.fixturesDir, "agent.key"); +var keyfn = join(common.fixturesDir, 'agent.key'); var key = fs.readFileSync(keyfn).toString(); -var certfn = join(common.fixturesDir, "agent.crt"); +var certfn = join(common.fixturesDir, 'agent.crt'); var cert = fs.readFileSync(certfn).toString(); var server = spawn('openssl', ['s_server', @@ -28,28 +28,28 @@ server.stdout.pipe(process.stdout); server.stderr.pipe(process.stdout); -var state = "WAIT-ACCEPT"; +var state = 'WAIT-ACCEPT'; -var serverStdoutBuffer = '' +var serverStdoutBuffer = ''; server.stdout.setEncoding('utf8'); -server.stdout.on('data', function (s) { +server.stdout.on('data', function(s) { serverStdoutBuffer += s; switch (state) { - case "WAIT-ACCEPT": + case 'WAIT-ACCEPT': if (/ACCEPT/g.test(serverStdoutBuffer)) { startClient(); - state = "WAIT-HELLO" + state = 'WAIT-HELLO'; } break; - case "WAIT-HELLO": + case 'WAIT-HELLO': if (/hello/g.test(serverStdoutBuffer)) { // End the current SSL connection and exit. // See s_server(1ssl). - server.stdin.write("Q"); + server.stdin.write('Q'); - state = "WAIT-SERVER-CLOSE"; + state = 'WAIT-SERVER-CLOSE'; } break; @@ -60,12 +60,12 @@ server.stdout.on('data', function (s) { var serverExitCode = -1; -server.on('exit', function (code) { +server.on('exit', function(code) { serverExitCode = code; }); -function startClient () { +function startClient() { var s = new net.Stream(); var sslcontext = crypto.createCredentials({key: key, cert: cert}); @@ -81,25 +81,27 @@ function startClient () { s.connect(PORT); - s.on('connect', function () { - console.log("client connected"); + s.on('connect', function() { + console.log('client connected'); }); - pair.on('secure', function () { + pair.on('secure', function() { console.log('client: connected+secure!'); - console.log('client pair.getPeerCertificate(): %j', pair.getPeerCertificate()); - console.log('client pair.getCipher(): %j', pair.getCipher()); - setTimeout(function () { + console.log('client pair.getPeerCertificate(): %j', + pair.getPeerCertificate()); + console.log('client pair.getCipher(): %j', + pair.getCipher()); + setTimeout(function() { pair.cleartext.write('hello\r\n'); }, 500); }); - pair.cleartext.on('data', function (d) { - console.log("cleartext: %s", d.toString()); + pair.cleartext.on('data', function(d) { + console.log('cleartext: %s', d.toString()); }); - s.on('close', function () { - console.log("client close"); + s.on('close', function() { + console.log('client close'); }); pair.encrypted.on('error', function(err) { @@ -116,7 +118,7 @@ function startClient () { } -process.on('exit', function () { +process.on('exit', function() { assert.equal(0, serverExitCode); - assert.equal("WAIT-SERVER-CLOSE", state); + assert.equal('WAIT-SERVER-CLOSE', state); }); diff --git a/test/simple/test-securepair-server.js b/test/simple/test-securepair-server.js index 905576acc9..8536a35dcc 100644 --- a/test/simple/test-securepair-server.js +++ b/test/simple/test-securepair-server.js @@ -8,14 +8,14 @@ var crypto = require('crypto'); var spawn = require('child_process').spawn; var connections = 0; -var key = fs.readFileSync(join(common.fixturesDir, "agent.key")).toString(); -var cert = fs.readFileSync(join(common.fixturesDir, "agent.crt")).toString(); +var key = fs.readFileSync(join(common.fixturesDir, 'agent.key')).toString(); +var cert = fs.readFileSync(join(common.fixturesDir, 'agent.crt')).toString(); -function log (a) { +function log(a) { console.error('***server*** ' + a); } -var server = net.createServer(function (socket) { +var server = net.createServer(function(socket) { connections++; log('connection fd=' + socket.fd); var sslcontext = crypto.createCredentials({key: key, cert: cert}); @@ -31,19 +31,19 @@ var server = net.createServer(function (socket) { log('i set it secure'); - pair.on('secure', function () { + pair.on('secure', function() { log('connected+secure!'); pair.cleartext.write('hello\r\n'); log(pair.getPeerCertificate()); log(pair.getCipher()); }); - pair.cleartext.on('data', function (data) { + pair.cleartext.on('data', function(data) { log('read bytes ' + data.length); pair.cleartext.write(data); }); - socket.on('end', function () { + socket.on('end', function() { log('socket end'); pair.cleartext.write('goodbye\r\n'); pair.cleartext.end(); @@ -87,7 +87,7 @@ var sentWorld = false; var gotWorld = false; var opensslExitCode = -1; -server.listen(8000, function () { +server.listen(8000, function() { // To test use: openssl s_client -connect localhost:8000 var client = spawn('openssl', ['s_client', '-connect', '127.0.0.1:8000']); @@ -95,7 +95,7 @@ server.listen(8000, function () { var out = ''; client.stdout.setEncoding('utf8'); - client.stdout.on('data', function (d) { + client.stdout.on('data', function(d) { out += d; if (!gotHello && /hello/.test(out)) { @@ -112,13 +112,13 @@ server.listen(8000, function () { client.stdout.pipe(process.stdout); - client.on('exit', function (code) { + client.on('exit', function(code) { opensslExitCode = code; server.close(); }); }); -process.on('exit', function () { +process.on('exit', function() { assert.equal(1, connections); assert.ok(gotHello); assert.ok(sentWorld); diff --git a/test/simple/test-sendfd.js b/test/simple/test-sendfd.js index 468413217b..6dd8000bf9 100644 --- a/test/simple/test-sendfd.js +++ b/test/simple/test-sendfd.js @@ -40,11 +40,9 @@ var DATA = { 'ord' : 0 }; -var SOCK_PATH = path.join( - __dirname, - '..', - path.basename(__filename, '.js') + '.sock' -); +var SOCK_PATH = path.join(__dirname, + '..', + path.basename(__filename, '.js') + '.sock'); var logChild = function(d) { if (typeof d == 'object') { @@ -108,7 +106,8 @@ srv.listen(SOCK_PATH); // Spawn a child running test/fixtures/recvfd.js var cp = child_process.spawn(process.argv[0], - [path.join(common.fixturesDir, 'recvfd.js'), SOCK_PATH]); + [path.join(common.fixturesDir, 'recvfd.js'), + SOCK_PATH]); cp.stdout.addListener('data', logChild); cp.stderr.addListener('data', logChild); diff --git a/test/simple/test-sigint-infinite-loop.js b/test/simple/test-sigint-infinite-loop.js index 3505f4a9a5..9bf424e024 100644 --- a/test/simple/test-sigint-infinite-loop.js +++ b/test/simple/test-sigint-infinite-loop.js @@ -4,32 +4,32 @@ var common = require('../common'); var assert = require('assert'); var spawn = require('child_process').spawn; -console.log("start"); +console.log('start'); var c = spawn(process.execPath, ['-e', 'while(true) { console.log("hi"); }']); var sentKill = false; var gotChildExit = true; -c.stdout.on('data', function (s) { +c.stdout.on('data', function(s) { // Prevent race condition: // Wait for the first bit of output from the child process - // so that we're sure that it's in the V8 event loop and not + // so that we're sure that it's in the V8 event loop and not // just in the startup phase of execution. if (!sentKill) { - c.kill('SIGINT') - console.log("SIGINT infinite-loop.js"); + c.kill('SIGINT'); + console.log('SIGINT infinite-loop.js'); sentKill = true; } }); -c.on('exit', function (code) { +c.on('exit', function(code) { assert.ok(code !== 0); - console.log("killed infinite-loop.js"); + console.log('killed infinite-loop.js'); gotChildExit = true; }); -process.on('exit', function () { +process.on('exit', function() { assert.ok(sentKill); assert.ok(gotChildExit); }); diff --git a/test/simple/test-signal-handler.js b/test/simple/test-signal-handler.js index 3c450524d0..906573a3ae 100644 --- a/test/simple/test-signal-handler.js +++ b/test/simple/test-signal-handler.js @@ -1,35 +1,35 @@ var common = require('../common'); var assert = require('assert'); -console.log("process.pid: " + process.pid); +console.log('process.pid: ' + process.pid); var first = 0, second = 0; -process.addListener('SIGUSR1', function () { - console.log("Interrupted by SIGUSR1"); +process.addListener('SIGUSR1', function() { + console.log('Interrupted by SIGUSR1'); first += 1; }); -process.addListener('SIGUSR1', function () { +process.addListener('SIGUSR1', function() { second += 1; - setTimeout(function () { - console.log("End."); + setTimeout(function() { + console.log('End.'); process.exit(0); }, 5); }); var i = 0; -setInterval(function () { - console.log("running process..." + ++i); +setInterval(function() { + console.log('running process...' + ++i); if (i == 5) { - process.kill(process.pid, "SIGUSR1"); + process.kill(process.pid, 'SIGUSR1'); } }, 1); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(1, first); assert.equal(1, second); }); diff --git a/test/simple/test-stdin-from-file.js b/test/simple/test-stdin-from-file.js index ae97290bc7..40e9093c3f 100644 --- a/test/simple/test-stdin-from-file.js +++ b/test/simple/test-stdin-from-file.js @@ -9,11 +9,20 @@ var tmpFile = join(common.fixturesDir, 'stdin.txt'); var cmd = process.argv[0] + ' ' + stdoutScript + ' < ' + tmpFile; -var string = "abc\nümlaut.\nsomething else\n" + - "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n"; +var string = 'abc\nümlaut.\nsomething else\n' + + '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,' + + '疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、' + + '云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' + + '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' + + '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + + '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + + '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' + + '采用封建制和郡县制并存的制度,' + + '它的建立保证了秦末乱世岭南地区社会秩序的稳定,' + + '有效的改善了岭南地区落后的政治、##济现状。\n'; -console.log(cmd + "\n\n"); +console.log(cmd + '\n\n'); try { fs.unlinkSync(tmpFile); @@ -26,6 +35,6 @@ childProccess.exec(cmd, function(err, stdout, stderr) { if (err) throw err; console.log(stdout); - assert.equal(stdout, "hello world\r\n" + string); - assert.equal("", stderr); + assert.equal(stdout, 'hello world\r\n' + string); + assert.equal('', stderr); }); diff --git a/test/simple/test-stdout-to-file.js b/test/simple/test-stdout-to-file.js index d5f7deadb0..a8d5357727 100644 --- a/test/simple/test-stdout-to-file.js +++ b/test/simple/test-stdout-to-file.js @@ -8,15 +8,14 @@ var scriptString = path.join(common.fixturesDir, 'print-chars.js'); var scriptBuffer = path.join(common.fixturesDir, 'print-chars-from-buffer.js'); var tmpFile = path.join(common.fixturesDir, 'stdout.txt'); -function test (size, useBuffer, cb) { - var cmd = process.argv[0] - + ' ' - + (useBuffer ? scriptBuffer : scriptString) - + ' ' - + size - + ' > ' - + tmpFile - ; +function test(size, useBuffer, cb) { + var cmd = process.argv[0] + + ' ' + + (useBuffer ? scriptBuffer : scriptString) + + ' ' + + size + + ' > ' + + tmpFile; try { fs.unlinkSync(tmpFile); @@ -41,14 +40,14 @@ function test (size, useBuffer, cb) { } var finished = false; -test(1024*1024, false, function () { - console.log("Done printing with string"); - test(1024*1024, true, function () { - console.log("Done printing with buffer"); +test(1024 * 1024, false, function() { + console.log('Done printing with string'); + test(1024 * 1024, true, function() { + console.log('Done printing with buffer'); finished = true; }); }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.ok(finished); });