forked from annevk/url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urltestrunner.html
59 lines (54 loc) · 1.92 KB
/
urltestrunner.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!doctype html>
<base id=base>
<meta charset=utf-8>
<script src=url.js></script>
<script src=urltestparser.js></script>
<script>
function fetchTests() {
var request = new XMLHttpRequest()
request.open("GET", "urltests.txt")
request.send()
request.responseType = "text"
request.onload = function() { runTests(request.response) }
}
function setBase(base) {
document.getElementById("base").href = base
}
function bURL(url, base) {
base = base || "about:blank"
setBase(base)
var a = document.createElement("a")
a.setAttribute("href", url)
return a
}
function runTests(raw) {
var tests = URLTestParser(raw)
for(var i = 0, l = tests.length; i < l; i++) {
var test = tests[i],
url = new jURL(test.input, new jURL(test.base))
if(url.protocol != test.protocol ||
url.hostname != test.host ||
url.port != test.port ||
url.pathname != test.path ||
url.search != test.search ||
url.hash != test.hash ||
url.href != test.href) {
document.querySelector("pre").appendChild(document.createTextNode("Got: " + url.protocol + "," + url.hostname + "," + url.port + "," + url.pathname + "," + url.search + "," + url.hash + ", expected: " + test.href + ", for input:" + test.input + "\n"))
}
/*
url = bURL(test.input, test.base)
if(url.protocol != test.protocol ||
url.hostname != test.host ||
url.port != test.port ||
url.pathname != test.path ||
url.search != test.search ||
url.hash != test.hash ||
url.href != test.href) {
document.querySelector("pre").appendChild(document.createTextNode("BROWSER Got: " + url.protocol + "," + url.hostname + "," + url.port + "," + url.pathname + "," + url.search + "," + url.hash + ", expected: " + test.href + ", for input:" + test.input + "\n"))
}
*/
}
document.querySelector("pre").appendChild(document.createTextNode("DONE"))
}
window.onload = fetchTests
</script><pre>