-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.html
100 lines (82 loc) · 2.76 KB
/
tests.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Test QueryString.js</h1>
<div id="trace"></div>
<script src="QueryString.js"></script>
<script>
function test(a, b) {
if (a === b) {
return 'PASS';
} else {
trace(a.toString() + ' vs. ' + b.toString());
return 'FAIL';
}
}
function trace(str) {
var p = document.createElement('p');
p.innerHTML = str;
document.getElementById('trace').appendChild(p);
}
// #1
trace('#1 ' + test(
QueryString.removeParameter('http://example.com/packaging/55dd787f8dcee5f831625522?&quizmonkey=5', 'quizmonkey'),
'http://example.com/packaging/55dd787f8dcee5f831625522'
).toString());
// #2
trace('#2 ' + test(
QueryString.addParameter('http://example.com/packaging/55dd787f8dcee5f831625522', 'quizmonkey', '2'),
'http://example.com/packaging/55dd787f8dcee5f831625522?quizmonkey=2'
).toString());
// #3
trace('#3 ' + test(
QueryString.getParameter('http://example.com/packaging/55dd787f8dcee5f831625522?quizmonkey=2', 'quizmonkey'),
'2'
).toString());
// #4
trace('#4 ' + test(
QueryString.addParameter('http://example.com/packaging/55dd787f8dcee5f831625522?style=listicle&quizmonkey=1&quizmonkey=3&aaa=bbb&quizmonkey=4', 'quizmonkey', '2'),
'http://example.com/packaging/55dd787f8dcee5f831625522?style=listicle&aaa=bbb&quizmonkey=2'
).toString());
// #5
trace('#5 ' + test(
QueryString.removeParameter('http://example.com/quiz.php?id=11&quizmonkey=2&quizmonkey_var%5B%5D=&quizmonkey_var%5B%5D=&quizmonkey_var%5B%5D=', 'quizmonkey_var[]'),
'http://example.com/quiz.php?id=11&quizmonkey=2'
).toString());
// #6
trace('#6 ' + test(
QueryString.getParameter('http://example.com/quiz.php?id=11&quizmonkey=1&quizmonkey_var[]=1&quizmonkey_var[]=2&quizmonkey_var[]=3', 'quizmonkey_var[]').toString(),
['1', '2', '3'].toString()
).toString());
// #7
trace('#7 ' + test(
QueryString.removeParameter('http://example.com/quiz.php?id=11&quizmonkey_var[]=1&quizmonkey_var[]=2&quizmonkey_var[]=3&quizmonkey=0&quizmonkey_var[]=&quizmonkey_var[]=&quizmonkey_var[]=', 'quizmonkey_var[]'),
'http://example.com/quiz.php?id=11&quizmonkey=0'
).toString());
// #8
trace('#8 ' + test(
QueryString.addQueryString('http://example.com/quiz.php?id=10', ''),
'http://example.com/quiz.php?id=10'
).toString());
// #9
trace('#9 ' + test(
QueryString.removeParameter('http://example.com/editor.html?quizmonkey=2#/docs/55dd787f8dcee5f831625522', 'quizmonkey'),
'http://example.com/editor.html#/docs/55dd787f8dcee5f831625522'
).toString());
// #10
trace('#10 ' + test(
QueryString.getParameter('http://example.com/editor.html', 'whatever'),
undefined
).toString());
// #11
trace('#11 ' + test(
QueryString.getParameter('http://example.com/path?quizmonkey=4&quizmonkey=2', 'quizmonkey'),
'2'
).toString());
</script>
</body>
</html>