Skip to content
Browse files

Switch from using new Array() to using the array literal []

  • Loading branch information...
1 parent 6d66cf6 commit 160f262eba68e2bd12990b8222f65c8cec7fd748 @chilts chilts committed
Showing with 71 additions and 71 deletions.
  1. +53 −53 tests/federation.js
  2. +18 −18 tests/url.js
View
106 tests/federation.js
@@ -5,31 +5,31 @@ var plan = tap.plan;
var libravatar = require('../lib/libravatar');
test("sanitization of invalid SRV responses", function (t) {
- var test1 = libravatar.sanitized_target(new Array(null, null), false);
+ var test1 = libravatar.sanitized_target([null, null], false);
var exp1 = null;
t.equal(test1, exp1, 'both parameters missing');
- var test2 = libravatar.sanitized_target(new Array(null, 80), false);
+ var test2 = libravatar.sanitized_target([null, 80], false);
var exp2 = null;
t.equal(test2, exp2, 'first parameter missing');
- var test3 = libravatar.sanitized_target(new Array('example.com', null), true);
+ var test3 = libravatar.sanitized_target(['example.com', null], true);
var exp3 = null;
t.equal(test3, exp3, 'second parameter missing');
- var test4 = libravatar.sanitized_target(new Array('example.com', 0), false);
+ var test4 = libravatar.sanitized_target(['example.com', 0], false);
var exp4 = null;
t.equal(test4, exp4, 'port too small');
- var test5 = libravatar.sanitized_target(new Array('example.com', 70000), true);
+ var test5 = libravatar.sanitized_target(['example.com', 70000], true);
var exp5 = null;
t.equal(test5, exp5, 'port too big');
- var test6 = libravatar.sanitized_target(new Array('exam$ple.com', 80), false);
+ var test6 = libravatar.sanitized_target(['exam$ple.com', 80], false);
var exp6 = null;
t.equal(test6, exp6, 'invalid hostname');
- var test7 = libravatar.sanitized_target(new Array('example.com', 'abc'), true);
+ var test7 = libravatar.sanitized_target(['example.com', 'abc'], true);
var exp7 = null;
t.equal(test7, exp7, 'invalid port');
@@ -37,19 +37,19 @@ test("sanitization of invalid SRV responses", function (t) {
});
test("sanitization of valid SRV responses", function (t) {
- var test1 = libravatar.sanitized_target(new Array('example.com', 80), false);
+ var test1 = libravatar.sanitized_target(['example.com', 80], false);
var exp1 = 'example.com';
t.equal(test1, exp1, 'normal http');
- var test2 = libravatar.sanitized_target(new Array('example.com', 443), true);
+ var test2 = libravatar.sanitized_target(['example.com', 443], true);
var exp2 = 'example.com';
t.equal(test2, exp2, 'normal https');
- var test3 = libravatar.sanitized_target(new Array('example.org', 8080), false);
+ var test3 = libravatar.sanitized_target(['example.org', 8080], false);
var exp3 = 'example.org:8080';
t.equal(test3, exp3, 'weird http');
- var test4 = libravatar.sanitized_target(new Array('example.org', 44300), true);
+ var test4 = libravatar.sanitized_target(['example.org', 44300], true);
var exp4 = 'example.org:44300';
t.equal(test4, exp4, 'weird https');
@@ -62,32 +62,32 @@ function array_equal(t, result, expected, description) {
}
test("ordering of invalid SRV hostnames", function (t) {
- var test1 = libravatar.srv_hostname(new Array());
- var exp1 = new Array(null, null);
+ var test1 = libravatar.srv_hostname([]);
+ var exp1 = [null, null];
array_equal(t, test1, exp1, 'empty array');
- var test2 = libravatar.srv_hostname(new Array({name: null, port: null}));
- var exp2 = new Array(null, null);
+ var test2 = libravatar.srv_hostname([{name: null, port: null}]);
+ var exp2 = [null, null];
array_equal(t, test2, exp2, 'single empty array');
t.end();
});
test("ordering of valid SRV hostnames on priority", function (t) {
- var test1 = libravatar.srv_hostname(new Array({name: 'example.com', port: 81}));
- var exp1 = new Array('example.com', 81);
+ var test1 = libravatar.srv_hostname([{name: 'example.com', port: 81}]);
+ var exp1 = ['example.com', 81];
array_equal(t, test1, exp1, 'single hostname');
- var test2 = libravatar.srv_hostname(new Array({name: 'a.example.org', port: 81, priority: 0, weight: 0},
- {name: 'b.example.org', port: 82, priority: 10, weight: 0}));
- var exp2 = new Array('a.example.org', 81);
+ var test2 = libravatar.srv_hostname([{name: 'a.example.org', port: 81, priority: 0, weight: 0},
+ {name: 'b.example.org', port: 82, priority: 10, weight: 0}]);
+ var exp2 = ['a.example.org', 81];
array_equal(t, test2, exp2, 'two hostnames');
- var test3 = libravatar.srv_hostname(new Array({name: 'a.example.org', port: 81, priority: 10, weight: 0},
- {name: 'b.example.org', port: 82, priority: 1, weight: 0},
- {name: 'c.example.org', port: 83, priority: 10, weight: 0},
- {name: 'd.example.org', port: 84, priority: 10, weight: 0}));
- var exp3 = new Array('b.example.org', 82);
+ var test3 = libravatar.srv_hostname([{name: 'a.example.org', port: 81, priority: 10, weight: 0},
+ {name: 'b.example.org', port: 82, priority: 1, weight: 0},
+ {name: 'c.example.org', port: 83, priority: 10, weight: 0},
+ {name: 'd.example.org', port: 84, priority: 10, weight: 0}]);
+ var exp3 = ['b.example.org', 82];
array_equal(t, test3, exp3, 'four hostnames');
t.end();
@@ -97,46 +97,46 @@ test("ordering of valid SRV hostnames on weight", function (t) {
var original_random = Math.random;
Math.random = function () { return 0.6; };
- var test1 = libravatar.srv_hostname(new Array({name: 'a.example.org', port: 81, priority: 10, weight: 1},
- {name: 'b.example.org', port: 82, priority: 10, weight: 5},
- {name: 'c.example.org', port: 83, priority: 10, weight: 10},
- {name: 'd.example.org', port: 84, priority: 10, weight: 50},
- {name: 'e.example.org', port: 85, priority: 10, weight: 0}));
- var exp1 = new Array('d.example.org', 84);
+ var test1 = libravatar.srv_hostname([{name: 'a.example.org', port: 81, priority: 10, weight: 1},
+ {name: 'b.example.org', port: 82, priority: 10, weight: 5},
+ {name: 'c.example.org', port: 83, priority: 10, weight: 10},
+ {name: 'd.example.org', port: 84, priority: 10, weight: 50},
+ {name: 'e.example.org', port: 85, priority: 10, weight: 0}]);
+ var exp1 = ['d.example.org', 84];
array_equal(t, test1, exp1, 'random 1');
Math.random = function () { return 0.2; };
- var test2 = libravatar.srv_hostname(new Array({name: 'a.example.org', port: 81, priority: 10, weight: 40},
- {name: 'b.example.org', port: 82, priority: 10, weight: 0},
- {name: 'c.example.org', port: 83, priority: 10, weight: 0},
- {name: 'e.example.org', port: 85, priority: 10, weight: 0}));
- var exp2 = new Array('a.example.org', 81);
+ var test2 = libravatar.srv_hostname([{name: 'a.example.org', port: 81, priority: 10, weight: 40},
+ {name: 'b.example.org', port: 82, priority: 10, weight: 0},
+ {name: 'c.example.org', port: 83, priority: 10, weight: 0},
+ {name: 'e.example.org', port: 85, priority: 10, weight: 0}]);
+ var exp2 = ['a.example.org', 81];
array_equal(t, test2, exp2, 'random 2');
Math.random = function () { return 0.4; };
- var test3 = libravatar.srv_hostname(new Array({name: 'a.example.org', port: 81, priority: 10, weight: 1},
- {name: 'b.example.org', port: 82, priority: 10, weight: 0},
- {name: 'c.example.org', port: 83, priority: 10, weight: 0},
- {name: 'e.example.org', port: 85, priority: 10, weight: 0}));
- var exp3 = new Array('e.example.org', 85);
+ var test3 = libravatar.srv_hostname([{name: 'a.example.org', port: 81, priority: 10, weight: 1},
+ {name: 'b.example.org', port: 82, priority: 10, weight: 0},
+ {name: 'c.example.org', port: 83, priority: 10, weight: 0},
+ {name: 'e.example.org', port: 85, priority: 10, weight: 0}]);
+ var exp3 = ['e.example.org', 85];
array_equal(t, test3, exp3, 'random 3');
Math.random = function () { return 0.3; };
- var test4 = libravatar.srv_hostname(new Array({name: 'a.example.org', port: 81, priority: 10, weight: 0},
- {name: 'b.example.org', port: 82, priority: 10, weight: 0},
- {name: 'c.example.org', port: 83, priority: 10, weight: 10},
- {name: 'e.example.org', port: 85, priority: 10, weight: 0}));
- var exp4 = new Array('c.example.org', 83);
+ var test4 = libravatar.srv_hostname([{name: 'a.example.org', port: 81, priority: 10, weight: 0},
+ {name: 'b.example.org', port: 82, priority: 10, weight: 0},
+ {name: 'c.example.org', port: 83, priority: 10, weight: 10},
+ {name: 'e.example.org', port: 85, priority: 10, weight: 0}]);
+ var exp4 = ['c.example.org', 83];
array_equal(t, test4, exp4, 'random 4');
Math.random = function () { return 0.8; };
- var test5 = libravatar.srv_hostname(new Array({name: 'a.example.org', port: 81, priority: 10, weight: 1},
- {name: 'b.example.org', port: 82, priority: 10, weight: 5},
- {name: 'c.example.org', port: 83, priority: 10, weight: 10},
- {name: 'd.example.org', port: 84, priority: 10, weight: 30},
- {name: 'e.example.org', port: 85, priority: 10, weight: 50},
- {name: 'f.example.org', port: 86, priority: 10, weight: 0}));
- var exp5 = new Array('e.example.org', 85);
+ var test5 = libravatar.srv_hostname([{name: 'a.example.org', port: 81, priority: 10, weight: 1},
+ {name: 'b.example.org', port: 82, priority: 10, weight: 5},
+ {name: 'c.example.org', port: 83, priority: 10, weight: 10},
+ {name: 'd.example.org', port: 84, priority: 10, weight: 30},
+ {name: 'e.example.org', port: 85, priority: 10, weight: 50},
+ {name: 'f.example.org', port: 86, priority: 10, weight: 0}]);
+ var exp5 = ['e.example.org', 85];
array_equal(t, test5, exp5, 'random 5');
Math.random = original_random;
View
36 tests/url.js
@@ -20,19 +20,19 @@ function array_equal(t, result, expected, description) {
test("parsing of user identity", function (t) {
var test1 = libravatar.parse_user_identity(null, null);
- var exp1 = new Array(null, null);
+ var exp1 = [null, null];
array_equal(t, test1, exp1, 'both parameters missing');
var test2 = libravatar.parse_user_identity(COMMON_EMAIL, COMMON_OPENID);
- var exp2 = new Array(COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN);
+ var exp2 = [COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN];
array_equal(t, test2, exp2, 'both parameters supplied');
var test3 = libravatar.parse_user_identity(COMMON_EMAIL, null);
- var exp3 = new Array(COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN);
+ var exp3 = [COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN];
array_equal(t, test3, exp3, 'standard email');
var test4 = libravatar.parse_user_identity(null, COMMON_OPENID);
- var exp4 = new Array(COMMON_OPENID_HASH, COMMON_OPENID_DOMAIN);
+ var exp4 = [COMMON_OPENID_HASH, COMMON_OPENID_DOMAIN];
array_equal(t, test4, exp4, 'standard openid');
t.end();
@@ -40,23 +40,23 @@ test("parsing of user identity", function (t) {
test("parsing of email address", function (t) {
var test1 = libravatar.parse_user_identity('', null);
- var exp1 = new Array(null, null);
+ var exp1 = [null, null];
array_equal(t, test1, exp1, 'empty email');
var test2 = libravatar.parse_user_identity('username', null);
- var exp2 = new Array(null, null);
+ var exp2 = [null, null];
array_equal(t, test2, exp2, 'missing hostname');
var test3 = libravatar.parse_user_identity('WHATEVER@wherever.whichever', null);
- var exp3 = new Array(COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN);
+ var exp3 = [COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN];
array_equal(t, test3, exp3, 'uppercase username');
var test4 = libravatar.parse_user_identity('Whatever@Wherever.whichever', null);
- var exp4 = new Array(COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN);
+ var exp4 = [COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN];
array_equal(t, test4, exp4, 'mixed-case username and hostname');
var test5 = libravatar.parse_user_identity(' Whatever@Wherever.whichever ', null);
- var exp5 = new Array(COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN);
+ var exp5 = [COMMON_EMAIL_HASH, COMMON_EMAIL_DOMAIN];
array_equal(t, test5, exp5, 'untrimmed email');
t.end();
@@ -64,39 +64,39 @@ test("parsing of email address", function (t) {
test("parsing of openid urls", function (t) {
var test1 = libravatar.parse_user_identity(null, '');
- var exp1 = new Array(null, null);
+ var exp1 = [null, null];
array_equal(t, test1, exp1, 'empty openid');
var test2 = libravatar.parse_user_identity(null, 'url');
- var exp2 = new Array(null, null);
+ var exp2 = [null, null];
array_equal(t, test2, exp2, 'invalid url');
var test3 = libravatar.parse_user_identity(null, 'http://example.COM/id');
- var exp3 = new Array(COMMON_OPENID_HASH, COMMON_OPENID_DOMAIN);
+ var exp3 = [COMMON_OPENID_HASH, COMMON_OPENID_DOMAIN];
array_equal(t, test3, exp3, 'mixed-case hostname');
var test4 = libravatar.parse_user_identity(null, ' HTTP://example.com/id ');
- var exp4 = new Array(COMMON_OPENID_HASH, COMMON_OPENID_DOMAIN);
+ var exp4 = [COMMON_OPENID_HASH, COMMON_OPENID_DOMAIN];
array_equal(t, test4, exp4, 'uppercase scheme');
var test5 = libravatar.parse_user_identity(null, 'http://user:password@Example.com/id');
- var exp5 = new Array('e1cf8061371aa00b82c0cf0b9b1140546bc31cd4a15cb8adc84ad01823bdf71e', COMMON_OPENID_DOMAIN);
+ var exp5 = ['e1cf8061371aa00b82c0cf0b9b1140546bc31cd4a15cb8adc84ad01823bdf71e', COMMON_OPENID_DOMAIN];
array_equal(t, test5, exp5, 'lowercase basic auth');
var test6 = libravatar.parse_user_identity(null, 'http://User:Password@Example.com/id');
- var exp6 = new Array('50f60bb4c1b47fffdd6e2ce65f8bf37b65a2fb960596fa6789ef7b0044b931a2', COMMON_OPENID_DOMAIN);
+ var exp6 = ['50f60bb4c1b47fffdd6e2ce65f8bf37b65a2fb960596fa6789ef7b0044b931a2', COMMON_OPENID_DOMAIN];
array_equal(t, test6, exp6, 'mixed-case basic auth');
var test7 = libravatar.parse_user_identity(null, 'http://openid.example.COM/id');
- var exp7 = new Array('a108913053c4949f18d9eef7a4a68f27591297cdd7a7e2e375702aa87b6d3c05', 'openid.example.com');
+ var exp7 = ['a108913053c4949f18d9eef7a4a68f27591297cdd7a7e2e375702aa87b6d3c05', 'openid.example.com'];
array_equal(t, test7, exp7, 'sub-domain');
var test8 = libravatar.parse_user_identity(null, 'https://example.com/id');
- var exp8 = new Array('43e813cfff429662436728ef4fb1cc12bcf20414cab78811137f7d718c1ddedb', COMMON_OPENID_DOMAIN);
+ var exp8 = ['43e813cfff429662436728ef4fb1cc12bcf20414cab78811137f7d718c1ddedb', COMMON_OPENID_DOMAIN];
array_equal(t, test8, exp8, 'https');
var test9 = libravatar.parse_user_identity(null, 'http://example.com/ID');
- var exp9 = new Array('ad8ce775cc12cba9bb8af26e00f55c473a3fcd3f554595a5ad9dd924a546a448', COMMON_OPENID_DOMAIN);
+ var exp9 = ['ad8ce775cc12cba9bb8af26e00f55c473a3fcd3f554595a5ad9dd924a546a448', COMMON_OPENID_DOMAIN];
array_equal(t, test9, exp9, 'uppercase path');
t.end();

0 comments on commit 160f262

Please sign in to comment.
Something went wrong with that request. Please try again.