Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80559 views
1
/*
2
* WARNING!
3
*
4
* Do not edit this file directly, it is built from the sources at
5
* https://github.com/mozilla/source-map/
6
*/
7
8
Components.utils.import('resource://test/Utils.jsm');
9
/* -*- Mode: js; js-indent-level: 2; -*- */
10
/*
11
* Copyright 2014 Mozilla Foundation and contributors
12
* Licensed under the New BSD license. See LICENSE or:
13
* http://opensource.org/licenses/BSD-3-Clause
14
*/
15
define("test/source-map/test-util", ["require", "exports", "module"], function (require, exports, module) {
16
17
var libUtil = require('source-map/util');
18
19
exports['test urls'] = function (assert, util) {
20
var assertUrl = function (url) {
21
assert.equal(url, libUtil.urlGenerate(libUtil.urlParse(url)));
22
};
23
assertUrl('http://');
24
assertUrl('http://www.example.com');
25
assertUrl('http://user:[email protected]');
26
assertUrl('http://www.example.com:80');
27
assertUrl('http://www.example.com/');
28
assertUrl('http://www.example.com/foo/bar');
29
assertUrl('http://www.example.com/foo/bar/');
30
assertUrl('http://user:[email protected]:80/foo/bar/');
31
32
assertUrl('//');
33
assertUrl('//www.example.com');
34
assertUrl('file:///www.example.com');
35
36
assert.equal(libUtil.urlParse(''), null);
37
assert.equal(libUtil.urlParse('.'), null);
38
assert.equal(libUtil.urlParse('..'), null);
39
assert.equal(libUtil.urlParse('a'), null);
40
assert.equal(libUtil.urlParse('a/b'), null);
41
assert.equal(libUtil.urlParse('a//b'), null);
42
assert.equal(libUtil.urlParse('/a'), null);
43
assert.equal(libUtil.urlParse('data:foo,bar'), null);
44
};
45
46
exports['test normalize()'] = function (assert, util) {
47
assert.equal(libUtil.normalize('/..'), '/');
48
assert.equal(libUtil.normalize('/../'), '/');
49
assert.equal(libUtil.normalize('/../../../..'), '/');
50
assert.equal(libUtil.normalize('/../../../../a/b/c'), '/a/b/c');
51
assert.equal(libUtil.normalize('/a/b/c/../../../d/../../e'), '/e');
52
53
assert.equal(libUtil.normalize('..'), '..');
54
assert.equal(libUtil.normalize('../'), '../');
55
assert.equal(libUtil.normalize('../../a/'), '../../a/');
56
assert.equal(libUtil.normalize('a/..'), '.');
57
assert.equal(libUtil.normalize('a/../../..'), '../..');
58
59
assert.equal(libUtil.normalize('/.'), '/');
60
assert.equal(libUtil.normalize('/./'), '/');
61
assert.equal(libUtil.normalize('/./././.'), '/');
62
assert.equal(libUtil.normalize('/././././a/b/c'), '/a/b/c');
63
assert.equal(libUtil.normalize('/a/b/c/./././d/././e'), '/a/b/c/d/e');
64
65
assert.equal(libUtil.normalize(''), '.');
66
assert.equal(libUtil.normalize('.'), '.');
67
assert.equal(libUtil.normalize('./'), '.');
68
assert.equal(libUtil.normalize('././a'), 'a');
69
assert.equal(libUtil.normalize('a/./'), 'a/');
70
assert.equal(libUtil.normalize('a/././.'), 'a');
71
72
assert.equal(libUtil.normalize('/a/b//c////d/////'), '/a/b/c/d/');
73
assert.equal(libUtil.normalize('///a/b//c////d/////'), '///a/b/c/d/');
74
assert.equal(libUtil.normalize('a/b//c////d'), 'a/b/c/d');
75
76
assert.equal(libUtil.normalize('.///.././../a/b//./..'), '../../a')
77
78
assert.equal(libUtil.normalize('http://www.example.com'), 'http://www.example.com');
79
assert.equal(libUtil.normalize('http://www.example.com/'), 'http://www.example.com/');
80
assert.equal(libUtil.normalize('http://www.example.com/./..//a/b/c/.././d//'), 'http://www.example.com/a/b/d/');
81
};
82
83
exports['test join()'] = function (assert, util) {
84
assert.equal(libUtil.join('a', 'b'), 'a/b');
85
assert.equal(libUtil.join('a/', 'b'), 'a/b');
86
assert.equal(libUtil.join('a//', 'b'), 'a/b');
87
assert.equal(libUtil.join('a', 'b/'), 'a/b/');
88
assert.equal(libUtil.join('a', 'b//'), 'a/b/');
89
assert.equal(libUtil.join('a/', '/b'), '/b');
90
assert.equal(libUtil.join('a//', '//b'), '//b');
91
92
assert.equal(libUtil.join('a', '..'), '.');
93
assert.equal(libUtil.join('a', '../b'), 'b');
94
assert.equal(libUtil.join('a/b', '../c'), 'a/c');
95
96
assert.equal(libUtil.join('a', '.'), 'a');
97
assert.equal(libUtil.join('a', './b'), 'a/b');
98
assert.equal(libUtil.join('a/b', './c'), 'a/b/c');
99
100
assert.equal(libUtil.join('a', 'http://www.example.com'), 'http://www.example.com');
101
assert.equal(libUtil.join('a', 'data:foo,bar'), 'data:foo,bar');
102
103
104
assert.equal(libUtil.join('', 'b'), 'b');
105
assert.equal(libUtil.join('.', 'b'), 'b');
106
assert.equal(libUtil.join('', 'b/'), 'b/');
107
assert.equal(libUtil.join('.', 'b/'), 'b/');
108
assert.equal(libUtil.join('', 'b//'), 'b/');
109
assert.equal(libUtil.join('.', 'b//'), 'b/');
110
111
assert.equal(libUtil.join('', '..'), '..');
112
assert.equal(libUtil.join('.', '..'), '..');
113
assert.equal(libUtil.join('', '../b'), '../b');
114
assert.equal(libUtil.join('.', '../b'), '../b');
115
116
assert.equal(libUtil.join('', '.'), '.');
117
assert.equal(libUtil.join('.', '.'), '.');
118
assert.equal(libUtil.join('', './b'), 'b');
119
assert.equal(libUtil.join('.', './b'), 'b');
120
121
assert.equal(libUtil.join('', 'http://www.example.com'), 'http://www.example.com');
122
assert.equal(libUtil.join('.', 'http://www.example.com'), 'http://www.example.com');
123
assert.equal(libUtil.join('', 'data:foo,bar'), 'data:foo,bar');
124
assert.equal(libUtil.join('.', 'data:foo,bar'), 'data:foo,bar');
125
126
127
assert.equal(libUtil.join('..', 'b'), '../b');
128
assert.equal(libUtil.join('..', 'b/'), '../b/');
129
assert.equal(libUtil.join('..', 'b//'), '../b/');
130
131
assert.equal(libUtil.join('..', '..'), '../..');
132
assert.equal(libUtil.join('..', '../b'), '../../b');
133
134
assert.equal(libUtil.join('..', '.'), '..');
135
assert.equal(libUtil.join('..', './b'), '../b');
136
137
assert.equal(libUtil.join('..', 'http://www.example.com'), 'http://www.example.com');
138
assert.equal(libUtil.join('..', 'data:foo,bar'), 'data:foo,bar');
139
140
141
assert.equal(libUtil.join('a', ''), 'a');
142
assert.equal(libUtil.join('a', '.'), 'a');
143
assert.equal(libUtil.join('a/', ''), 'a');
144
assert.equal(libUtil.join('a/', '.'), 'a');
145
assert.equal(libUtil.join('a//', ''), 'a');
146
assert.equal(libUtil.join('a//', '.'), 'a');
147
assert.equal(libUtil.join('/a', ''), '/a');
148
assert.equal(libUtil.join('/a', '.'), '/a');
149
assert.equal(libUtil.join('', ''), '.');
150
assert.equal(libUtil.join('.', ''), '.');
151
assert.equal(libUtil.join('.', ''), '.');
152
assert.equal(libUtil.join('.', '.'), '.');
153
assert.equal(libUtil.join('..', ''), '..');
154
assert.equal(libUtil.join('..', '.'), '..');
155
assert.equal(libUtil.join('http://foo.org/a', ''), 'http://foo.org/a');
156
assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a');
157
assert.equal(libUtil.join('http://foo.org/a/', ''), 'http://foo.org/a');
158
assert.equal(libUtil.join('http://foo.org/a/', '.'), 'http://foo.org/a');
159
assert.equal(libUtil.join('http://foo.org/a//', ''), 'http://foo.org/a');
160
assert.equal(libUtil.join('http://foo.org/a//', '.'), 'http://foo.org/a');
161
assert.equal(libUtil.join('http://foo.org', ''), 'http://foo.org/');
162
assert.equal(libUtil.join('http://foo.org', '.'), 'http://foo.org/');
163
assert.equal(libUtil.join('http://foo.org/', ''), 'http://foo.org/');
164
assert.equal(libUtil.join('http://foo.org/', '.'), 'http://foo.org/');
165
assert.equal(libUtil.join('http://foo.org//', ''), 'http://foo.org/');
166
assert.equal(libUtil.join('http://foo.org//', '.'), 'http://foo.org/');
167
assert.equal(libUtil.join('//www.example.com', ''), '//www.example.com/');
168
assert.equal(libUtil.join('//www.example.com', '.'), '//www.example.com/');
169
170
171
assert.equal(libUtil.join('http://foo.org/a', 'b'), 'http://foo.org/a/b');
172
assert.equal(libUtil.join('http://foo.org/a/', 'b'), 'http://foo.org/a/b');
173
assert.equal(libUtil.join('http://foo.org/a//', 'b'), 'http://foo.org/a/b');
174
assert.equal(libUtil.join('http://foo.org/a', 'b/'), 'http://foo.org/a/b/');
175
assert.equal(libUtil.join('http://foo.org/a', 'b//'), 'http://foo.org/a/b/');
176
assert.equal(libUtil.join('http://foo.org/a/', '/b'), 'http://foo.org/b');
177
assert.equal(libUtil.join('http://foo.org/a//', '//b'), 'http://b');
178
179
assert.equal(libUtil.join('http://foo.org/a', '..'), 'http://foo.org/');
180
assert.equal(libUtil.join('http://foo.org/a', '../b'), 'http://foo.org/b');
181
assert.equal(libUtil.join('http://foo.org/a/b', '../c'), 'http://foo.org/a/c');
182
183
assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a');
184
assert.equal(libUtil.join('http://foo.org/a', './b'), 'http://foo.org/a/b');
185
assert.equal(libUtil.join('http://foo.org/a/b', './c'), 'http://foo.org/a/b/c');
186
187
assert.equal(libUtil.join('http://foo.org/a', 'http://www.example.com'), 'http://www.example.com');
188
assert.equal(libUtil.join('http://foo.org/a', 'data:foo,bar'), 'data:foo,bar');
189
190
191
assert.equal(libUtil.join('http://foo.org', 'a'), 'http://foo.org/a');
192
assert.equal(libUtil.join('http://foo.org/', 'a'), 'http://foo.org/a');
193
assert.equal(libUtil.join('http://foo.org//', 'a'), 'http://foo.org/a');
194
assert.equal(libUtil.join('http://foo.org', '/a'), 'http://foo.org/a');
195
assert.equal(libUtil.join('http://foo.org/', '/a'), 'http://foo.org/a');
196
assert.equal(libUtil.join('http://foo.org//', '/a'), 'http://foo.org/a');
197
198
199
assert.equal(libUtil.join('http://', 'www.example.com'), 'http://www.example.com');
200
assert.equal(libUtil.join('file:///', 'www.example.com'), 'file:///www.example.com');
201
assert.equal(libUtil.join('http://', 'ftp://example.com'), 'ftp://example.com');
202
203
assert.equal(libUtil.join('http://www.example.com', '//foo.org/bar'), 'http://foo.org/bar');
204
assert.equal(libUtil.join('//www.example.com', '//foo.org/bar'), '//foo.org/bar');
205
};
206
207
// TODO Issue #128: Define and test this function properly.
208
exports['test relative()'] = function (assert, util) {
209
assert.equal(libUtil.relative('/the/root', '/the/root/one.js'), 'one.js');
210
assert.equal(libUtil.relative('/the/root', '/the/rootone.js'), '/the/rootone.js');
211
212
assert.equal(libUtil.relative('', '/the/root/one.js'), '/the/root/one.js');
213
assert.equal(libUtil.relative('.', '/the/root/one.js'), '/the/root/one.js');
214
assert.equal(libUtil.relative('', 'the/root/one.js'), 'the/root/one.js');
215
assert.equal(libUtil.relative('.', 'the/root/one.js'), 'the/root/one.js');
216
217
assert.equal(libUtil.relative('/', '/the/root/one.js'), 'the/root/one.js');
218
assert.equal(libUtil.relative('/', 'the/root/one.js'), 'the/root/one.js');
219
};
220
221
});
222
function run_test() {
223
runSourceMapTests('test/source-map/test-util', do_throw);
224
}
225
226