summaryrefslogtreecommitdiff
path: root/test/simple
diff options
context:
space:
mode:
authorOleg Efimov <efimovov@gmail.com>2010-12-06 01:33:52 +0300
committerRyan Dahl <ry@tinyclouds.org>2010-12-05 15:42:41 -0800
commit093dfaf801a10905ba27df8cf3aa17b36ea5149a (patch)
tree27c559ae0d5c97c4671be1ed2b7d247ea6aacb34 /test/simple
parent0665f0271e71270dc23ec5231b245adfe709a49f (diff)
downloadnode-new-093dfaf801a10905ba27df8cf3aa17b36ea5149a.tar.gz
GJSLint all tests, only 3 long lines left in test-url.js
test/simple/test-url.js:31:(0110) Line too long (82 characters). test/simple/test-url.js:39:(0110) Line too long (85 characters). test/simple/test-url.js:40:(0110) Line too long (92 characters).
Diffstat (limited to 'test/simple')
-rw-r--r--test/simple/test-http-1.0.js30
-rw-r--r--test/simple/test-http-304.js19
-rw-r--r--test/simple/test-http-allow-req-after-204-res.js10
-rw-r--r--test/simple/test-http-blank-header.js30
-rw-r--r--test/simple/test-http-buffer-sanity.js28
-rw-r--r--test/simple/test-http-cat.js45
-rw-r--r--test/simple/test-http-chunked.js33
-rw-r--r--test/simple/test-http-client-parse-error.js12
-rw-r--r--test/simple/test-http-client-race-2.js65
-rw-r--r--test/simple/test-http-client-race.js43
-rw-r--r--test/simple/test-http-client-upload.js24
-rw-r--r--test/simple/test-http-contentLength0.js13
-rw-r--r--test/simple/test-http-curl-chunk-problem.js33
-rw-r--r--test/simple/test-http-eof-on-connect.js8
-rw-r--r--test/simple/test-http-exceptions.js18
-rw-r--r--test/simple/test-http-expect-continue.js72
-rw-r--r--test/simple/test-http-full-response.js38
-rw-r--r--test/simple/test-http-head-request.js16
-rw-r--r--test/simple/test-http-head-response-has-no-body.js8
-rw-r--r--test/simple/test-http-keep-alive-close-on-header.js34
-rw-r--r--test/simple/test-http-keep-alive.js35
-rw-r--r--test/simple/test-http-malformed-request.js18
-rw-r--r--test/simple/test-http-parser.js32
-rw-r--r--test/simple/test-http-proxy.js62
-rw-r--r--test/simple/test-http-server-multiheaders.js25
-rw-r--r--test/simple/test-http-server.js66
-rw-r--r--test/simple/test-http-set-cookies.js20
-rw-r--r--test/simple/test-http-set-timeout.js23
-rw-r--r--test/simple/test-http-set-trailers.js75
-rw-r--r--test/simple/test-http-upgrade-client.js56
-rw-r--r--test/simple/test-http-upgrade-client2.js8
-rw-r--r--test/simple/test-http-upgrade-server.js125
-rw-r--r--test/simple/test-http-upgrade-server2.js28
-rw-r--r--test/simple/test-http-wget.js32
-rw-r--r--test/simple/test-http-write-empty-string.js20
-rw-r--r--test/simple/test-http.js68
-rw-r--r--test/simple/test-path.js124
-rw-r--r--test/simple/test-url.js641
38 files changed, 1051 insertions, 986 deletions
diff --git a/test/simple/test-http-1.0.js b/test/simple/test-http-1.0.js
index c3ab565ff0..43c3f7535d 100644
--- a/test/simple/test-http-1.0.js
+++ b/test/simple/test-http-1.0.js
@@ -1,44 +1,44 @@
var common = require('../common');
var assert = require('assert');
-var net = require("net");
-var http = require("http");
+var net = require('net');
+var http = require('http');
-var body = "hello world\n";
-var server_response = "";
+var body = 'hello world\n';
+var server_response = '';
var client_got_eof = false;
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
assert.equal('1.0', req.httpVersion);
assert.equal(1, req.httpVersionMajor);
assert.equal(0, req.httpVersionMinor);
- res.writeHead(200, {"Content-Type": "text/plain"});
+ res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(body);
-})
+});
server.listen(common.PORT);
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var c = net.createConnection(common.PORT);
- c.setEncoding("utf8");
+ c.setEncoding('utf8');
- c.addListener("connect", function () {
- c.write( "GET / HTTP/1.0\r\n\r\n" );
+ c.addListener('connect', function() {
+ c.write('GET / HTTP/1.0\r\n\r\n');
});
- c.addListener("data", function (chunk) {
+ c.addListener('data', function(chunk) {
console.log(chunk);
server_response += chunk;
});
- c.addListener("end", function () {
+ c.addListener('end', function() {
client_got_eof = true;
c.end();
server.close();
});
});
-process.addListener("exit", function () {
- var m = server_response.split("\r\n\r\n");
+process.addListener('exit', function() {
+ var m = server_response.split('\r\n\r\n');
assert.equal(m[1], body);
assert.equal(true, client_got_eof);
});
diff --git a/test/simple/test-http-304.js b/test/simple/test-http-304.js
index 563da13b5f..a2cc95e57d 100644
--- a/test/simple/test-http-304.js
+++ b/test/simple/test-http-304.js
@@ -4,18 +4,19 @@ var assert = require('assert');
var http = require('http');
var childProcess = require('child_process');
-var s = http.createServer(function (request, response) {
+var s = http.createServer(function(request, response) {
response.writeHead(304);
response.end();
});
-s.listen(common.PORT, function () {
- childProcess.exec('curl -i http://127.0.0.1:'+common.PORT+'/', function (err, stdout, stderr) {
- if (err) throw err;
- s.close();
- common.error('curled response correctly');
- common.error(common.inspect(stdout));
- });
+s.listen(common.PORT, function() {
+ childProcess.exec('curl -i http://127.0.0.1:' + common.PORT + '/',
+ function(err, stdout, stderr) {
+ if (err) throw err;
+ s.close();
+ common.error('curled response correctly');
+ common.error(common.inspect(stdout));
+ });
});
-console.log('Server running at http://127.0.0.1:'+common.PORT+'/')
+console.log('Server running at http://127.0.0.1:' + common.PORT + '/');
diff --git a/test/simple/test-http-allow-req-after-204-res.js b/test/simple/test-http-allow-req-after-204-res.js
index 6139c6f489..c7882610d6 100644
--- a/test/simple/test-http-allow-req-after-204-res.js
+++ b/test/simple/test-http-allow-req-after-204-res.js
@@ -3,12 +3,12 @@ var http = require('http');
var assert = require('assert');
// first 204 or 304 works, subsequent anything fails
-var codes = [ 204, 200 ];
+var codes = [204, 200];
// Methods don't really matter, but we put in something realistic.
var methods = ['DELETE', 'DELETE'];
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
var code = codes.shift();
assert.equal('number', typeof code);
assert.ok(code > 0);
@@ -21,13 +21,13 @@ var client = http.createClient(common.PORT);
function nextRequest() {
var method = methods.shift();
- console.error("writing request: %s", method);
+ console.error('writing request: %s', method);
var request = client.request(method, '/');
- request.on('response', function (response) {
+ request.on('response', function(response) {
response.on('end', function() {
if (methods.length == 0) {
- console.error("close server");
+ console.error('close server');
server.close();
} else {
// throws error:
diff --git a/test/simple/test-http-blank-header.js b/test/simple/test-http-blank-header.js
index 3cc4d190d6..dd8091fecb 100644
--- a/test/simple/test-http-blank-header.js
+++ b/test/simple/test-http-blank-header.js
@@ -5,43 +5,43 @@ var net = require('net');
var gotReq = false;
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
common.error('got req');
gotReq = true;
assert.equal('GET', req.method);
assert.equal('/blah', req.url);
assert.deepEqual({
- host: "mapdevel.trolologames.ru:443",
- origin: "http://mapdevel.trolologames.ru",
- cookie: "",
+ host: 'mapdevel.trolologames.ru:443',
+ origin: 'http://mapdevel.trolologames.ru',
+ cookie: ''
}, req.headers);
});
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
var c = net.createConnection(common.PORT);
- c.addListener('connect', function () {
+ c.addListener('connect', function() {
common.error('client wrote message');
- c.write( "GET /blah HTTP/1.1\r\n"
- + "Host: mapdevel.trolologames.ru:443\r\n"
- + "Cookie:\r\n"
- + "Origin: http://mapdevel.trolologames.ru\r\n"
- + "\r\n\r\nhello world"
- );
+ c.write('GET /blah HTTP/1.1\r\n' +
+ 'Host: mapdevel.trolologames.ru:443\r\n' +
+ 'Cookie:\r\n' +
+ 'Origin: http://mapdevel.trolologames.ru\r\n' +
+ '\r\n\r\nhello world'
+ );
});
- c.addListener('end', function () {
+ c.addListener('end', function() {
c.end();
});
- c.addListener('close', function () {
+ c.addListener('close', function() {
common.error('client close');
server.close();
});
});
-process.addListener('exit', function () {
+process.addListener('exit', function() {
assert.ok(gotReq);
});
diff --git a/test/simple/test-http-buffer-sanity.js b/test/simple/test-http-buffer-sanity.js
index c25a79d5c6..57a813f8a3 100644
--- a/test/simple/test-http-buffer-sanity.js
+++ b/test/simple/test-http-buffer-sanity.js
@@ -12,15 +12,15 @@ for (var i = 0; i < buffer.length; i++) {
}
-var web = http.Server(function (req, res) {
+var web = http.Server(function(req, res) {
web.close();
console.log(req.headers);
var i = 0;
- req.on('data', function (d) {
- process.stdout.write(",");
+ req.on('data', function(d) {
+ process.stdout.write(',');
measuredSize += d.length;
for (var j = 0; j < d.length; j++) {
assert.equal(buffer[i], d[j]);
@@ -29,40 +29,40 @@ var web = http.Server(function (req, res) {
});
- 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);
});
});
var gotThanks = false;
-web.listen(common.PORT, function () {
- console.log("Making request");
+web.listen(common.PORT, function() {
+ console.log('Making request');
var client = http.createClient(common.PORT);
var req = client.request('GET', '/', { 'content-length': buffer.length });
req.end(buffer);
- 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.equal(bufferSize, measuredSize);
assert.ok(gotThanks);
});
diff --git a/test/simple/test-http-cat.js b/test/simple/test-http-cat.js
index f967b2ed2e..2ab7618606 100644
--- a/test/simple/test-http-cat.js
+++ b/test/simple/test-http-cat.js
@@ -1,13 +1,13 @@
-var common = require("../common");
+var common = require('../common');
var assert = require('assert');
-var http = require("http");
+var http = require('http');
-var body = "exports.A = function() { return 'A';}";
-var server = http.createServer(function (req, res) {
- console.log("got request");
+var body = 'exports.A = function() { return "A";}';
+var server = http.createServer(function(req, res) {
+ console.log('got request');
res.writeHead(200, [
- ["Content-Length", body.length],
- ["Content-Type", "text/plain"]
+ ['Content-Length', body.length],
+ ['Content-Type', 'text/plain']
]);
res.end(body);
});
@@ -15,28 +15,29 @@ var server = http.createServer(function (req, res) {
var got_good_server_content = false;
var bad_server_got_error = false;
-server.listen(common.PORT, function () {
- http.cat("http://localhost:"+common.PORT+"/", "utf8", function (err, content) {
- if (err) {
- throw err;
- } else {
- console.log("got response");
- got_good_server_content = true;
- assert.equal(body, content);
- server.close();
- }
- });
+server.listen(common.PORT, function() {
+ http.cat('http://localhost:' + common.PORT + '/', 'utf8',
+ function(err, content) {
+ if (err) {
+ throw err;
+ } else {
+ console.log('got response');
+ got_good_server_content = true;
+ assert.equal(body, content);
+ server.close();
+ }
+ });
- http.cat("http://localhost:12312/", "utf8", function (err, content) {
+ http.cat('http://localhost:12312/', 'utf8', function(err, content) {
if (err) {
- console.log("got error (this should happen)");
+ console.log('got error (this should happen)');
bad_server_got_error = true;
}
});
});
-process.addListener("exit", function () {
- console.log("exit");
+process.addListener('exit', function() {
+ console.log('exit');
assert.equal(true, got_good_server_content);
assert.equal(true, bad_server_got_error);
});
diff --git a/test/simple/test-http-chunked.js b/test/simple/test-http-chunked.js
index eb8c7ab63a..4801d54d58 100644
--- a/test/simple/test-http-chunked.js
+++ b/test/simple/test-http-chunked.js
@@ -1,22 +1,31 @@
var common = require('../common');
var assert = require('assert');
-var http = require("http");
+var http = require('http');
-var UTF8_STRING = "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、经济现状。";
+var UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的一个国家,' +
+ '国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、' +
+ '贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' +
+ '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' +
+ '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' +
+ '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。' +
+ '南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' +
+ '采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,' +
+ '有效的改善了岭南地区落后的政治、经济现状。';
var server = http.createServer(function(req, res) {
- res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
+ res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'});
res.end(UTF8_STRING, 'utf8');
});
server.listen(common.PORT);
-server.addListener("listening", function() {
- http.cat("http://127.0.0.1:"+common.PORT+"/", "utf8", function (err, data) {
- if (err) throw err;
- assert.equal('string', typeof data);
- console.log('here is the response:');
- assert.equal(UTF8_STRING, data);
- console.log(data);
- server.close();
- });
+server.addListener('listening', function() {
+ http.cat('http://127.0.0.1:' + common.PORT + '/', 'utf8',
+ function(err, data) {
+ if (err) throw err;
+ assert.equal('string', typeof data);
+ console.log('here is the response:');
+ assert.equal(UTF8_STRING, data);
+ console.log(data);
+ server.close();
+ });
});
diff --git a/test/simple/test-http-client-parse-error.js b/test/simple/test-http-client-parse-error.js
index d598b31d51..9468bde441 100644
--- a/test/simple/test-http-client-parse-error.js
+++ b/test/simple/test-http-client-parse-error.js
@@ -1,4 +1,4 @@
-var common = require("../common");
+var common = require('../common');
var assert = require('assert');
var http = require('http');
@@ -8,21 +8,21 @@ var net = require('net');
var srv = net.createServer(function(c) {
c.write('bad http - should trigger parse error\r\n');
- console.log("connection");
+ console.log('connection');
c.addListener('end', function() { c.end(); });
});
var parseError = false;
-srv.listen(common.PORT, '127.0.0.1', function () {
+srv.listen(common.PORT, '127.0.0.1', function() {
var hc = http.createClient(common.PORT, '127.0.0.1');
hc.request('GET', '/').end();
- hc.on('error', function (e) {
- console.log("got error from client");
+ hc.on('error', function(e) {
+ console.log('got error from client');
srv.close();
- assert.ok(e.message.indexOf("Parse Error") >= 0);
+ assert.ok(e.message.indexOf('Parse Error') >= 0);
parseError = true;
});
});
diff --git a/test/simple/test-http-client-race-2.js b/test/simple/test-http-client-race-2.js
index 97df9ef547..136c02c1ab 100644
--- a/test/simple/test-http-client-race-2.js
+++ b/test/simple/test-http-client-race-2.js
@@ -1,59 +1,58 @@
var common = require('../common');
var assert = require('assert');
var http = require('http');
-var url = require("url");
+var url = require('url');
//
// Slight variation on test-http-client-race to test for another race
// condition involving the parsers FreeList used internally by http.Client.
//
-var body1_s = "1111111111111111";
-var body2_s = "22222";
-var body3_s = "3333333333333333333";
+var body1_s = '1111111111111111';
+var body2_s = '22222';
+var body3_s = '3333333333333333333';
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
var pathname = url.parse(req.url).pathname;
var body;
switch (pathname) {
- case "/1": body = body1_s; break;
- case "/2": body = body2_s; break;
+ case '/1': body = body1_s; break;
+ case '/2': body = body2_s; break;
default: body = body3_s;
- };
+ }
- res.writeHead(200, { "Content-Type": "text/plain"
- , "Content-Length": body.length
- });
+ res.writeHead(200,
+ {'Content-Type': 'text/plain', 'Content-Length': body.length});
res.end(body);
});
server.listen(common.PORT);
-var body1 = "";
-var body2 = "";
-var body3 = "";
+var body1 = '';
+var body2 = '';
+var body3 = '';
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var client = http.createClient(common.PORT);
//
// Client #1 is assigned Parser #1
//
- var req1 = client.request("/1")
+ var req1 = client.request('/1');
req1.end();
- req1.addListener('response', function (res1) {
- res1.setEncoding("utf8");
+ req1.addListener('response', function(res1) {
+ res1.setEncoding('utf8');
- res1.addListener('data', function (chunk) {
+ res1.addListener('data', function(chunk) {
body1 += chunk;
});
- res1.addListener('end', function () {
+ res1.addListener('end', function() {
//
- // Delay execution a little to allow the "close" event to be processed
+ // Delay execution a little to allow the 'close' event to be processed
// (required to trigger this bug!)
//
- setTimeout(function () {
+ setTimeout(function() {
//
// The bug would introduce itself here: Client #2 would be allocated the
// parser that previously belonged to Client #1. But we're not finished
@@ -63,24 +62,24 @@ server.addListener("listening", function() {
//
// At this point, the bug would manifest itself and crash because the
- // internal state of the parser was no longer valid for use by Client #1.
+ // internal state of the parser was no longer valid for use by Client #1
//
- var req2 = client.request("/2");
+ var req2 = client.request('/2');
req2.end();
- req2.addListener('response', function (res2) {
- res2.setEncoding("utf8");
- res2.addListener('data', function (chunk) { body2 += chunk; });
- res2.addListener('end', function () {
+ req2.addListener('response', function(res2) {
+ res2.setEncoding('utf8');
+ res2.addListener('data', function(chunk) { body2 += chunk; });
+ res2.addListener('end', function() {
//
// Just to be really sure we've covered all our bases, execute a
// request using client2.
//
- var req3 = client2.request("/3");
+ var req3 = client2.request('/3');
req3.end();
- req3.addListener('response', function (res3) {
- res3.setEncoding("utf8");
- res3.addListener('data', function (chunk) { body3 += chunk });
+ req3.addListener('response', function(res3) {
+ res3.setEncoding('utf8');
+ res3.addListener('data', function(chunk) { body3 += chunk });
res3.addListener('end', function() { server.close(); });
});
});
@@ -90,7 +89,7 @@ server.addListener("listening", function() {
});
});
-process.addListener("exit", function () {
+process.addListener('exit', function() {
assert.equal(body1_s, body1);
assert.equal(body2_s, body2);
assert.equal(body3_s, body3);
diff --git a/test/simple/test-http-client-race.js b/test/simple/test-http-client-race.js
index 6d93201a54..627905e78e 100644
--- a/test/simple/test-http-client-race.js
+++ b/test/simple/test-http-client-race.js
@@ -1,48 +1,47 @@
var common = require('../common');
var assert = require('assert');
var http = require('http');
-var url = require("url");
+var url = require('url');
-var body1_s = "1111111111111111";
-var body2_s = "22222";
+var body1_s = '1111111111111111';
+var body2_s = '22222';
-var server = http.createServer(function (req, res) {
- var body = url.parse(req.url).pathname === "/1" ? body1_s : body2_s;
- res.writeHead(200, { "Content-Type": "text/plain"
- , "Content-Length": body.length
- });
+var server = http.createServer(function(req, res) {
+ var body = url.parse(req.url).pathname === '/1' ? body1_s : body2_s;
+ res.writeHead(200,
+ {'Content-Type': 'text/plain', 'Content-Length': body.length});
res.end(body);
});
server.listen(common.PORT);
-var body1 = "";
-var body2 = "";
+var body1 = '';
+var body2 = '';
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var client = http.createClient(common.PORT);
- var req1 = client.request("/1")
+ var req1 = client.request('/1');
req1.end();
- req1.addListener('response', function (res1) {
- res1.setEncoding("utf8");
+ req1.addListener('response', function(res1) {
+ res1.setEncoding('utf8');
- res1.addListener('data', function (chunk) {
+ res1.addListener('data', function(chunk) {
body1 += chunk;
});
- res1.addListener('end', function () {
- var req2 = client.request("/2");
+ res1.addListener('end', function() {
+ var req2 = client.request('/2');
req2.end();
- req2.addListener('response', function (res2) {
- res2.setEncoding("utf8");
- res2.addListener('data', function (chunk) { body2 += chunk; });
- res2.addListener('end', function () { server.close(); });
+ req2.addListener('response', function(res2) {
+ res2.setEncoding('utf8');
+ res2.addListener('data', function(chunk) { body2 += chunk; });
+ res2.addListener('end', function() { server.close(); });
});
});
});
});
-process.addListener("exit", function () {
+process.addListener('exit', function() {
assert.equal(body1_s, body1);
assert.equal(body2_s, body2);
});
diff --git a/test/simple/test-http-client-upload.js b/test/simple/test-http-client-upload.js
index b49235e291..3bd9bed0a9 100644
--- a/test/simple/test-http-client-upload.js
+++ b/test/simple/test-http-client-upload.js
@@ -2,22 +2,22 @@ var common = require('../common');
var assert = require('assert');
var http = require('http');
-var sent_body = "";
+var sent_body = '';
var server_req_complete = false;
var client_res_complete = false;
var server = http.createServer(function(req, res) {
- assert.equal("POST", req.method);
- req.setEncoding("utf8");
+ assert.equal('POST', req.method);
+ req.setEncoding('utf8');
- req.addListener('data', function (chunk) {
- console.log("server got: " + JSON.stringify(chunk));
+ req.addListener('data', function(chunk) {
+ console.log('server got: ' + JSON.stringify(chunk));
sent_body += chunk;
});
- req.addListener('end', function () {
+ req.addListener('end', function() {
server_req_complete = true;
- console.log("request complete from server");
+ console.log('request complete from server');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('hello\n');
res.end();
@@ -25,7 +25,7 @@ var server = http.createServer(function(req, res) {
});
server.listen(common.PORT);
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var client = http.createClient(common.PORT);
var req = client.request('POST', '/');
req.write('1\n');
@@ -33,10 +33,10 @@ server.addListener("listening", function() {
req.write('3\n');
req.end();
- common.error("client finished sending request");
+ common.error('client finished sending request');
req.addListener('response', function(res) {
- res.setEncoding("utf8");
+ res.setEncoding('utf8');
res.addListener('data', function(chunk) {
console.log(chunk);
});
@@ -47,8 +47,8 @@ server.addListener("listening", function() {
});
});
-process.addListener("exit", function () {
- assert.equal("1\n2\n3\n", sent_body);
+process.addListener('exit', function() {
+ assert.equal('1\n2\n3\n', sent_body);
assert.equal(true, server_req_complete);
assert.equal(true, client_res_complete);
});
diff --git a/test/simple/test-http-contentLength0.js b/test/simple/test-http-contentLength0.js
index 7e3dca5409..a7e2b5acdc 100644
--- a/test/simple/test-http-contentLength0.js
+++ b/test/simple/test-http-contentLength0.js
@@ -1,12 +1,13 @@
var common = require('../common');
-var http = require("http");
+var http = require('http');
-// Simple test of Node's HTTP Client choking on a response with a "Content-Length: 0 " response header.
-// I.E. a space character after the "Content-Length" throws an `error` event.
+// Simple test of Node's HTTP Client choking on a response
+// with a 'Content-Length: 0 ' response header.
+// I.E. a space character after the 'Content-Length' throws an `error` event.
-var s = http.createServer(function(req, res) {
- res.writeHead(200, { "Content-Length": "0 " });
+var s = http.createServer(function(req, res) {
+ res.writeHead(200, {'Content-Length': '0 '});
res.end();
});
s.listen(common.PORT, function() {
@@ -14,7 +15,7 @@ s.listen(common.PORT, function() {
var r = http.createClient(common.PORT);
var request = r.request('GET', '/');
- request.on('response', function (response) {
+ request.on('response', function(response) {
console.log('STATUS: ' + response.statusCode);
s.close();
});
diff --git a/test/simple/test-http-curl-chunk-problem.js b/test/simple/test-http-curl-chunk-problem.js
index 8c42e152e8..30b8a981f1 100644
--- a/test/simple/test-http-curl-chunk-problem.js
+++ b/test/simple/test-http-curl-chunk-problem.js
@@ -2,45 +2,46 @@
var common = require('../common');
var assert = require('assert');
var http = require('http'),
- cp = require('child_process');
+ cp = require('child_process');
var filename = require('path').join(common.tmpDir || '/tmp', 'big');
var count = 0;
-function maybeMakeRequest () {
+function maybeMakeRequest() {
if (++count < 2) return;
- console.log("making curl request");
+ console.log('making curl request');
cp.exec('curl http://127.0.0.1:' + common.PORT + '/ | shasum',
- function (err, stdout, stderr) {
- if (err) throw err;
- assert.equal('8c206a1a87599f532ce68675536f0b1546900d7a', stdout.slice(0, 40));
- console.log("got the correct response");
- server.close();
- });
+ function(err, stdout, stderr) {
+ if (err) throw err;
+ assert.equal('8c206a1a87599f532ce68675536f0b1546900d7a',
+ stdout.slice(0, 40));
+ console.log('got the correct response');
+ server.close();
+ });
}
cp.exec('dd if=/dev/zero of=' + filename + ' bs=1024 count=10240',
- function (err, stdout, stderr) {
- if (err) throw err;
- maybeMakeRequest();
- });
+ function(err, stdout, stderr) {
+ if (err) throw err;
+ maybeMakeRequest();
+ });
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
res.writeHead(200);
// Create the subprocess
var cat = cp.spawn('cat', [filename]);
// Stream the data through to the response as binary chunks
- cat.stdout.on('data', function (data) {
+ cat.stdout.on('data', function(data) {
res.write(data);
});
// End the response on exit (and log errors)
- cat.on('exit', function (code) {
+ cat.on('exit', function(code) {
if (code !== 0) {
console.error('subprocess exited with code ' + code);
exit(1);
diff --git a/test/simple/test-http-eof-on-connect.js b/test/simple/test-http-eof-on-connect.js
index 4a23659faa..9bb5bbb8f0 100644
--- a/test/simple/test-http-eof-on-connect.js
+++ b/test/simple/test-http-eof-on-connect.js
@@ -7,13 +7,13 @@ var http = require('http');
// It is separate from test-http-malformed-request.js because it is only
// reproduceable on the first packet on the first connection to a server.
-var server = http.createServer(function (req, res) {});
+var server = http.createServer(function(req, res) {});
server.listen(common.PORT);
-server.addListener("listening", function() {
- net.createConnection(common.PORT).addListener("connect", function () {
+server.addListener('listening', function() {
+ net.createConnection(common.PORT).addListener('connect', function() {
this.destroy();
- }).addListener("close", function () {
+ }).addListener('close', function() {
server.close();
});
});
diff --git a/test/simple/test-http-exceptions.js b/test/simple/test-http-exceptions.js
index 4e711d7ff8..e723496e54 100644
--- a/test/simple/test-http-exceptions.js
+++ b/test/simple/test-http-exceptions.js
@@ -1,17 +1,17 @@
var common = require('../common');
-var assert = require('assert');;
+var assert = require('assert');
var http = require('http');
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
intentionally_not_defined();
- res.writeHead(200, {"Content-Type": "text/plain"});
- res.write("Thank you, come again.");
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.write('Thank you, come again.');
res.end();
});
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
var req;
- for (var i = 0; i < 4 ; i += 1) {
+ for (var i = 0; i < 4; i += 1) {
req = http.createClient(common.PORT).request('GET', '/busy/' + i);
req.end();
}
@@ -19,9 +19,9 @@ server.listen(common.PORT, function () {
var exception_count = 0;
-process.addListener("uncaughtException", function (err) {
- console.log("Caught an exception: " + err);
- if (err.name === "AssertionError") throw err;
+process.addListener('uncaughtException', function(err) {
+ console.log('Caught an exception: ' + err);
+ if (err.name === 'AssertionError') throw err;
if (++exception_count == 4) process.exit(0);
});
diff --git a/test/simple/test-http-expect-continue.js b/test/simple/test-http-expect-continue.js
index 5b64cee8de..e15918fbfe 100644
--- a/test/simple/test-http-expect-continue.js
+++ b/test/simple/test-http-expect-continue.js
@@ -1,65 +1,63 @@
-var common = require("../common");
+var common = require('../common');
var assert = require('assert');
-var http = require("http");
+var http = require('http');
var outstanding_reqs = 0;
-var test_req_body = "some stuff...\n";
-var test_res_body = "other stuff!\n";
+var test_req_body = 'some stuff...\n';
+var test_res_body = 'other stuff!\n';
var sent_continue = false;
var got_continue = false;
function handler(req, res) {
- assert.equal(sent_continue, true, "Full response sent before 100 Continue");
- common.debug("Server sending full response...");
+ assert.equal(sent_continue, true, 'Full response sent before 100 Continue');
+ common.debug('Server sending full response...');
res.writeHead(200, {
- 'Content-Type' : 'text/plain',
- "ABCD" : "1"
+ 'Content-Type' : 'text/plain',
+ 'ABCD' : '1'
});
res.end(test_res_body);
}
var server = http.createServer(handler);
-server.addListener("checkContinue", function(req, res) {
- common.debug("Server got Expect: 100-continue...");
- res.writeContinue();
- sent_continue = true;
- handler(req, res);
-});
+server.addListener('checkContinue', function(req, res) {
+ common.debug('Server got Expect: 100-continue...');
+ res.writeContinue();
+ sent_continue = true;
+ handler(req, res);
+});
server.listen(common.PORT);
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var client = http.createClient(common.PORT);
- var req = client.request("POST", "/world", {
- "Expect": "100-continue",
+ var req = client.request('POST', '/world', {
+ 'Expect': '100-continue'
});
- common.debug("Client sending request...");
+ common.debug('Client sending request...');
outstanding_reqs++;
- var body = "";
- req.addListener('continue', function () {
- common.debug("Client got 100 Continue...");
- got_continue = true;
- req.end(test_req_body);
+ var body = '';
+ req.addListener('continue', function() {
+ common.debug('Client got 100 Continue...');
+ got_continue = true;
+ req.end(test_req_body);
});
- req.addListener('response', function (res) {
- assert.equal(got_continue, true,
- "Full response received before 100 Continue"
- );
- assert.equal(200, res.statusCode,
- "Final status code was " + res.statusCode + ", not 200."
- );
- res.setEncoding("utf8");
- res.addListener('data', function (chunk) { body += chunk; });
- res.addListener('end', function () {
- common.debug("Got full response.");
- assert.equal(body, test_res_body, "Response body doesn't match.");
- assert.ok("abcd" in res.headers, "Response headers missing.");
+ req.addListener('response', function(res) {
+ assert.equal(got_continue, true,
+ 'Full response received before 100 Continue');
+ assert.equal(200, res.statusCode,
+ 'Final status code was ' + res.statusCode + ', not 200.');
+ res.setEncoding('utf8');
+ res.addListener('data', function(chunk) { body += chunk; });
+ res.addListener('end', function() {
+ common.debug('Got full response.');
+ assert.equal(body, test_res_body, 'Response body doesn\'t match.');
+ assert.ok('abcd' in res.headers, 'Response headers missing.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
server.close();
process.exit();
- }
+ }
});
});
});
diff --git a/test/simple/test-http-full-response.js b/test/simple/test-http-full-response.js
index 6a7d77ff63..90c8332821 100644
--- a/test/simple/test-http-full-response.js
+++ b/test/simple/test-http-full-response.js
@@ -1,20 +1,20 @@
var common = require('../common');
var assert = require('assert');
-// This test requires the program "ab"
+// This test requires the program 'ab'
var http = require('http');
-var exec = require("child_process").exec;
+var exec = require('child_process').exec;
var bodyLength = 12345;
-var body = "";
+var body = '';
for (var i = 0; i < bodyLength; i++) {
body += 'c';
}
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
res.writeHead(200, {
- "Content-Length": bodyLength,
- "Content-Type": "text/plain"
+ 'Content-Length': bodyLength,
+ 'Content-Type': 'text/plain'
});
res.end(body);
});
@@ -22,11 +22,11 @@ var server = http.createServer(function (req, res) {
var runs = 0;
function runAb(opts, callback) {
- var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/";
- exec(command, function (err, stdout, stderr) {
+ var command = 'ab ' + opts + ' http://127.0.0.1:' + common.PORT + '/';
+ exec(command, function(err, stdout, stderr) {
if (err) {
- if (stderr.indexOf("ab") >= 0) {
- console.log("ab not installed? skipping test.\n" + stderr);
+ if (stderr.indexOf('ab') >= 0) {
+ console.log('ab not installed? skipping test.\n' + stderr);
process.reallyExit(0);
}
process.exit();
@@ -47,19 +47,19 @@ function runAb(opts, callback) {
runs++;
- if (callback) callback()
+ if (callback) callback();
});
}
-server.listen(common.PORT, function () {
- runAb("-c 1 -n 10", function () {
- console.log("-c 1 -n 10 okay");
+server.listen(common.PORT, function() {
+ runAb('-c 1 -n 10', function() {
+ console.log('-c 1 -n 10 okay');
- runAb("-c 1 -n 100", function () {
- console.log("-c 1 -n 100 okay");
+ runAb('-c 1 -n 100', function() {
+ console.log('-c 1 -n 100 okay');
- runAb("-c 1 -n 1000", function () {
- console.log("-c 1 -n 1000 okay");
+ runAb('-c 1 -n 1000', function() {
+ console.log('-c 1 -n 1000 okay');
server.close();
});
});
@@ -67,6 +67,6 @@ server.listen(common.PORT, function () {
});
-process.addListener("exit", function () {
+process.addListener('exit', function() {
assert.equal(3, runs);
});
diff --git a/test/simple/test-http-head-request.js b/test/simple/test-http-head-request.js
index 57878d4550..627ede43ce 100644
--- a/test/simple/test-http-head-request.js
+++ b/test/simple/test-http-head-request.js
@@ -4,30 +4,30 @@ var http = require('http');
var util = require('util');
-var body = "hello world\n";
+var body = 'hello world\n';
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
common.error('req: ' + req.method);
- res.writeHead(200, {"Content-Length": body.length});
+ res.writeHead(200, {'Content-Length': body.length});
res.end();
server.close();
});
var gotEnd = false;
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
var client = http.createClient(common.PORT);
- var request = client.request("HEAD", "/");
+ var request = client.request('HEAD', '/');
request.end();
- request.addListener('response', function (response) {
+ request.addListener('response', function(response) {
common.error('response start');
- response.addListener("end", function () {
+ response.addListener('end', function() {
common.error('response end');
gotEnd = true;
});
});
});
-process.addListener('exit', function () {
+process.addListener('exit', function() {
assert.ok(gotEnd);
});
diff --git a/test/simple/test-http-head-response-has-no-body.js b/test/simple/test-http-head-response-has-no-body.js
index 270a5e73e9..17ef4ac95e 100644
--- a/test/simple/test-http-head-response-has-no-body.js
+++ b/test/simple/test-http-head-response-has-no-body.js
@@ -15,11 +15,11 @@ server.listen(common.PORT);
var responseComplete = false;
-server.addListener("listening", function() {
- var req = http.createClient(common.PORT).request('HEAD', '/')
+server.addListener('listening', function() {
+ var req = http.createClient(common.PORT).request('HEAD', '/');
common.error('req');
req.end();
- req.addListener('response', function (res) {
+ req.addListener('response', function(res) {
common.error('response');
res.addListener('end', function() {
common.error('response end');
@@ -29,6 +29,6 @@ server.addListener("listening", function() {
});
});
-process.addListener('exit', function () {
+process.addListener('exit', function() {
assert.ok(responseComplete);
});
diff --git a/test/simple/test-http-keep-alive-close-on-header.js b/test/simple/test-http-keep-alive-close-on-header.js
index 03538b5047..4afe9e2db0 100644
--- a/test/simple/test-http-keep-alive-close-on-header.js
+++ b/test/simple/test-http-keep-alive-close-on-header.js
@@ -3,45 +3,45 @@ var assert = require('assert');
var http = require('http');
var util = require('util');
-var body = "hello world\n";
-var headers = {'connection':'keep-alive'}
+var body = 'hello world\n';
+var headers = {'connection': 'keep-alive'};
-var server = http.createServer(function (req, res) {
- res.writeHead(200, {"Content-Length": body.length, "Connection":"close"});
+var server = http.createServer(function(req, res) {
+ res.writeHead(200, {'Content-Length': body.length, 'Connection': 'close'});
res.write(body);
res.end();
});
var connectCount = 0;
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
var client = http.createClient(common.PORT);
- client.addListener("connect", function () {
- common.error("CONNECTED")
+ client.addListener('connect', function() {
+ common.error('CONNECTED');
connectCount++;
- })
+ });
- var request = client.request("GET", "/", headers);
+ var request = client.request('GET', '/', headers);
request.end();
- request.addListener('response', function (response) {
+ request.addListener('response', function(response) {
common.error('response start');
- response.addListener("end", function () {
+ response.addListener('end', function() {
common.error('response end');
- var req = client.request("GET", "/", headers);
- req.addListener('response', function (response) {
- response.addListener("end", function () {
+ var req = client.request('GET', '/', headers);
+ req.addListener('response', function(response) {
+ response.addListener('end', function() {
client.end();
server.close();
- })
- })
+ });
+ });
req.end();
});
});
});
-process.addListener('exit', function () {
+process.addListener('exit', function() {
assert.equal(2, connectCount);
});
diff --git a/test/simple/test-http-keep-alive.js b/test/simple/test-http-keep-alive.js
index b44f4d41b9..10e7e8824e 100644
--- a/test/simple/test-http-keep-alive.js
+++ b/test/simple/test-http-keep-alive.js
@@ -3,45 +3,44 @@ var assert = require('assert');
var http = require('http');
var util = require('util');
-var body = "hello world\n";
-var headers = {'connection':'keep-alive'}
+var body = 'hello world\n';
+var headers = {'connection': 'keep-alive'};
-var server = http.createServer(function (req, res) {
- res.writeHead(200, {"Content-Length": body.length});
+var server = http.createServer(function(req, res) {
+ res.writeHead(200, {'Content-Length': body.length});
res.write(body);
res.end();
});
var connectCount = 0;
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
var client = http.createClient(common.PORT);
- client.addListener("connect", function () {
- common.error("CONNECTED")
+ client.addListener('connect', function() {
+ common.error('CONNECTED');
connectCount++;
- })
+ });
- var request = client.request("GET", "/", headers);
+ var request = client.request('GET', '/', headers);
request.end();
- request.addListener('response', function (response) {
+ request.addListener('response', function(response) {
common.error('response start');
-
- response.addListener("end", function () {
+ response.addListener('end', function() {
common.error('response end');
- var req = client.request("GET", "/", headers);
- req.addListener('response', function (response) {
- response.addListener("end", function () {
+ var req = client.request('GET', '/', headers);
+ req.addListener('response', function(response) {
+ response.addListener('end', function() {
client.end();
server.close();
- })
- })
+ });
+ });
req.end();
});
});
});
-process.addListener('exit', function () {
+process.addListener('exit', function() {
assert.equal(1, connectCount);
});
diff --git a/test/simple/test-http-malformed-request.js b/test/simple/test-http-malformed-request.js
index db571ac558..cabd328719 100644
--- a/test/simple/test-http-malformed-request.js
+++ b/test/simple/test-http-malformed-request.js
@@ -2,7 +2,7 @@ var common = require('../common');
var assert = require('assert');
var net = require('net');
var http = require('http');
-var url = require("url");
+var url = require('url');
// Make sure no exceptions are thrown when receiving malformed HTTP
// requests.
@@ -10,27 +10,27 @@ var url = require("url");
var nrequests_completed = 0;
var nrequests_expected = 1;
-var server = http.createServer(function (req, res) {
- console.log("req: " + JSON.stringify(url.parse(req.url)));
+var server = http.createServer(function(req, res) {
+ console.log('req: ' + JSON.stringify(url.parse(req.url)));
- res.writeHead(200, {"Content-Type": "text/plain"});
- res.write("Hello World");
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.write('Hello World');
res.end();
if (++nrequests_completed == nrequests_expected) server.close();
});
server.listen(common.PORT);
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var c = net.createConnection(common.PORT);
- c.addListener("connect", function () {
- c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
+ c.addListener('connect', function() {
+ c.write('GET /hello?foo=%99bar HTTP/1.1\r\n\r\n');
c.end();
});
// TODO add more!
});
-process.addListener("exit", function () {
+process.addListener('exit', function() {
assert.equal(nrequests_expected, nrequests_completed);
});
diff --git a/test/simple/test-http-parser.js b/test/simple/test-http-parser.js
index aa5551a8e6..d9e9cf0a44 100644
--- a/test/simple/test-http-parser.js
+++ b/test/simple/test-http-parser.js
@@ -8,39 +8,39 @@ var assert = require('assert');
var HTTPParser = process.binding('http_parser').HTTPParser;
-var parser = new HTTPParser("request");
+var parser = new HTTPParser('request');
var Buffer = require('buffer').Buffer;
var buffer = new Buffer(1024);
-var request = "GET /hello HTTP/1.1\r\n\r\n";
+var request = 'GET /hello HTTP/1.1\r\n\r\n';
buffer.write(request, 0, 'ascii');
var callbacks = 0;
-parser.onMessageBegin = function () {
- console.log("message begin");
+parser.onMessageBegin = function() {
+ console.log('message begin');
callbacks++;
};
-parser.onHeadersComplete = function (info) {
- console.log("headers complete: " + JSON.stringify(info));
+parser.onHeadersComplete = function(info) {
+ console.log('headers complete: ' + JSON.stringify(info));
assert.equal('GET', info.method);
assert.equal(1, info.versionMajor);
assert.equal(1, info.versionMinor);
callbacks++;
};
-parser.onURL = function (b, off, len) {
- //throw new Error("hello world");
+parser.onURL = function(b, off, len) {
+ //throw new Error('hello world');
callbacks++;
};
-parser.onPath = function (b, off, length) {
- console.log("path [" + off + ", " + length + "]");
- var path = b.toString('ascii', off, off+length);
- console.log("path = '" + path + "'");
+parser.onPath = function(b, off, length) {
+ console.log('path [' + off + ', ' + length + ']');
+ var path = b.toString('ascii', off, off + length);
+ console.log('path = "' + path + '"');
assert.equal('/hello', path);
callbacks++;
};
@@ -53,11 +53,11 @@ assert.equal(4, callbacks);
// thrown from parser.execute()
//
-parser.onURL = function (b, off, len) {
- throw new Error("hello world");
+parser.onURL = function(b, off, len) {
+ throw new Error('hello world');
};
-assert.throws(function () {
+assert.throws(function() {
parser.execute(buffer, 0, request.length);
-}, Error, "hello world");
+}, Error, 'hello world');
diff --git a/test/simple/test-http-proxy.js b/test/simple/test-http-proxy.js
index b8e9462885..4e4e38a8a4 100644
--- a/test/simple/test-http-proxy.js
+++ b/test/simple/test-http-proxy.js
@@ -1,33 +1,35 @@
var common = require('../common');
var assert = require('assert');
var http = require('http');
-var url = require("url");
+var url = require('url');
var PROXY_PORT = common.PORT;
-var BACKEND_PORT = common.PORT+1;
+var BACKEND_PORT = common.PORT + 1;
-var cookies = [ "session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT",
- "prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT" ];
+var cookies = [
+ 'session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT',
+ 'prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT'
+];
-var headers = {"content-type": "text/plain",
- "set-cookie": cookies,
- "hello": "world" };
+var headers = {'content-type': 'text/plain',
+ 'set-cookie': cookies,
+ 'hello': 'world' };
-var backend = http.createServer(function (req, res) {
- common.debug("backend request");
+var backend = http.createServer(function(req, res) {
+ common.debug('backend request');
res.writeHead(200, headers);
- res.write("hello world\n");
+ res.write('hello world\n');
res.end();
});
var proxy_client = http.createClient(BACKEND_PORT);
-var proxy = http.createServer(function (req, res) {
- common.debug("proxy req headers: " + JSON.stringify(req.headers));
+var proxy = http.createServer(function(req, res) {
+ common.debug('proxy req headers: ' + JSON.stringify(req.headers));
var proxy_req = proxy_client.request(url.parse(req.url).pathname);
proxy_req.end();
proxy_req.addListener('response', function(proxy_res) {
- common.debug("proxy res headers: " + JSON.stringify(proxy_res.headers));
+ common.debug('proxy res headers: ' + JSON.stringify(proxy_res.headers));
assert.equal('world', proxy_res.headers['hello']);
assert.equal('text/plain', proxy_res.headers['content-type']);
@@ -35,52 +37,52 @@ var proxy = http.createServer(function (req, res) {
res.writeHead(proxy_res.statusCode, proxy_res.headers);
- proxy_res.addListener("data", function(chunk) {
+ proxy_res.addListener('data', function(chunk) {
res.write(chunk);
});
- proxy_res.addListener("end", function() {
+ proxy_res.addListener('end', function() {
res.end();
- common.debug("proxy res");
+ common.debug('proxy res');
});
});
});
-var body = "";
+var body = '';
var nlistening = 0;
-function startReq () {
+function startReq() {
nlistening++;
if (nlistening < 2) return;
var client = http.createClient(PROXY_PORT);
- var req = client.request("/test");
- common.debug("client req")
- req.addListener('response', function (res) {
- common.debug("got res");
+ var req = client.request('/test');
+ common.debug('client req');
+ req.addListener('response', function(res) {
+ common.debug('got res');
assert.equal(200, res.statusCode);
assert.equal('world', res.headers['hello']);
assert.equal('text/plain', res.headers['content-type']);
assert.deepEqual(cookies, res.headers['set-cookie']);
- res.setEncoding("utf8");
- res.addListener('data', function (chunk) { body += chunk; });
- res.addListener('end', function () {
+ res.setEncoding('utf8');
+ res.addListener('data', function(chunk) { body += chunk; });
+ res.addListener('end', function() {
proxy.close();
backend.close();
- common.debug("closed both");
+ common.debug('closed both');
});
});
req.end();
}
-common.debug("listen proxy")
+common.debug('listen proxy');
proxy.listen(PROXY_PORT, startReq);
-common.debug("listen backend")
+common.debug('listen backend');
backend.listen(BACKEND_PORT, startReq);
-process.addListener("exit", function () {
- assert.equal(body, "hello world\n");
+process.addListener('exit', function() {
+ assert.equal(body, 'hello world\n');
});
diff --git a/test/simple/test-http-server-multiheaders.js b/test/simple/test-http-server-multiheaders.js
index ad609c6ce3..f1fb09e84a 100644
--- a/test/simple/test-http-server-multiheaders.js
+++ b/test/simple/test-http-server-multiheaders.js
@@ -18,20 +18,19 @@ var srv = http.createServer(function(req, res) {
srv.close();
});
-srv.listen(common.PORT, function () {
+srv.listen(common.PORT, function() {
var hc = http.createClient(common.PORT, 'localhost');
var hr = hc.request('/',
- [
- ['accept', 'abc'],
- ['accept', 'def'],
- ['Accept', 'ghijklmnopqrst'],
- ['host', 'foo'],
- ['Host', 'bar'],
- ['hOst', 'baz'],
- ['x-foo', 'bingo'],
- ['x-bar', 'banjo'],
- ['x-bar', 'bango']
- ]
- );
+ [
+ ['accept', 'abc'],
+ ['accept', 'def'],
+ ['Accept', 'ghijklmnopqrst'],
+ ['host', 'foo'],
+ ['Host', 'bar'],
+ ['hOst', 'baz'],
+ ['x-foo', 'bingo'],
+ ['x-bar', 'banjo'],
+ ['x-bar', 'bango']
+ ]);
hr.end();
});
diff --git a/test/simple/test-http-server.js b/test/simple/test-http-server.js
index 1a1525b4fc..969b6d35d6 100644
--- a/test/simple/test-http-server.js
+++ b/test/simple/test-http-server.js
@@ -2,45 +2,45 @@ var common = require('../common');
var assert = require('assert');
var net = require('net');
var http = require('http');
-var url = require("url");
-var qs = require("querystring");
+var url = require('url');
+var qs = require('querystring');
var request_number = 0;
var requests_sent = 0;
-var server_response = "";
+var server_response = '';
var client_got_eof = false;
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
res.id = request_number;
req.id = request_number++;
if (req.id == 0) {
- assert.equal("GET", req.method);
- assert.equal("/hello", url.parse(req.url).pathname);
- assert.equal("world", qs.parse(url.parse(req.url).query).hello);
- assert.equal("b==ar", qs.parse(url.parse(req.url).query).foo);
+ assert.equal('GET', req.method);
+ assert.equal('/hello', url.parse(req.url).pathname);
+ assert.equal('world', qs.parse(url.parse(req.url).query).hello);
+ assert.equal('b==ar', qs.parse(url.parse(req.url).query).foo);
}
if (req.id == 1) {
- common.error("req 1");
- assert.equal("POST", req.method);
- assert.equal("/quit", url.parse(req.url).pathname);
+ common.error('req 1');
+ assert.equal('POST', req.method);
+ assert.equal('/quit', url.parse(req.url).pathname);
}
if (req.id == 2) {
- common.error("req 2");
- assert.equal("foo", req.headers['x-x']);
+ common.error('req 2');
+ assert.equal('foo', req.headers['x-x']);
}
if (req.id == 3) {
- common.error("req 3");
- assert.equal("bar", req.headers['x-x']);
+ common.error('req 3');
+ assert.equal('bar', req.headers['x-x']);
this.close();
- common.error("server closed");
+ common.error('server closed');
}
- setTimeout(function () {
- res.writeHead(200, {"Content-Type": "text/plain"});
+ setTimeout(function() {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(url.parse(req.url).pathname);
res.end();
}, 1);
@@ -48,51 +48,51 @@ var server = http.createServer(function (req, res) {
});
server.listen(common.PORT);
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var c = net.createConnection(common.PORT);
- c.setEncoding("utf8");
+ c.setEncoding('utf8');
- c.addListener("connect", function () {
- c.write( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" );
+ c.addListener('connect', function() {
+ c.write('GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n');
requests_sent += 1;
});
- c.addListener("data", function (chunk) {
+ c.addListener('data', function(chunk) {
server_response += chunk;
if (requests_sent == 1) {
- c.write("POST /quit HTTP/1.1\r\n\r\n");
+ c.write('POST /quit HTTP/1.1\r\n\r\n');
requests_sent += 1;
}
if (requests_sent == 2) {
- c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n"
- +"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n");
+ c.write('GET / HTTP/1.1\r\nX-X: foo\r\n\r\n' +
+ 'GET / HTTP/1.1\r\nX-X: bar\r\n\r\n');
c.end();
- assert.equal(c.readyState, "readOnly");
+ assert.equal(c.readyState, 'readOnly');
requests_sent += 2;
}
});
- c.addListener("end", function () {
+ c.addListener('end', function() {
client_got_eof = true;
});
- c.addListener("close", function () {
- assert.equal(c.readyState, "closed");
+ c.addListener('close', function() {
+ assert.equal(c.readyState, 'closed');
});
});
-process.addListener("exit", function () {
+process.addListener('exit', function() {
assert.equal(4, request_number);
assert.equal(4, requests_sent);
- var hello = new RegExp("/hello");
+ var hello = new RegExp('/hello');
assert.equal(true, hello.exec(server_response) != null);
- var quit = new RegExp("/quit");
+ var quit = new RegExp('/quit');
assert.equal(true, quit.exec(server_response) != null);
assert.equal(true, client_got_eof);
diff --git a/test/simple/test-http-set-cookies.js b/test/simple/test-http-set-cookies.js
index b99bf05a76..748f96bd25 100644
--- a/test/simple/test-http-set-cookies.js
+++ b/test/simple/test-http-set-cookies.js
@@ -1,24 +1,24 @@
var common = require('../common');
-var assert = require('assert');;
+var assert = require('assert');
var http = require('http');
var nresponses = 0;
var server = http.createServer(function(req, res) {
if (req.url == '/one') {
- res.writeHead(200, [ ['set-cookie', 'A'],
- ['content-type', 'text/plain'] ]);
- res.end("one\n");
+ res.writeHead(200, [['set-cookie', 'A'],
+ ['content-type', 'text/plain']]);
+ res.end('one\n');
} else {
- res.writeHead(200, [ ['set-cookie', 'A'],
- ['set-cookie', 'B'],
- ['content-type', 'text/plain'] ]);
- res.end("two\n");
+ res.writeHead(200, [['set-cookie', 'A'],
+ ['set-cookie', 'B'],
+ ['content-type', 'text/plain']]);
+ res.end('two\n');
}
});
server.listen(common.PORT);
-server.addListener("listening", function() {
+server.addListener('listening', function() {
//
// one set-cookie header
//
@@ -66,6 +66,6 @@ server.addListener("listening", function() {
});
-process.addListener("exit", function () {
+process.addListener('exit', function() {
assert.equal(2, nresponses);
});
diff --git a/test/simple/test-http-set-timeout.js b/test/simple/test-http-set-timeout.js
index 5e0bae5214..1ae3229cae 100644
--- a/test/simple/test-http-set-timeout.js
+++ b/test/simple/test-http-set-timeout.js
@@ -1,26 +1,27 @@
var common = require('../common');
-var assert = require('assert');;
+var assert = require('assert');
var http = require('http');
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
console.log('got request. setting 1 second timeout');
req.connection.setTimeout(500);
- req.connection.addListener('timeout', function(){
- common.debug("TIMEOUT");
+ req.connection.addListener('timeout', function() {
+ common.debug('TIMEOUT');
server.close();
});
});
-server.listen(common.PORT, function () {
- console.log('Server running at http://127.0.0.1:'+common.PORT+'/');
+server.listen(common.PORT, function() {
+ console.log('Server running at http://127.0.0.1:' + common.PORT + '/');
- var errorTimer = setTimeout(function () {
+ var errorTimer = setTimeout(function() {
throw new Error('Timeout was not sucessful');
}, 2000);
- http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) {
- clearTimeout(errorTimer);
- console.log('HTTP REQUEST COMPLETE (this is good)');
- });
+ http.cat('http://localhost:' + common.PORT + '/', 'utf8',
+ function(err, content) {
+ clearTimeout(errorTimer);
+ console.log('HTTP REQUEST COMPLETE (this is good)');
+ });
});
diff --git a/test/simple/test-http-set-trailers.js b/test/simple/test-http-set-trailers.js
index 35d2b9ede5..67fe567f67 100644
--- a/test/simple/test-http-set-trailers.js
+++ b/test/simple/test-http-set-trailers.js
@@ -6,69 +6,69 @@ var net = require('net');
var outstanding_reqs = 0;
var server = http.createServer(function(req, res) {
- res.writeHead(200, [ ['content-type', 'text/plain'] ]);
- res.addTrailers({"x-foo": "bar"});
- res.end("stuff" + "\n");
+ res.writeHead(200, [['content-type', 'text/plain']]);
+ res.addTrailers({'x-foo': 'bar'});
+ res.end('stuff' + '\n');
});
server.listen(common.PORT);
// first, we test an HTTP/1.0 request.
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var c = net.createConnection(common.PORT);
- var res_buffer = "";
+ var res_buffer = '';
- c.setEncoding("utf8");
+ c.setEncoding('utf8');
- c.addListener("connect", function () {
+ c.addListener('connect', function() {
outstanding_reqs++;
- c.write( "GET / HTTP/1.0\r\n\r\n" );
+ c.write('GET / HTTP/1.0\r\n\r\n');
});
- c.addListener("data", function (chunk) {
-// console.log(chunk);
+ c.addListener('data', function(chunk) {
+ //console.log(chunk);
res_buffer += chunk;
});
- c.addListener("end", function () {
+ c.addListener('end', function() {
c.end();
- assert.ok(! /x-foo/.test(res_buffer), "Trailer in HTTP/1.0 response.");
+ assert.ok(! /x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
- server.close();
- process.exit();
+ server.close();
+ process.exit();
}
});
});
// now, we test an HTTP/1.1 request.
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var c = net.createConnection(common.PORT);
- var res_buffer = "";
+ var res_buffer = '';
var tid;
- c.setEncoding("utf8");
+ c.setEncoding('utf8');
- c.addListener("connect", function () {
+ c.addListener('connect', function() {
outstanding_reqs++;
- c.write( "GET / HTTP/1.1\r\n\r\n" );
- tid = setTimeout(assert.fail, 2000, "Couldn't find last chunk.");
+ c.write('GET / HTTP/1.1\r\n\r\n');
+ tid = setTimeout(assert.fail, 2000, 'Couldn\'t find last chunk.');
});
- c.addListener("data", function (chunk) {
-// console.log(chunk);
+ c.addListener('data', function(chunk) {
+ //console.log(chunk);
res_buffer += chunk;
if (/0\r\n/.test(res_buffer)) { // got the end.
- outstanding_reqs--;
- clearTimeout(tid);
- assert.ok(
- /0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer),
- "No trailer in HTTP/1.1 response."
- );
- if (outstanding_reqs == 0) {
- server.close();
- process.exit();
- }
+ outstanding_reqs--;
+ clearTimeout(tid);
+ assert.ok(
+ /0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer),
+ 'No trailer in HTTP/1.1 response.'
+ );
+ if (outstanding_reqs == 0) {
+ server.close();
+ process.exit();
+ }
}
});
});
@@ -76,14 +76,13 @@ server.addListener("listening", function() {
// now, see if the client sees the trailers.
server.addListener('listening', function() {
var client = http.createClient(common.PORT);
- var req = client.request("/hello", {});
+ var req = client.request('/hello', {});
req.end();
outstanding_reqs++;
- req.addListener('response', function (res) {
- res.addListener('end', function () {
-// console.log(res.trailers);
- assert.ok("x-foo" in res.trailers,
- "Client doesn't see trailers.");
+ req.addListener('response', function(res) {
+ res.addListener('end', function() {
+ //console.log(res.trailers);
+ assert.ok('x-foo' in res.trailers, 'Client doesn\'t see trailers.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
server.close();
diff --git a/test/simple/test-http-upgrade-client.js b/test/simple/test-http-upgrade-client.js
index 84bdaf11c6..386f1a26fa 100644
--- a/test/simple/test-http-upgrade-client.js
+++ b/test/simple/test-http-upgrade-client.js
@@ -10,47 +10,47 @@ var net = require('net');
// Create a TCP server
var srv = net.createServer(function(c) {
- var data = '';
- c.addListener('data', function(d) {
- data += d.toString('utf8');
-
- c.write('HTTP/1.1 101\r\n');
- c.write('hello: world\r\n');
- c.write('connection: upgrade\r\n');
- c.write('upgrade: websocket\r\n');
- c.write('\r\n');
- c.write('nurtzo');
- });
-
- c.addListener('end', function() {
- c.end();
- });
+ var data = '';
+ c.addListener('data', function(d) {
+ data += d.toString('utf8');
+
+ c.write('HTTP/1.1 101\r\n');
+ c.write('hello: world\r\n');
+ c.write('connection: upgrade\r\n');
+ c.write('upgrade: websocket\r\n');
+ c.write('\r\n');
+ c.write('nurtzo');
+ });
+
+ c.addListener('end', function() {
+ c.end();
+ });
});
var gotUpgrade = false;
-srv.listen(common.PORT, '127.0.0.1', function () {
+srv.listen(common.PORT, '127.0.0.1', function() {
var hc = http.createClient(common.PORT, '127.0.0.1');
hc.addListener('upgrade', function(res, socket, upgradeHead) {
- // XXX: This test isn't fantastic, as it assumes that the entire response
- // from the server will arrive in a single data callback
- assert.equal(upgradeHead, 'nurtzo');
+ // XXX: This test isn't fantastic, as it assumes that the entire response
+ // from the server will arrive in a single data callback
+ assert.equal(upgradeHead, 'nurtzo');
- console.log(res.headers);
- var expectedHeaders = { "hello": "world",
- "connection": "upgrade",
- "upgrade": "websocket" };
- assert.deepEqual(expectedHeaders, res.headers);
+ console.log(res.headers);
+ var expectedHeaders = {'hello': 'world',
+ 'connection': 'upgrade',
+ 'upgrade': 'websocket' };
+ assert.deepEqual(expectedHeaders, res.headers);
- socket.end();
- srv.close();
+ socket.end();
+ srv.close();
- gotUpgrade = true;
+ gotUpgrade = true;
});
hc.request('GET', '/').end();
});
process.addListener('exit', function() {
- assert.ok(gotUpgrade);
+ assert.ok(gotUpgrade);
});
diff --git a/test/simple/test-http-upgrade-client2.js b/test/simple/test-http-upgrade-client2.js
index 3550f70f5d..14a2fa1798 100644
--- a/test/simple/test-http-upgrade-client2.js
+++ b/test/simple/test-http-upgrade-client2.js
@@ -1,4 +1,4 @@
-var common = require("../common");
+var common = require('../common');
var assert = require('assert');
var http = require('http');
@@ -9,14 +9,14 @@ server.on('upgrade', function(req, socket, head) {
socket.write('HTTP/1.1 101 Ok' + CRLF +
'Connection: Upgrade' + CRLF +
'Upgrade: Test' + CRLF + CRLF + 'head');
- socket.on('end', function () {
+ socket.on('end', function() {
socket.end();
});
});
var successCount = 0;
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
var client = http.createClient(common.PORT);
@@ -61,6 +61,6 @@ server.listen(common.PORT, function () {
});
-process.on('exit', function () {
+process.on('exit', function() {
assert.equal(2, successCount);
});
diff --git a/test/simple/test-http-upgrade-server.js b/test/simple/test-http-upgrade-server.js
index 8662df4df7..26cd133c03 100644
--- a/test/simple/test-http-upgrade-server.js
+++ b/test/simple/test-http-upgrade-server.js
@@ -1,149 +1,154 @@
var common = require('../common');
var assert = require('assert');
-var util = require("util");
-var net = require("net");
-var http = require("http");
+var util = require('util');
+var net = require('net');
+var http = require('http');
var requests_recv = 0;
var requests_sent = 0;
var request_upgradeHead = null;
-function createTestServer(){
+function createTestServer() {
return new testServer();
-};
+}
-function testServer(){
+function testServer() {
var server = this;
- http.Server.call(server, function(){});
+ http.Server.call(server, function() {});
- server.addListener("connection", function(){
+ server.addListener('connection', function() {
requests_recv++;
});
- server.addListener("request", function(req, res){
- res.writeHead(200, {"Content-Type": "text/plain"});
- res.write("okay");
+ server.addListener('request', function(req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.write('okay');
res.end();
});
- server.addListener("upgrade", function(req, socket, upgradeHead){
- socket.write("HTTP/1.1 101 Web Socket Protocol Handshake\r\n" +
- "Upgrade: WebSocket\r\n" +
- "Connection: Upgrade\r\n" +
- "\r\n\r\n");
+ server.addListener('upgrade', function(req, socket, upgradeHead) {
+ socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ '\r\n\r\n');
request_upgradeHead = upgradeHead;
- socket.ondata = function(d, start, end){
+ socket.ondata = function(d, start, end) {
var data = d.toString('utf8', start, end);
- if(data == "kill"){
+ if (data == 'kill') {
socket.end();
} else {
- socket.write(data, "utf8");
+ socket.write(data, 'utf8');
}
};
});
-};
+}
util.inherits(testServer, http.Server);
-function writeReq(socket, data, encoding){
+function writeReq(socket, data, encoding) {
requests_sent++;
socket.write(data);
-};
+}
/*-----------------------------------------------
connection: Upgrade with listener
-----------------------------------------------*/
-function test_upgrade_with_listener(_server){
+function test_upgrade_with_listener(_server) {
var conn = net.createConnection(common.PORT);
- conn.setEncoding("utf8");
+ conn.setEncoding('utf8');
var state = 0;
- conn.addListener("connect", function () {
- writeReq(conn, "GET / HTTP/1.1\r\n" +
- "Upgrade: WebSocket\r\n" +
- "Connection: Upgrade\r\n" +
- "\r\n" +
- "WjN}|M(6");
+ conn.addListener('connect', function() {
+ writeReq(conn,
+ 'GET / HTTP/1.1\r\n' +
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ '\r\n' +
+ 'WjN}|M(6');
});
- conn.addListener("data", function (data) {
+ conn.addListener('data', function(data) {
state++;
assert.equal('string', typeof data);
- if(state == 1) {
- assert.equal("HTTP/1.1 101", data.substr(0, 12));
- assert.equal("WjN}|M(6", request_upgradeHead.toString("utf8"));
- conn.write("test", "utf8");
- } else if(state == 2) {
- assert.equal("test", data);
- conn.write("kill", "utf8");
+ if (state == 1) {
+ assert.equal('HTTP/1.1 101', data.substr(0, 12));
+ assert.equal('WjN}|M(6', request_upgradeHead.toString('utf8'));
+ conn.write('test', 'utf8');
+ } else if (state == 2) {
+ assert.equal('test', data);
+ conn.write('kill', 'utf8');
}
});
- conn.addListener("end", function(){
+ conn.addListener('end', function() {
assert.equal(2, state);
conn.end();
- _server.removeAllListeners("upgrade");
+ _server.removeAllListeners('upgrade');
test_upgrade_no_listener();
});
-};
+}
/*-----------------------------------------------
connection: Upgrade, no listener
-----------------------------------------------*/
var test_upgrade_no_listener_ended = false;
-function test_upgrade_no_listener(){
+function test_upgrade_no_listener() {
var conn = net.createConnection(common.PORT);
- conn.setEncoding("utf8");
-
- conn.addListener("connect", function () {
- writeReq(conn, "GET / HTTP/1.1\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\n\r\n");
+ conn.setEncoding('utf8');
+
+ conn.addListener('connect', function() {
+ writeReq(conn,
+ 'GET / HTTP/1.1\r\n' +
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ '\r\n');
});
- conn.addListener("end", function(){
+ conn.addListener('end', function() {
test_upgrade_no_listener_ended = true;
conn.end();
});
- conn.addListener("close", function(){
+ conn.addListener('close', function() {
test_standard_http();
});
-};
+}
/*-----------------------------------------------
connection: normal
-----------------------------------------------*/
-function test_standard_http(){
+function test_standard_http() {
var conn = net.createConnection(common.PORT);
- conn.setEncoding("utf8");
+ conn.setEncoding('utf8');
- conn.addListener("connect", function () {
- writeReq(conn, "GET / HTTP/1.1\r\n\r\n");
+ conn.addListener('connect', function() {
+ writeReq(conn, 'GET / HTTP/1.1\r\n\r\n');
});
- conn.addListener("data", function(data){
- assert.equal("string", typeof data);
- assert.equal("HTTP/1.1 200", data.substr(0, 12));
+ conn.addListener('data', function(data) {
+ assert.equal('string', typeof data);
+ assert.equal('HTTP/1.1 200', data.substr(0, 12));
conn.end();
});
- conn.addListener("close", function(){
+ conn.addListener('close', function() {
server.close();
});
-};
+}
var server = createTestServer();
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
// All tests get chained after this:
test_upgrade_with_listener(server);
});
@@ -152,7 +157,7 @@ server.listen(common.PORT, function () {
/*-----------------------------------------------
Fin.
-----------------------------------------------*/
-process.addListener("exit", function () {
+process.addListener('exit', function() {
assert.equal(3, requests_recv);
assert.equal(3, requests_sent);
assert.ok(test_upgrade_no_listener_ended);
diff --git a/test/simple/test-http-upgrade-server2.js b/test/simple/test-http-upgrade-server2.js
index d80768ca37..fd84ebe8ca 100644
--- a/test/simple/test-http-upgrade-server2.js
+++ b/test/simple/test-http-upgrade-server2.js
@@ -3,12 +3,12 @@ var assert = require('assert');
var http = require('http');
var net = require('net');
-var server = http.createServer(function (req, res) {
+var server = http.createServer(function(req, res) {
common.error('got req');
- throw new Error("This shouldn't happen.");
+ throw new Error('This shouldn\'t happen.');
});
-server.addListener('upgrade', function (req, socket, upgradeHead) {
+server.addListener('upgrade', function(req, socket, upgradeHead) {
common.error('got upgrade event');
// test that throwing an error from upgrade gets
// is uncaught
@@ -17,35 +17,35 @@ server.addListener('upgrade', function (req, socket, upgradeHead) {
var gotError = false;
-process.addListener('uncaughtException', function (e) {
- common.error('got "clientError" event');
+process.addListener('uncaughtException', function(e) {
+ common.error('got \'clientError\' event');
assert.equal('upgrade error', e.message);
gotError = true;
process.exit(0);
});
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
var c = net.createConnection(common.PORT);
- c.addListener('connect', function () {
+ c.addListener('connect', function() {
common.error('client wrote message');
- c.write("GET /blah HTTP/1.1\r\n" +
- "Upgrade: WebSocket\r\n" +
- "Connection: Upgrade\r\n" +
- "\r\n\r\nhello world");
+ c.write('GET /blah HTTP/1.1\r\n' +
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ '\r\n\r\nhello world');
});
- c.addListener('end', function () {
+ c.addListener('end', function() {
c.end();
});
- c.addListener('close', function () {
+ c.addListener('close', function() {
common.error('client close');
server.close();
});
});
-process.addListener('exit', function () {
+process.addListener('exit', function() {
assert.ok(gotError);
});
diff --git a/test/simple/test-http-wget.js b/test/simple/test-http-wget.js
index 1fa970bd9c..3a977ae8ee 100644
--- a/test/simple/test-http-wget.js
+++ b/test/simple/test-http-wget.js
@@ -18,49 +18,49 @@ var http = require('http');
// content-length is not provided, that the connection is in fact
// closed.
-var server_response = "";
+var server_response = '';
var client_got_eof = false;
var connection_was_closed = false;
-var server = http.createServer(function (req, res) {
- res.writeHead(200, {"Content-Type": "text/plain"});
- res.write("hello ");
- res.write("world\n");
+var server = http.createServer(function(req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.write('hello ');
+ res.write('world\n');
res.end();
});
server.listen(common.PORT);
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var c = net.createConnection(common.PORT);
- c.setEncoding("utf8");
+ c.setEncoding('utf8');
- c.addListener("connect", function () {
- c.write("GET / HTTP/1.0\r\n" +
- "Connection: Keep-Alive\r\n\r\n");
+ c.addListener('connect', function() {
+ c.write('GET / HTTP/1.0\r\n' +
+ 'Connection: Keep-Alive\r\n\r\n');
});
- c.addListener("data", function (chunk) {
+ c.addListener('data', function(chunk) {
console.log(chunk);
server_response += chunk;
});
- c.addListener("end", function () {
+ c.addListener('end', function() {
client_got_eof = true;
console.log('got end');
c.end();
});
- c.addListener("close", function () {
+ c.addListener('close', function() {
connection_was_closed = true;
console.log('got close');
server.close();
});
});
-process.addListener("exit", function () {
- var m = server_response.split("\r\n\r\n");
- assert.equal(m[1], "hello world\n");
+process.addListener('exit', function() {
+ var m = server_response.split('\r\n\r\n');
+ assert.equal(m[1], 'hello world\n');
assert.ok(client_got_eof);
assert.ok(connection_was_closed);
});
diff --git a/test/simple/test-http-write-empty-string.js b/test/simple/test-http-write-empty-string.js
index 5378d81777..39c2f613d9 100644
--- a/test/simple/test-http-write-empty-string.js
+++ b/test/simple/test-http-write-empty-string.js
@@ -3,7 +3,7 @@ var assert = require('assert');
var http = require('http');
-var server = http.createServer(function (request, response) {
+var server = http.createServer(function(request, response) {
console.log('responding to ' + request.url);
response.writeHead(200, {'Content-Type': 'text/plain'});
@@ -14,26 +14,26 @@ var server = http.createServer(function (request, response) {
response.end('3\n');
this.close();
-})
+});
-var response="";
+var response = '';
-process.addListener('exit', function () {
+process.addListener('exit', function() {
assert.equal('1\n2\n3\n', response);
});
-server.listen(common.PORT, function () {
+server.listen(common.PORT, function() {
var client = http.createClient(common.PORT);
- var req = client.request("/");
+ var req = client.request('/');
req.end();
- req.addListener('response', function (res) {
+ req.addListener('response', function(res) {
assert.equal(200, res.statusCode);
- res.setEncoding("ascii");
- res.addListener('data', function (chunk) {
+ res.setEncoding('ascii');
+ res.addListener('data', function(chunk) {
response += chunk;
});
- common.error("Got /hello response");
+ common.error('Got /hello response');
});
});
diff --git a/test/simple/test-http.js b/test/simple/test-http.js
index 824f722e1e..0e2a420fad 100644
--- a/test/simple/test-http.js
+++ b/test/simple/test-http.js
@@ -1,80 +1,80 @@
var common = require('../common');
var assert = require('assert');
var http = require('http');
-var url = require("url");
+var url = require('url');
-function p (x) {
+function p(x) {
common.error(common.inspect(x));
}
var responses_sent = 0;
var responses_recvd = 0;
-var body0 = "";
-var body1 = "";
+var body0 = '';
+var body1 = '';
-var server = http.Server(function (req, res) {
+var server = http.Server(function(req, res) {
if (responses_sent == 0) {
- assert.equal("GET", req.method);
- assert.equal("/hello", url.parse(req.url).pathname);
+ assert.equal('GET', req.method);
+ assert.equal('/hello', url.parse(req.url).pathname);
console.dir(req.headers);
- assert.equal(true, "accept" in req.headers);
- assert.equal("*/*", req.headers["accept"]);
+ assert.equal(true, 'accept' in req.headers);
+ assert.equal('*/*', req.headers['accept']);
- assert.equal(true, "foo" in req.headers);
- assert.equal("bar", req.headers["foo"]);
+ assert.equal(true, 'foo' in req.headers);
+ assert.equal('bar', req.headers['foo']);
}
if (responses_sent == 1) {
- assert.equal("POST", req.method);
- assert.equal("/world", url.parse(req.url).pathname);
+ assert.equal('POST', req.method);
+ assert.equal('/world', url.parse(req.url).pathname);
this.close();
}
- req.addListener('end', function () {
- res.writeHead(200, {"Content-Type": "text/plain"});
- res.write("The path was " + url.parse(req.url).pathname);
+ req.addListener('end', function() {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.write('The path was ' + url.parse(req.url).pathname);
res.end();
responses_sent += 1;
});
- //assert.equal("127.0.0.1", res.connection.remoteAddress);
+ //assert.equal('127.0.0.1', res.connection.remoteAddress);
});
server.listen(common.PORT);
-server.addListener("listening", function() {
+server.addListener('listening', function() {
var client = http.createClient(common.PORT);
- var req = client.request("/hello", {"Accept": "*/*", "Foo": "bar"});
+ var req = client.request('/hello', {'Accept': '*/*', 'Foo': 'bar'});
req.end();
- req.addListener('response', function (res) {
+ req.addListener('response', function(res) {
assert.equal(200, res.statusCode);
responses_recvd += 1;
- res.setEncoding("utf8");
- res.addListener('data', function (chunk) { body0 += chunk; });
- common.debug("Got /hello response");
+ res.setEncoding('utf8');
+ res.addListener('data', function(chunk) { body0 += chunk; });
+ common.debug('Got /hello response');
});
- setTimeout(function () {
- req = client.request("POST", "/world");
+ setTimeout(function() {
+ req = client.request('POST', '/world');
req.end();
- req.addListener('response',function (res) {
+ req.addListener('response', function(res) {
assert.equal(200, res.statusCode);
responses_recvd += 1;
- res.setEncoding("utf8");
- res.addListener('data', function (chunk) { body1 += chunk; });
- common.debug("Got /world response");
+ res.setEncoding('utf8');
+ res.addListener('data', function(chunk) { body1 += chunk; });
+ common.debug('Got /world response');
});
}, 1);
});
-process.addListener("exit", function () {
- common.debug("responses_recvd: " + responses_recvd);
+process.addListener('exit', function() {
+ common.debug('responses_recvd: ' + responses_recvd);
assert.equal(2, responses_recvd);
- common.debug("responses_sent: " + responses_sent);
+ common.debug('responses_sent: ' + responses_sent);
assert.equal(2, responses_sent);
- assert.equal("The path was /hello", body0);
- assert.equal("The path was /world", body1);
+ assert.equal('The path was /hello', body0);
+ assert.equal('The path was /world', body1);
});
diff --git a/test/simple/test-path.js b/test/simple/test-path.js
index cb78071c2c..5a9b936ba7 100644
--- a/test/simple/test-path.js
+++ b/test/simple/test-path.js
@@ -41,75 +41,79 @@ assert.equal(path.extname('file.'), '.');
// path.join tests
var failures = [];
var joinTests =
- // arguments result
- [[['.', 'x/b', '..', '/b/c.js' ], 'x/b/c.js' ]
- ,[['/.', 'x/b', '..', '/b/c.js' ], '/x/b/c.js' ]
- ,[['/foo', '../../../bar' ], '/bar' ]
- ,[['foo', '../../../bar' ], '../../bar' ]
- ,[['foo/', '../../../bar' ], '../../bar' ]
- ,[['foo/x', '../../../bar' ], '../bar' ]
- ,[['foo/x', './bar' ], 'foo/x/bar' ]
- ,[['foo/x/', './bar' ], 'foo/x/bar' ]
- ,[['foo/x/', '.', 'bar' ], 'foo/x/bar' ]
- ,[['./' ], './' ]
- ,[['.', './' ], './' ]
- ,[['.', '.', '.' ], '.' ]
- ,[['.', './', '.' ], '.' ]
- ,[['.', '/./', '.' ], '.' ]
- ,[['.', '/////./', '.' ], '.' ]
- ,[['.' ], '.' ]
- ,[['','.' ], '.' ]
- ,[['', 'foo' ], 'foo' ]
- ,[['foo', '/bar' ], 'foo/bar' ]
- ,[['', '/foo' ], '/foo' ]
- ,[['', '', '/foo' ], '/foo' ]
- ,[['', '', 'foo' ], 'foo' ]
- ,[['foo', '' ], 'foo' ]
- ,[['foo/', '' ], 'foo/' ]
- ,[['foo', '', '/bar' ], 'foo/bar' ]
- ,[['./', '..', '/foo' ], '../foo' ]
- ,[['./', '..', '..', '/foo' ], '../../foo' ]
- ,[['.', '..', '..', '/foo' ], '../../foo' ]
- ,[['', '..', '..', '/foo' ], '../../foo' ]
- ,[['/' ], '/' ]
- ,[['/', '.' ], '/' ]
- ,[['/', '..' ], '/' ]
- ,[['/', '..', '..' ], '/' ]
- ,[['' ], '.' ]
- ,[['', '' ], '.' ]
- ,[[' /foo' ], ' /foo' ]
- ,[[' ', 'foo' ], ' /foo' ]
- ,[[' ', '.' ], ' ' ]
- ,[[' ', '/' ], ' /' ]
- ,[[' ', '' ], ' ' ]
- // preserving empty path parts, for url resolution case
- // pass boolean true as LAST argument.
- ,[['', '', true ], '/' ]
- ,[['foo', '', true ], 'foo/' ]
- ,[['foo', '', 'bar', true ], 'foo//bar' ]
- ,[['foo/', '', 'bar', true ], 'foo///bar' ]
- ,[['', true ], '.' ]
- // filtration of non-strings.
- ,[['x', true, 7, 'y', null, {} ], 'x/y' ]
- ];
+ // arguments result
+ [[['.', 'x/b', '..', '/b/c.js'], 'x/b/c.js'],
+ [['/.', 'x/b', '..', '/b/c.js'], '/x/b/c.js'],
+ [['/foo', '../../../bar'], '/bar'],
+ [['foo', '../../../bar'], '../../bar'],
+ [['foo/', '../../../bar'], '../../bar'],
+ [['foo/x', '../../../bar'], '../bar'],
+ [['foo/x', './bar'], 'foo/x/bar'],
+ [['foo/x/', './bar'], 'foo/x/bar'],
+ [['foo/x/', '.', 'bar'], 'foo/x/bar'],
+ [['./'], './'],
+ [['.', './'], './'],
+ [['.', '.', '.'], '.'],
+ [['.', './', '.'], '.'],
+ [['.', '/./', '.'], '.'],
+ [['.', '/////./', '.'], '.'],
+ [['.'], '.'],
+ [['', '.'], '.'],
+ [['', 'foo'], 'foo'],
+ [['foo', '/bar'], 'foo/bar'],
+ [['', '/foo'], '/foo'],
+ [['', '', '/foo'], '/foo'],
+ [['', '', 'foo'], 'foo'],
+ [['foo', ''], 'foo'],
+ [['foo/', ''], 'foo/'],
+ [['foo', '', '/bar'], 'foo/bar'],
+ [['./', '..', '/foo'], '../foo'],
+ [['./', '..', '..', '/foo'], '../../foo'],
+ [['.', '..', '..', '/foo'], '../../foo'],
+ [['', '..', '..', '/foo'], '../../foo'],
+ [['/'], '/'],
+ [['/', '.'], '/'],
+ [['/', '..'], '/'],
+ [['/', '..', '..'], '/'],
+ [[''], '.'],
+ [['', ''], '.'],
+ [[' /foo'], ' /foo'],
+ [[' ', 'foo'], ' /foo'],
+ [[' ', '.'], ' '],
+ [[' ', '/'], ' /'],
+ [[' ', ''], ' '],
+ // preserving empty path parts, for url resolution case
+ // pass boolean true as LAST argument.
+ [['', '', true], '/'],
+ [['foo', '', true], 'foo/'],
+ [['foo', '', 'bar', true], 'foo//bar'],
+ [['foo/', '', 'bar', true], 'foo///bar'],
+ [['', true], '.'],
+ // filtration of non-strings.
+ [['x', true, 7, 'y', null, {}], 'x/y']
+ ];
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('./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');
diff --git a/test/simple/test-url.js b/test/simple/test-url.js
index dd01e3a163..c59e92bec3 100644
--- a/test/simple/test-url.js
+++ b/test/simple/test-url.js
@@ -7,251 +7,273 @@ var url = require('url'),
// URLs to parse, and expected data
// { url : parsed }
var parseTests = {
- "//some_path" : {
- "href": "//some_path",
- "pathname": "//some_path"
+ '//some_path' : {
+ 'href': '//some_path',
+ 'pathname': '//some_path'
},
- "http://www.narwhaljs.org/blog/categories?id=news" : {
- "href": "http://www.narwhaljs.org/blog/categories?id=news",
- "protocol": "http:",
- "host": "www.narwhaljs.org",
- "hostname": "www.narwhaljs.org",
- "search": "?id=news",
- "query": "id=news",
- "pathname": "/blog/categories"
+ 'http://www.narwhaljs.org/blog/categories?id=news' : {
+ 'href': 'http://www.narwhaljs.org/blog/categories?id=news',
+ 'protocol': 'http:',
+ 'host': 'www.narwhaljs.org',
+ 'hostname': 'www.narwhaljs.org',
+ 'search': '?id=news',
+ 'query': 'id=news',
+ 'pathname': '/blog/categories'
},
- "http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=" : {
- "href": "http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=",
- "protocol": "http:",
- "host": "mt0.google.com",
- "hostname": "mt0.google.com",
- "pathname": "/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s="
+ 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=' : {
+ 'href': 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=',
+ 'protocol': 'http:',
+ 'host': 'mt0.google.com',
+ 'hostname': 'mt0.google.com',
+ 'pathname': '/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s='
},
- "http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=" : {
- "href": "http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=",
- "protocol": "http:",
- "host": "mt0.google.com",
- "hostname": "mt0.google.com",
- "search": "???&hl=en&src=api&x=2&y=2&z=3&s=",
- "query": "??&hl=en&src=api&x=2&y=2&z=3&s=",
- "pathname": "/vt/lyrs=m@114"
+ 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' : {
+ 'href': 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=',
+ 'protocol': 'http:',
+ 'host': 'mt0.google.com',
+ 'hostname': 'mt0.google.com',
+ 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',
+ 'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
+ 'pathname': '/vt/lyrs=m@114'
},
- "http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=" : {
- "href": "http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=",
- "protocol": "http:",
- "host": "user:pass@mt0.google.com",
- "auth": "user:pass",
- "hostname": "mt0.google.com",
- "search": "???&hl=en&src=api&x=2&y=2&z=3&s=",
- "query": "??&hl=en&src=api&x=2&y=2&z=3&s=",
- "pathname": "/vt/lyrs=m@114"
+ 'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' : {
+ 'href': 'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=',
+ 'protocol': 'http:',
+ 'host': 'user:pass@mt0.google.com',
+ 'auth': 'user:pass',
+ 'hostname': 'mt0.google.com',
+ 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',
+ 'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
+ 'pathname': '/vt/lyrs=m@114'
},
- "file:///etc/passwd" : {
- "href": "file:///etc/passwd",
- "protocol": "file:",
- "pathname": "///etc/passwd"
+ 'file:///etc/passwd' : {
+ 'href': 'file:///etc/passwd',
+ 'protocol': 'file:',
+ 'pathname': '///etc/passwd'
},
- "file:///etc/node/" : {
- "href": "file:///etc/node/",
- "protocol": "file:",
- "pathname": "///etc/node/"
+ 'file:///etc/node/' : {
+ 'href': 'file:///etc/node/',
+ 'protocol': 'file:',
+ 'pathname': '///etc/node/'
},
- "http:/baz/../foo/bar" : {
- "href": "http:/baz/../foo/bar",
- "protocol": "http:",
- "pathname": "/baz/../foo/bar"
+ 'http:/baz/../foo/bar' : {
+ 'href': 'http:/baz/../foo/bar',
+ 'protocol': 'http:',
+ 'pathname': '/baz/../foo/bar'
},
- "http://user:pass@example.com:8000/foo/bar?baz=quux#frag" : {
- "href": "http://user:pass@example.com:8000/foo/bar?baz=quux#frag",
- "protocol": "http:",
- "host": "user:pass@example.com:8000",
- "auth": "user:pass",
- "port": "8000",
- "hostname": "example.com",
- "hash": "#frag",
- "search": "?baz=quux",
- "query": "baz=quux",
- "pathname": "/foo/bar"
+ 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag' : {
+ 'href': 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag',
+ 'protocol': 'http:',
+ 'host': 'user:pass@example.com:8000',
+ 'auth': 'user:pass',
+ 'port': '8000',
+ 'hostname': 'example.com',
+ 'hash': '#frag',
+ 'search': '?baz=quux',
+ 'query': 'baz=quux',
+ 'pathname': '/foo/bar'
},
- "//user:pass@example.com:8000/foo/bar?baz=quux#frag" : {
- "href": "//user:pass@example.com:8000/foo/bar?baz=quux#frag",
- "host": "user:pass@example.com:8000",
- "auth": "user:pass",
- "port": "8000",
- "hostname": "example.com",
- "hash": "#frag",
- "search": "?baz=quux",
- "query": "baz=quux",
- "pathname": "/foo/bar"
+ '//user:pass@example.com:8000/foo/bar?baz=quux#frag' : {
+ 'href': '//user:pass@example.com:8000/foo/bar?baz=quux#frag',
+ 'host': 'user:pass@example.com:8000',
+ 'auth': 'user:pass',
+ 'port': '8000',
+ 'hostname': 'example.com',
+ 'hash': '#frag',
+ 'search': '?baz=quux',
+ 'query': 'baz=quux',
+ 'pathname': '/foo/bar'
},
- "http://example.com?foo=bar#frag" : {
- "href": "http://example.com?foo=bar#frag",
- "protocol": "http:",
- "host": "example.com",
- "hostname": "example.com",
- "hash": "#frag",
- "search": "?foo=bar",
- "query": "foo=bar"
+ 'http://example.com?foo=bar#frag' : {
+ 'href': 'http://example.com?foo=bar#frag',
+ 'protocol': 'http:',
+ 'host': 'example.com',
+ 'hostname': 'example.com',
+ 'hash': '#frag',
+ 'search': '?foo=bar',
+ 'query': 'foo=bar'
},
- "http://example.com?foo=@bar#frag" : {
- "href": "http://example.com?foo=@bar#frag",
- "protocol": "http:",
- "host": "example.com",
- "hostname": "example.com",
- "hash": "#frag",
- "search": "?foo=@bar",
- "query": "foo=@bar"
+ 'http://example.com?foo=@bar#frag' : {
+ 'href': 'http://example.com?foo=@bar#frag',
+ 'protocol': 'http:',
+ 'host': 'example.com',
+ 'hostname': 'example.com',
+ 'hash': '#frag',
+ 'search': '?foo=@bar',
+ 'query': 'foo=@bar'
},
- "http://example.com?foo=/bar/#frag" : {
- "href": "http://example.com?foo=/bar/#frag",
- "protocol": "http:",
- "host": "example.com",
- "hostname": "example.com",
- "hash": "#frag",
- "search": "?foo=/bar/",
- "query": "foo=/bar/"
+ 'http://example.com?foo=/bar/#frag' : {
+ 'href': 'http://example.com?foo=/bar/#frag',
+ 'protocol': 'http:',
+ 'host': 'example.com',
+ 'hostname': 'example.com',
+ 'hash': '#frag',
+ 'search': '?foo=/bar/',
+ 'query': 'foo=/bar/'
},
- "http://example.com?foo=?bar/#frag" : {
- "href": "http://example.com?foo=?bar/#frag",
- "protocol": "http:",
- "host": "example.com",
- "hostname": "example.com",
- "hash": "#frag",
- "search": "?foo=?bar/",
- "query": "foo=?bar/"
+ 'http://example.com?foo=?bar/#frag' : {
+ 'href': 'http://example.com?foo=?bar/#frag',
+ 'protocol': 'http:',
+ 'host': 'example.com',
+ 'hostname': 'example.com',
+ 'hash': '#frag',
+ 'search': '?foo=?bar/',
+ 'query': 'foo=?bar/'
},
- "http://example.com#frag=?bar/#frag" : {
- "href": "http://example.com#frag=?bar/#frag",
- "protocol": "http:",
- "host": "example.com",
- "hostname": "example.com",
- "hash": "#frag=?bar/#frag"
+ 'http://example.com#frag=?bar/#frag' : {
+ 'href': 'http://example.com#frag=?bar/#frag',
+ 'protocol': 'http:',
+ 'host': 'example.com',
+ 'hostname': 'example.com',
+ 'hash': '#frag=?bar/#frag'
},
- "/foo/bar?baz=quux#frag" : {
- "href": "/foo/bar?baz=quux#frag",
- "hash": "#frag",
- "search": "?baz=quux",
- "query": "baz=quux",
- "pathname": "/foo/bar"
+ '/foo/bar?baz=quux#frag' : {
+ 'href': '/foo/bar?baz=quux#frag',
+ 'hash': '#frag',
+ 'search': '?baz=quux',
+ 'query': 'baz=quux',
+ 'pathname': '/foo/bar'
},
- "http:/foo/bar?baz=quux#frag" : {
- "href": "http:/foo/bar?baz=quux#frag",
- "protocol": "http:",
- "hash": "#frag",
- "search": "?baz=quux",
- "query": "baz=quux",
- "pathname": "/foo/bar"
+ 'http:/foo/bar?baz=quux#frag' : {
+ 'href': 'http:/foo/bar?baz=quux#frag',
+ 'protocol': 'http:',
+ 'hash': '#frag',
+ 'search': '?baz=quux',
+ 'query': 'baz=quux',
+ 'pathname': '/foo/bar'
},
- "mailto:foo@bar.com?subject=hello" : {
- "href": "mailto:foo@bar.com?subject=hello",
- "protocol": "mailto:",
- "host": "foo@bar.com",
- "auth" : "foo",
- "hostname" : "bar.com",
- "search": "?subject=hello",
- "query": "subject=hello"
+ 'mailto:foo@bar.com?subject=hello' : {
+ 'href': 'mailto:foo@bar.com?subject=hello',
+ 'protocol': 'mailto:',
+ 'host': 'foo@bar.com',
+ 'auth' : 'foo',
+ 'hostname' : 'bar.com',
+ 'search': '?subject=hello',
+ 'query': 'subject=hello'
},
- "javascript:alert('hello');" : {
- "href": "javascript:alert('hello');",
- "protocol": "javascript:",
- "host": "alert('hello')",
- "hostname": "alert('hello')",
- "pathname" : ";"
+ 'javascript:alert(\'hello\');' : {
+ 'href': 'javascript:alert(\'hello\');',
+ 'protocol': 'javascript:',
+ 'host': 'alert(\'hello\')',
+ 'hostname': 'alert(\'hello\')',
+ 'pathname' : ';'
},
- "xmpp:isaacschlueter@jabber.org" : {
- "href": "xmpp:isaacschlueter@jabber.org",
- "protocol": "xmpp:",
- "host": "isaacschlueter@jabber.org",
- "auth": "isaacschlueter",
- "hostname": "jabber.org"
+ 'xmpp:isaacschlueter@jabber.org' : {
+ 'href': 'xmpp:isaacschlueter@jabber.org',
+ 'protocol': 'xmpp:',
+ 'host': 'isaacschlueter@jabber.org',
+ 'auth': 'isaacschlueter',
+ 'hostname': 'jabber.org'
}
};
for (var u in parseTests) {
var actual = url.parse(u),
- expected = parseTests[u];
+ expected = parseTests[u];
for (var i in expected) {
var e = JSON.stringify(expected[i]),
- a = JSON.stringify(actual[i]);
- assert.equal(e, a, "parse(" + u + ")."+i+" == "+e+"\nactual: "+a);
+ a = JSON.stringify(actual[i]);
+ assert.equal(e, a,
+ 'parse(' + u + ').' + i + ' == ' + e + '\nactual: ' + a);
}
var expected = u,
- actual = url.format(parseTests[u]);
+ actual = url.format(parseTests[u]);
- assert.equal(expected, actual, "format("+u+") == "+u+"\nactual:"+actual);
+ assert.equal(expected, actual,
+ 'format(' + u + ') == ' + u + '\nactual:' + actual);
}
var parseTestsWithQueryString = {
- "/foo/bar?baz=quux#frag" : {
- "href": "/foo/bar?baz=quux#frag",
- "hash": "#frag",
- "search": "?baz=quux",
- "query": {
- "baz": "quux"
- },
- "pathname": "/foo/bar"
- },
+ '/foo/bar?baz=quux#frag' : {
+ 'href': '/foo/bar?baz=quux#frag',
+ 'hash': '#frag',
+ 'search': '?baz=quux',
+ 'query': {
+ 'baz': 'quux'
+ },
+ 'pathname': '/foo/bar'
+ }
};
for (var u in parseTestsWithQueryString) {
- var actual = url.parse(u,true);
+ var actual = url.parse(u, true);
var expected = parseTestsWithQueryString[u];
for (var i in expected) {
var e = JSON.stringify(expected[i]),
- a = JSON.stringify(actual[i]);
- assert.equal(e, a, "parse(" + u + ")."+i+" == "+e+"\nactual: "+a);
+ a = JSON.stringify(actual[i]);
+ assert.equal(e, a,
+ 'parse(' + u + ').' + i + ' == ' + e + '\nactual: ' + a);
}
}
-// some extra formatting tests, just to verify that it'll format slightly wonky content to a valid url.
+// some extra formatting tests, just to verify
+// that it'll format slightly wonky content to a valid url.
var formatTests = {
- "http://a.com/a/b/c?s#h" : {
- "protocol": "http",
- "host": "a.com",
- "pathname": "a/b/c",
- "hash": "h",
- "search": "s"
+ 'http://a.com/a/b/c?s#h' : {
+ 'protocol': 'http',
+ 'host': 'a.com',
+ 'pathname': 'a/b/c',
+ 'hash': 'h',
+ 'search': 's'
},
- "xmpp:isaacschlueter@jabber.org" : {
- "href": "xmpp://isaacschlueter@jabber.org",
- "protocol": "xmpp:",
- "host": "isaacschlueter@jabber.org",
- "auth": "isaacschlueter",
- "hostname": "jabber.org"
+ 'xmpp:isaacschlueter@jabber.org' : {
+ 'href': 'xmpp://isaacschlueter@jabber.org',
+ 'protocol': 'xmpp:',
+ 'host': 'isaacschlueter@jabber.org',
+ 'auth': 'isaacschlueter',
+ 'hostname': 'jabber.org'
}
};
for (var u in formatTests) {
var actual = url.format(formatTests[u]);
- assert.equal(actual, u, "wonky format("+u+") == "+u+"\nactual:"+actual);
+ assert.equal(actual, u,
+ 'wonky format(' + u + ') == ' + u + '\nactual:' + actual);
}
-[
- // [from, path, expected]
- ["/foo/bar/baz", "quux", "/foo/bar/quux"],
- ["/foo/bar/baz", "quux/asdf", "/foo/bar/quux/asdf"],
- ["/foo/bar/baz", "quux/baz", "/foo/bar/quux/baz"],
- ["/foo/bar/baz", "../quux/baz", "/foo/quux/baz"],
- ["/foo/bar/baz", "/bar", "/bar"],
- ["/foo/bar/baz/", "quux", "/foo/bar/baz/quux"],
- ["/foo/bar/baz/", "quux/baz", "/foo/bar/baz/quux/baz"],
- ["/foo/bar/baz", "../../../../../../../../quux/baz", "/quux/baz"],
- ["/foo/bar/baz", "../../../../../../../quux/baz", "/quux/baz"],
- ["foo/bar", "../../../baz", "../../baz"],
- ["foo/bar/", "../../../baz", "../baz"],
- ["http://example.com/b//c//d;p?q#blarg","https:#hash2","https:///#hash2" ],
- ["http://example.com/b//c//d;p?q#blarg","https:/p/a/t/h?s#hash2","https://p/a/t/h?s#hash2" ],
- ["http://example.com/b//c//d;p?q#blarg","https://u:p@h.com/p/a/t/h?s#hash2","https://u:p@h.com/p/a/t/h?s#hash2"],
- ["http://example.com/b//c//d;p?q#blarg","https:/a/b/c/d","https://a/b/c/d"],
- ["http://example.com/b//c//d;p?q#blarg","http:#hash2","http://example.com/b//c//d;p?q#hash2" ],
- ["http://example.com/b//c//d;p?q#blarg","http:/p/a/t/h?s#hash2","http://example.com/p/a/t/h?s#hash2" ],
- ["http://example.com/b//c//d;p?q#blarg","http://u:p@h.com/p/a/t/h?s#hash2","http://u:p@h.com/p/a/t/h?s#hash2" ],
- ["http://example.com/b//c//d;p?q#blarg","http:/a/b/c/d","http://example.com/a/b/c/d"],
- ["/foo/bar/baz", "/../etc/passwd", "/etc/passwd"]
-].forEach(function (relativeTest) {
+/*
+ [from, path, expected]
+*/
+var relativeTests = [
+ ['/foo/bar/baz', 'quux', '/foo/bar/quux'],
+ ['/foo/bar/baz', 'quux/asdf', '/foo/bar/quux/asdf'],
+ ['/foo/bar/baz', 'quux/baz', '/foo/bar/quux/baz'],
+ ['/foo/bar/baz', '../quux/baz', '/foo/quux/baz'],
+ ['/foo/bar/baz', '/bar', '/bar'],
+ ['/foo/bar/baz/', 'quux', '/foo/bar/baz/quux'],
+ ['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
+ ['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],
+ ['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],
+ ['foo/bar', '../../../baz', '../../baz'],
+ ['foo/bar/', '../../../baz', '../baz'],
+ ['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],
+ ['http://example.com/b//c//d;p?q#blarg',
+ 'https:/p/a/t/h?s#hash2',
+ 'https://p/a/t/h?s#hash2'],
+ ['http://example.com/b//c//d;p?q#blarg',
+ 'https://u:p@h.com/p/a/t/h?s#hash2',
+ 'https://u:p@h.com/p/a/t/h?s#hash2'],
+ ['http://example.com/b//c//d;p?q#blarg',
+ 'https:/a/b/c/d',
+ 'https://a/b/c/d'],
+ ['http://example.com/b//c//d;p?q#blarg',
+ 'http:#hash2',
+ 'http://example.com/b//c//d;p?q#hash2'],
+ ['http://example.com/b//c//d;p?q#blarg',
+ 'http:/p/a/t/h?s#hash2',
+ 'http://example.com/p/a/t/h?s#hash2'],
+ ['http://example.com/b//c//d;p?q#blarg',
+ 'http://u:p@h.com/p/a/t/h?s#hash2',
+ 'http://u:p@h.com/p/a/t/h?s#hash2'],
+ ['http://example.com/b//c//d;p?q#blarg',
+ 'http:/a/b/c/d',
+ 'http://example.com/a/b/c/d'],
+ ['/foo/bar/baz', '/../etc/passwd', '/etc/passwd']
+];
+relativeTests.forEach(function(relativeTest) {
var a = url.resolve(relativeTest[0], relativeTest[1]),
- e = relativeTest[2];
+ e = relativeTest[2];
assert.equal(e, a,
- "resolve("+[relativeTest[0], relativeTest[1]]+") == "+e+
- "\n actual="+a);
+ 'resolve(' + [relativeTest[0], relativeTest[1]] + ') == ' + e +
+ '\n actual=' + a);
});
@@ -273,50 +295,51 @@ var bases = [
];
//[to, from, result]
-[
+var relativeTests2 = [
// http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html
- ['../c', 'foo:a/b', 'foo:c'],
- ['foo:.', 'foo:a', 'foo:'],
+ ['../c', 'foo:a/b', 'foo:c'],
+ ['foo:.', 'foo:a', 'foo:'],
['/foo/../../../bar', 'zz:abc', 'zz:/bar'],
- ['/foo/../bar', 'zz:abc', 'zz:/bar'],
- ['foo/../../../bar', 'zz:abc', 'zz:bar'], // @isaacs Disagree. Not how web browsers resolve this.
+ ['/foo/../bar', 'zz:abc', 'zz:/bar'],
+ // @isaacs Disagree. Not how web browsers resolve this.
+ ['foo/../../../bar', 'zz:abc', 'zz:bar'],
// ['foo/../../../bar', 'zz:abc', 'zz:../../bar'], // @isaacs Added
- ['foo/../bar', 'zz:abc', 'zz:bar'],
- ['zz:.', 'zz:abc', 'zz:'],
- ['/.' , bases[0], 'http://a/'],
- ['/.foo' , bases[0], 'http://a/.foo'],
- ['.foo' , bases[0], 'http://a/b/c/.foo'],
+ ['foo/../bar', 'zz:abc', 'zz:bar'],
+ ['zz:.', 'zz:abc', 'zz:'],
+ ['/.', bases[0], 'http://a/'],
+ ['/.foo', bases[0], 'http://a/.foo'],
+ ['.foo', bases[0], 'http://a/b/c/.foo'],
// http://gbiv.com/protocols/uri/test/rel_examples1.html
// examples from RFC 2396
- ['g:h' , bases[0], 'g:h'],
- ['g' , bases[0], 'http://a/b/c/g'],
- ['./g' , bases[0], 'http://a/b/c/g'],
- ['g/' , bases[0], 'http://a/b/c/g/'],
- ['/g' , bases[0], 'http://a/g'],
- ['//g' , bases[0], 'http://g'],
+ ['g:h', bases[0], 'g:h'],
+ ['g', bases[0], 'http://a/b/c/g'],
+ ['./g', bases[0], 'http://a/b/c/g'],
+ ['g/', bases[0], 'http://a/b/c/g/'],
+ ['/g', bases[0], 'http://a/g'],
+ ['//g', bases[0], 'http://g'],
// changed with RFC 2396bis
- //('?y' , bases[0], 'http://a/b/c/d;p?y'],
- ['?y' , bases[0], 'http://a/b/c/d;p?y'],
- ['g?y' , bases[0], 'http://a/b/c/g?y'],
+ //('?y', bases[0], 'http://a/b/c/d;p?y'],
+ ['?y', bases[0], 'http://a/b/c/d;p?y'],
+ ['g?y', bases[0], 'http://a/b/c/g?y'],
// changed with RFC 2396bis
- //('#s' , bases[0], CURRENT_DOC_URI + '#s'],
- ['#s' , bases[0], 'http://a/b/c/d;p?q#s'],
- ['g#s' , bases[0], 'http://a/b/c/g#s'],
- ['g?y#s' , bases[0], 'http://a/b/c/g?y#s'],
- [';x' , bases[0], 'http://a/b/c/;x'],
- ['g;x' , bases[0], 'http://a/b/c/g;x'],
+ //('#s', bases[0], CURRENT_DOC_URI + '#s'],
+ ['#s', bases[0], 'http://a/b/c/d;p?q#s'],
+ ['g#s', bases[0], 'http://a/b/c/g#s'],
+ ['g?y#s', bases[0], 'http://a/b/c/g?y#s'],
+ [';x', bases[0], 'http://a/b/c/;x'],
+ ['g;x', bases[0], 'http://a/b/c/g;x'],
['g;x?y#s' , bases[0], 'http://a/b/c/g;x?y#s'],
// changed with RFC 2396bis
- //('' , bases[0], CURRENT_DOC_URI],
- ['' , bases[0], 'http://a/b/c/d;p?q'],
- ['.' , bases[0], 'http://a/b/c/'],
- ['./' , bases[0], 'http://a/b/c/'],
- ['..' , bases[0], 'http://a/b/'],
- ['../' , bases[0], 'http://a/b/'],
- ['../g' , bases[0], 'http://a/b/g'],
- ['../..' , bases[0], 'http://a/'],
- ['../../' , bases[0], 'http://a/'],
+ //('', bases[0], CURRENT_DOC_URI],
+ ['', bases[0], 'http://a/b/c/d;p?q'],
+ ['.', bases[0], 'http://a/b/c/'],
+ ['./', bases[0], 'http://a/b/c/'],
+ ['..', bases[0], 'http://a/b/'],
+ ['../', bases[0], 'http://a/b/'],
+ ['../g', bases[0], 'http://a/b/g'],
+ ['../..', bases[0], 'http://a/'],
+ ['../../', bases[0], 'http://a/'],
['../../g' , bases[0], 'http://a/g'],
['../../../g', bases[0], ('http://a/../g', 'http://a/g')],
['../../../../g', bases[0], ('http://a/../../g', 'http://a/g')],
@@ -347,82 +370,85 @@ var bases = [
// http://gbiv.com/protocols/uri/test/rel_examples2.html
// slashes in base URI's query args
- ['g' , bases[1], 'http://a/b/c/g'],
- ['./g' , bases[1], 'http://a/b/c/g'],
- ['g/' , bases[1], 'http://a/b/c/g/'],
- ['/g' , bases[1], 'http://a/g'],
- ['//g' , bases[1], 'http://g'],
+ ['g', bases[1], 'http://a/b/c/g'],
+ ['./g', bases[1], 'http://a/b/c/g'],
+ ['g/', bases[1], 'http://a/b/c/g/'],
+ ['/g', bases[1], 'http://a/g'],
+ ['//g', bases[1], 'http://g'],
// changed in RFC 2396bis
- //('?y' , bases[1], 'http://a/b/c/?y'],
- ['?y' , bases[1], 'http://a/b/c/d;p?y'],
- ['g?y' , bases[1], 'http://a/b/c/g?y'],
+ //('?y', bases[1], 'http://a/b/c/?y'],
+ ['?y', bases[1], 'http://a/b/c/d;p?y'],
+ ['g?y', bases[1], 'http://a/b/c/g?y'],
['g?y/./x' , bases[1], 'http://a/b/c/g?y/./x'],
['g?y/../x', bases[1], 'http://a/b/c/g?y/../x'],
- ['g#s' , bases[1], 'http://a/b/c/g#s'],
+ ['g#s', bases[1], 'http://a/b/c/g#s'],
['g#s/./x' , bases[1], 'http://a/b/c/g#s/./x'],
['g#s/../x', bases[1], 'http://a/b/c/g#s/../x'],
- ['./' , bases[1], 'http://a/b/c/'],
- ['../' , bases[1], 'http://a/b/'],
- ['../g' , bases[1], 'http://a/b/g'],
- ['../../' , bases[1], 'http://a/'],
+ ['./', bases[1], 'http://a/b/c/'],
+ ['../', bases[1], 'http://a/b/'],
+ ['../g', bases[1], 'http://a/b/g'],
+ ['../../', bases[1], 'http://a/'],
['../../g' , bases[1], 'http://a/g'],
// http://gbiv.com/protocols/uri/test/rel_examples3.html
// slashes in path params
// all of these changed in RFC 2396bis
- ['g' , bases[2], 'http://a/b/c/d;p=1/g'],
- ['./g' , bases[2], 'http://a/b/c/d;p=1/g'],
- ['g/' , bases[2], 'http://a/b/c/d;p=1/g/'],
- ['g?y' , bases[2], 'http://a/b/c/d;p=1/g?y'],
- [';x' , bases[2], 'http://a/b/c/d;p=1/;x'],
- ['g;x' , bases[2], 'http://a/b/c/d;p=1/g;x'],
+ ['g', bases[2], 'http://a/b/c/d;p=1/g'],
+ ['./g', bases[2], 'http://a/b/c/d;p=1/g'],
+ ['g/', bases[2], 'http://a/b/c/d;p=1/g/'],
+ ['g?y', bases[2], 'http://a/b/c/d;p=1/g?y'],
+ [';x', bases[2], 'http://a/b/c/d;p=1/;x'],
+ ['g;x', bases[2], 'http://a/b/c/d;p=1/g;x'],
['g;x=1/./y', bases[2], 'http://a/b/c/d;p=1/g;x=1/y'],
['g;x=1/../y', bases[2], 'http://a/b/c/d;p=1/y'],
- ['./' , bases[2], 'http://a/b/c/d;p=1/'],
- ['../' , bases[2], 'http://a/b/c/'],
- ['../g' , bases[2], 'http://a/b/c/g'],
- ['../../' , bases[2], 'http://a/b/'],
+ ['./', bases[2], 'http://a/b/c/d;p=1/'],
+ ['../', bases[2], 'http://a/b/c/'],
+ ['../g', bases[2], 'http://a/b/c/g'],
+ ['../../', bases[2], 'http://a/b/'],
['../../g' , bases[2], 'http://a/b/g'],
// http://gbiv.com/protocols/uri/test/rel_examples4.html
// double and triple slash, unknown scheme
- ['g:h' , bases[3], 'g:h'],
- ['g' , bases[3], 'fred:///s//a/b/g'],
- ['./g' , bases[3], 'fred:///s//a/b/g'],
- ['g/' , bases[3], 'fred:///s//a/b/g/'],
- ['/g' , bases[3], 'fred:///g'], // may change to fred:///s//a/g
- ['//g' , bases[3], 'fred://g'], // may change to fred:///s//g
- ['//g/x' , bases[3], 'fred://g/x'], // may change to fred:///s//g/x
- ['///g' , bases[3], 'fred:///g'],
- ['./' , bases[3], 'fred:///s//a/b/'],
- ['../' , bases[3], 'fred:///s//a/'],
- ['../g' , bases[3], 'fred:///s//a/g'],
+ ['g:h', bases[3], 'g:h'],
+ ['g', bases[3], 'fred:///s//a/b/g'],
+ ['./g', bases[3], 'fred:///s//a/b/g'],
+ ['g/', bases[3], 'fred:///s//a/b/g/'],
+ ['/g', bases[3], 'fred:///g'], // may change to fred:///s//a/g
+ ['//g', bases[3], 'fred://g'], // may change to fred:///s//g
+ ['//g/x', bases[3], 'fred://g/x'], // may change to fred:///s//g/x
+ ['///g', bases[3], 'fred:///g'],
+ ['./', bases[3], 'fred:///s//a/b/'],
+ ['../', bases[3], 'fred:///s//a/'],
+ ['../g', bases[3], 'fred:///s//a/g'],
- ['../../' , bases[3], 'fred:///s//'],
+ ['../../', bases[3], 'fred:///s//'],
['../../g' , bases[3], 'fred:///s//g'],
['../../../g', bases[3], 'fred:///s/g'],
- ['../../../../g', bases[3], 'fred:///g'], // may change to fred:///s//a/../../../g
+ // may change to fred:///s//a/../../../g
+ ['../../../../g', bases[3], 'fred:///g'],
// http://gbiv.com/protocols/uri/test/rel_examples5.html
// double and triple slash, well-known scheme
- ['g:h' , bases[4], 'g:h'],
- ['g' , bases[4], 'http:///s//a/b/g'],
- ['./g' , bases[4], 'http:///s//a/b/g'],
- ['g/' , bases[4], 'http:///s//a/b/g/'],
- ['/g' , bases[4], 'http:///g'], // may change to http:///s//a/g
- ['//g' , bases[4], 'http://g'], // may change to http:///s//g
- ['//g/x' , bases[4], 'http://g/x'], // may change to http:///s//g/x
- ['///g' , bases[4], 'http:///g'],
- ['./' , bases[4], 'http:///s//a/b/'],
- ['../' , bases[4], 'http:///s//a/'],
- ['../g' , bases[4], 'http:///s//a/g'],
- ['../../' , bases[4], 'http:///s//'],
+ ['g:h', bases[4], 'g:h'],
+ ['g', bases[4], 'http:///s//a/b/g'],
+ ['./g', bases[4], 'http:///s//a/b/g'],
+ ['g/', bases[4], 'http:///s//a/b/g/'],
+ ['/g', bases[4], 'http:///g'], // may change to http:///s//a/g
+ ['//g', bases[4], 'http://g'], // may change to http:///s//g
+ ['//g/x', bases[4], 'http://g/x'], // may change to http:///s//g/x
+ ['///g', bases[4], 'http:///g'],
+ ['./', bases[4], 'http:///s//a/b/'],
+ ['../', bases[4], 'http:///s//a/'],
+ ['../g', bases[4], 'http:///s//a/g'],
+ ['../../', bases[4], 'http:///s//'],
['../../g' , bases[4], 'http:///s//g'],
- ['../../../g', bases[4], 'http:///s/g'], // may change to http:///s//a/../../g
- ['../../../../g', bases[4], 'http:///g'], // may change to http:///s//a/../../../g
+ // may change to http:///s//a/../../g
+ ['../../../g', bases[4], 'http:///s/g'],
+ // may change to http:///s//a/../../../g
+ ['../../../../g', bases[4], 'http:///g'],
// from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py
- ["bar:abc", "foo:xyz", "bar:abc"],
+ ['bar:abc', 'foo:xyz', 'bar:abc'],
['../abc', 'http://example/x/y/z', 'http://example/x/abc'],
['http://example/x/abc', 'http://example2/x/y/z', 'http://example/x/abc'],
['../r', 'http://ex/x/y/z', 'http://ex/x/r'],
@@ -434,7 +460,9 @@ var bases = [
['', 'http://ex/x/y/', 'http://ex/x/y/'],
['', 'http://ex/x/y/pdq', 'http://ex/x/y/pdq'],
['z/', 'http://ex/x/y/', 'http://ex/x/y/z/'],
- ['#Animal', 'file:/swap/test/animal.rdf', 'file:/swap/test/animal.rdf#Animal'],
+ ['#Animal',
+ 'file:/swap/test/animal.rdf',
+ 'file:/swap/test/animal.rdf#Animal'],
['../abc', 'file:/e/x/y/z', 'file:/e/x/abc'],
['/example/x/abc', 'file:/example2/x/y/z', 'file:/example/x/abc'],
['../r', 'file:/ex/x/y/z', 'file:/ex/x/r'],
@@ -448,12 +476,16 @@ var bases = [
['', 'file:/ex/x/y/', 'file:/ex/x/y/'],
['', 'file:/ex/x/y/pdq', 'file:/ex/x/y/pdq'],
['z/', 'file:/ex/x/y/', 'file:/ex/x/y/z/'],
- ['file://meetings.example.com/cal#m1', 'file:/devel/WWW/2000/10/swap/test/reluri-1.n3', 'file://meetings.example.com/cal#m1'],
- ['file://meetings.example.com/cal#m1', 'file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3', 'file://meetings.example.com/cal#m1'],
+ ['file://meetings.example.com/cal#m1',
+ 'file:/devel/WWW/2000/10/swap/test/reluri-1.n3',
+ 'file://meetings.example.com/cal#m1'],
+ ['file://meetings.example.com/cal#m1',
+ 'file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3',
+ 'file://meetings.example.com/cal#m1'],
['./#blort', 'file:/some/dir/foo', 'file:/some/dir/#blort'],
['./#', 'file:/some/dir/foo', 'file:/some/dir/#'],
// Ryan Lee
- ["./", "http://example/x/abc.efg", "http://example/x/"],
+ ['./', 'http://example/x/abc.efg', 'http://example/x/'],
// Graham Klyne's tests
@@ -465,11 +497,15 @@ var bases = [
['./p=q:r', 'http://ex/x/y', 'http://ex/x/p=q:r'],
['?pp/rr', 'http://ex/x/y?pp/qq', 'http://ex/x/y?pp/rr'],
['y/z', 'http://ex/x/y?pp/qq', 'http://ex/x/y/z'],
- ['local/qual@domain.org#frag', 'mailto:local', 'mailto:local/qual@domain.org#frag'],
- ['more/qual2@domain2.org#frag', 'mailto:local/qual1@domain1.org', 'mailto:local/more/qual2@domain2.org#frag'],
+ ['local/qual@domain.org#frag',
+ 'mailto:local',
+ 'mailto:local/qual@domain.org#frag'],
+ ['more/qual2@domain2.org#frag',
+ 'mailto:local/qual1@domain1.org',
+ 'mailto:local/more/qual2@domain2.org#frag'],
['y?q', 'http://ex/x/y?q', 'http://ex/x/y?q'],
['/x/y?q', 'http://ex?p', 'http://ex/x/y?q'],
- ['c/d', 'foo:a/b', 'foo:a/c/d'],
+ ['c/d', 'foo:a/b', 'foo:a/c/d'],
['/c/d', 'foo:a/b', 'foo:/c/d'],
['', 'foo:a/b?c#d', 'foo:a/b?c'],
['b/c', 'foo:a', 'foo:b/c'],
@@ -494,8 +530,12 @@ var bases = [
// 70-77
['local2@domain2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2'],
- ['local2@domain2?query2', 'mailto:local1@domain1', 'mailto:local2@domain2?query2'],
- ['local2@domain2?query2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2?query2'],
+ ['local2@domain2?query2',
+ 'mailto:local1@domain1',
+ 'mailto:local2@domain2?query2'],
+ ['local2@domain2?query2',
+ 'mailto:local1@domain1?query1',
+ 'mailto:local2@domain2?query2'],
['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'],
['local@domain?query2', 'mailto:?query1', 'mailto:local@domain?query2'],
['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'],
@@ -503,19 +543,26 @@ var bases = [
['http://example/a/b#c/../d', 'foo:bar', 'http://example/a/b#c/../d'],
// 82-88
- // ['http:this', 'http://example.org/base/uri', 'http:this'], // @isaacs Disagree. Not how browsers do it.
- ['http:this', 'http://example.org/base/uri', "http://example.org/base/this"], // @isaacs Added
+ // @isaacs Disagree. Not how browsers do it.
+ // ['http:this', 'http://example.org/base/uri', 'http:this'],
+ // @isaacs Added
+ ['http:this', 'http://example.org/base/uri', 'http://example.org/base/this'],
['http:this', 'http:base', 'http:this'],
['.//g', 'f:/a', 'f://g'],
['b/c//d/e', 'f://example.org/base/a', 'f://example.org/base/b/c//d/e'],
- ['m2@example.ord/c2@example.org', 'mid:m@example.ord/c@example.org', 'mid:m@example.ord/m2@example.ord/c2@example.org'],
- ['mini1.xml', 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/', 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'],
+ ['m2@example.ord/c2@example.org',
+ 'mid:m@example.ord/c@example.org',
+ 'mid:m@example.ord/m2@example.ord/c2@example.org'],
+ ['mini1.xml',
+ 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/',
+ 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'],
['../b/c', 'foo:a/y/z', 'foo:a/b/c']
-].forEach(function (relativeTest) {
+];
+relativeTests2.forEach(function(relativeTest) {
var a = url.resolve(relativeTest[1], relativeTest[0]),
- e = relativeTest[2];
+ e = relativeTest[2];
assert.equal(e, a,
- "resolve("+[relativeTest[1], relativeTest[0]]+") == "+e+
- "\n actual="+a);
+ 'resolve(' + [relativeTest[1], relativeTest[0]] + ') == ' + e +
+ '\n actual=' + a);
});