-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtestrefimpl.js
38 lines (32 loc) · 1.33 KB
/
testrefimpl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var fs = require("fs");
var punycode = require("../reference-implementation/punycode");
eval(fs.readFileSync("../reference-implementation/idna.js", "utf8"));
eval(fs.readFileSync("../reference-implementation/unorm.js", "utf8"));
eval(fs.readFileSync("../reference-implementation/url.js", "utf8"));
eval(fs.readFileSync("../reference-implementation/urlparser.js", "utf8"));
eval(
fs.readFileSync("../reference-implementation/test/urltestparser.js", "utf8").
replace(/:\ \{\ get:/g, ": { enumerable: true, get:")
);
var data = URLTestParser(fs.
readFileSync("../reference-implementation/test/urltestdata.txt", "utf8"));
properties = ['href', 'protocol', 'hostname', 'port', 'username', 'password',
'pathname', 'search', 'hash', 'exception'];
var constructorResults = [];
for (var i = 0; i < data.length; i++) {
var test = data[i];
var url = new Url(test.input, test.base);
result = {input: test.input, base: test.base};
properties.forEach(function(property) {
if (url[property]) result[property] = url[property].toString()
});
if (url['exception'] && url['exception'].extension) {
result['exception_extension'] = true
}
constructorResults.push(result)
};
var results = {
useragent: "reference-implementation @ " + new Date().toString(),
constructor: constructorResults
}
console.log(JSON.stringify(results, undefined, 2));