Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / escodegen / node_modules / source-map / test / source-map / test-util.js
1 /* -*- Mode: js; js-indent-level: 2; -*- */
2 /*
3  * Copyright 2014 Mozilla Foundation and contributors
4  * Licensed under the New BSD license. See LICENSE or:
5  * http://opensource.org/licenses/BSD-3-Clause
6  */
7 if (typeof define !== 'function') {
8     var define = require('amdefine')(module, require);
9 }
10 define(function (require, exports, module) {
11
12   var libUtil = require('../../lib/source-map/util');
13
14   exports['test urls'] = function (assert, util) {
15     var assertUrl = function (url) {
16       assert.equal(url, libUtil.urlGenerate(libUtil.urlParse(url)));
17     };
18     assertUrl('http://');
19     assertUrl('http://www.example.com');
20     assertUrl('http://user:pass@www.example.com');
21     assertUrl('http://www.example.com:80');
22     assertUrl('http://www.example.com/');
23     assertUrl('http://www.example.com/foo/bar');
24     assertUrl('http://www.example.com/foo/bar/');
25     assertUrl('http://user:pass@www.example.com:80/foo/bar/');
26
27     assertUrl('//');
28     assertUrl('//www.example.com');
29     assertUrl('file:///www.example.com');
30
31     assert.equal(libUtil.urlParse(''), null);
32     assert.equal(libUtil.urlParse('.'), null);
33     assert.equal(libUtil.urlParse('..'), null);
34     assert.equal(libUtil.urlParse('a'), null);
35     assert.equal(libUtil.urlParse('a/b'), null);
36     assert.equal(libUtil.urlParse('a//b'), null);
37     assert.equal(libUtil.urlParse('/a'), null);
38     assert.equal(libUtil.urlParse('data:foo,bar'), null);
39   };
40
41   exports['test normalize()'] = function (assert, util) {
42     assert.equal(libUtil.normalize('/..'), '/');
43     assert.equal(libUtil.normalize('/../'), '/');
44     assert.equal(libUtil.normalize('/../../../..'), '/');
45     assert.equal(libUtil.normalize('/../../../../a/b/c'), '/a/b/c');
46     assert.equal(libUtil.normalize('/a/b/c/../../../d/../../e'), '/e');
47
48     assert.equal(libUtil.normalize('..'), '..');
49     assert.equal(libUtil.normalize('../'), '../');
50     assert.equal(libUtil.normalize('../../a/'), '../../a/');
51     assert.equal(libUtil.normalize('a/..'), '.');
52     assert.equal(libUtil.normalize('a/../../..'), '../..');
53
54     assert.equal(libUtil.normalize('/.'), '/');
55     assert.equal(libUtil.normalize('/./'), '/');
56     assert.equal(libUtil.normalize('/./././.'), '/');
57     assert.equal(libUtil.normalize('/././././a/b/c'), '/a/b/c');
58     assert.equal(libUtil.normalize('/a/b/c/./././d/././e'), '/a/b/c/d/e');
59
60     assert.equal(libUtil.normalize(''), '.');
61     assert.equal(libUtil.normalize('.'), '.');
62     assert.equal(libUtil.normalize('./'), '.');
63     assert.equal(libUtil.normalize('././a'), 'a');
64     assert.equal(libUtil.normalize('a/./'), 'a/');
65     assert.equal(libUtil.normalize('a/././.'), 'a');
66
67     assert.equal(libUtil.normalize('/a/b//c////d/////'), '/a/b/c/d/');
68     assert.equal(libUtil.normalize('///a/b//c////d/////'), '///a/b/c/d/');
69     assert.equal(libUtil.normalize('a/b//c////d'), 'a/b/c/d');
70
71     assert.equal(libUtil.normalize('.///.././../a/b//./..'), '../../a')
72
73     assert.equal(libUtil.normalize('http://www.example.com'), 'http://www.example.com');
74     assert.equal(libUtil.normalize('http://www.example.com/'), 'http://www.example.com/');
75     assert.equal(libUtil.normalize('http://www.example.com/./..//a/b/c/.././d//'), 'http://www.example.com/a/b/d/');
76   };
77
78   exports['test join()'] = function (assert, util) {
79     assert.equal(libUtil.join('a', 'b'), 'a/b');
80     assert.equal(libUtil.join('a/', 'b'), 'a/b');
81     assert.equal(libUtil.join('a//', 'b'), 'a/b');
82     assert.equal(libUtil.join('a', 'b/'), 'a/b/');
83     assert.equal(libUtil.join('a', 'b//'), 'a/b/');
84     assert.equal(libUtil.join('a/', '/b'), '/b');
85     assert.equal(libUtil.join('a//', '//b'), '//b');
86
87     assert.equal(libUtil.join('a', '..'), '.');
88     assert.equal(libUtil.join('a', '../b'), 'b');
89     assert.equal(libUtil.join('a/b', '../c'), 'a/c');
90
91     assert.equal(libUtil.join('a', '.'), 'a');
92     assert.equal(libUtil.join('a', './b'), 'a/b');
93     assert.equal(libUtil.join('a/b', './c'), 'a/b/c');
94
95     assert.equal(libUtil.join('a', 'http://www.example.com'), 'http://www.example.com');
96     assert.equal(libUtil.join('a', 'data:foo,bar'), 'data:foo,bar');
97
98
99     assert.equal(libUtil.join('', 'b'), 'b');
100     assert.equal(libUtil.join('.', 'b'), 'b');
101     assert.equal(libUtil.join('', 'b/'), 'b/');
102     assert.equal(libUtil.join('.', 'b/'), 'b/');
103     assert.equal(libUtil.join('', 'b//'), 'b/');
104     assert.equal(libUtil.join('.', 'b//'), 'b/');
105
106     assert.equal(libUtil.join('', '..'), '..');
107     assert.equal(libUtil.join('.', '..'), '..');
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('', 'http://www.example.com'), 'http://www.example.com');
117     assert.equal(libUtil.join('.', 'http://www.example.com'), 'http://www.example.com');
118     assert.equal(libUtil.join('', 'data:foo,bar'), 'data:foo,bar');
119     assert.equal(libUtil.join('.', 'data:foo,bar'), 'data:foo,bar');
120
121
122     assert.equal(libUtil.join('..', 'b'), '../b');
123     assert.equal(libUtil.join('..', 'b/'), '../b/');
124     assert.equal(libUtil.join('..', 'b//'), '../b/');
125
126     assert.equal(libUtil.join('..', '..'), '../..');
127     assert.equal(libUtil.join('..', '../b'), '../../b');
128
129     assert.equal(libUtil.join('..', '.'), '..');
130     assert.equal(libUtil.join('..', './b'), '../b');
131
132     assert.equal(libUtil.join('..', 'http://www.example.com'), 'http://www.example.com');
133     assert.equal(libUtil.join('..', 'data:foo,bar'), 'data:foo,bar');
134
135
136     assert.equal(libUtil.join('a', ''), 'a');
137     assert.equal(libUtil.join('a', '.'), 'a');
138     assert.equal(libUtil.join('a/', ''), 'a');
139     assert.equal(libUtil.join('a/', '.'), 'a');
140     assert.equal(libUtil.join('a//', ''), 'a');
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('', ''), '.');
145     assert.equal(libUtil.join('.', ''), '.');
146     assert.equal(libUtil.join('.', ''), '.');
147     assert.equal(libUtil.join('.', '.'), '.');
148     assert.equal(libUtil.join('..', ''), '..');
149     assert.equal(libUtil.join('..', '.'), '..');
150     assert.equal(libUtil.join('http://foo.org/a', ''), 'http://foo.org/a');
151     assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a');
152     assert.equal(libUtil.join('http://foo.org/a/', ''), 'http://foo.org/a');
153     assert.equal(libUtil.join('http://foo.org/a/', '.'), 'http://foo.org/a');
154     assert.equal(libUtil.join('http://foo.org/a//', ''), 'http://foo.org/a');
155     assert.equal(libUtil.join('http://foo.org/a//', '.'), 'http://foo.org/a');
156     assert.equal(libUtil.join('http://foo.org', ''), 'http://foo.org/');
157     assert.equal(libUtil.join('http://foo.org', '.'), 'http://foo.org/');
158     assert.equal(libUtil.join('http://foo.org/', ''), 'http://foo.org/');
159     assert.equal(libUtil.join('http://foo.org/', '.'), 'http://foo.org/');
160     assert.equal(libUtil.join('http://foo.org//', ''), 'http://foo.org/');
161     assert.equal(libUtil.join('http://foo.org//', '.'), 'http://foo.org/');
162     assert.equal(libUtil.join('//www.example.com', ''), '//www.example.com/');
163     assert.equal(libUtil.join('//www.example.com', '.'), '//www.example.com/');
164
165
166     assert.equal(libUtil.join('http://foo.org/a', 'b'), 'http://foo.org/a/b');
167     assert.equal(libUtil.join('http://foo.org/a/', 'b'), 'http://foo.org/a/b');
168     assert.equal(libUtil.join('http://foo.org/a//', 'b'), 'http://foo.org/a/b');
169     assert.equal(libUtil.join('http://foo.org/a', 'b/'), 'http://foo.org/a/b/');
170     assert.equal(libUtil.join('http://foo.org/a', 'b//'), 'http://foo.org/a/b/');
171     assert.equal(libUtil.join('http://foo.org/a/', '/b'), 'http://foo.org/b');
172     assert.equal(libUtil.join('http://foo.org/a//', '//b'), 'http://b');
173
174     assert.equal(libUtil.join('http://foo.org/a', '..'), 'http://foo.org/');
175     assert.equal(libUtil.join('http://foo.org/a', '../b'), 'http://foo.org/b');
176     assert.equal(libUtil.join('http://foo.org/a/b', '../c'), 'http://foo.org/a/c');
177
178     assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a');
179     assert.equal(libUtil.join('http://foo.org/a', './b'), 'http://foo.org/a/b');
180     assert.equal(libUtil.join('http://foo.org/a/b', './c'), 'http://foo.org/a/b/c');
181
182     assert.equal(libUtil.join('http://foo.org/a', 'http://www.example.com'), 'http://www.example.com');
183     assert.equal(libUtil.join('http://foo.org/a', 'data:foo,bar'), 'data:foo,bar');
184
185
186     assert.equal(libUtil.join('http://foo.org', 'a'), 'http://foo.org/a');
187     assert.equal(libUtil.join('http://foo.org/', 'a'), 'http://foo.org/a');
188     assert.equal(libUtil.join('http://foo.org//', 'a'), 'http://foo.org/a');
189     assert.equal(libUtil.join('http://foo.org', '/a'), 'http://foo.org/a');
190     assert.equal(libUtil.join('http://foo.org/', '/a'), 'http://foo.org/a');
191     assert.equal(libUtil.join('http://foo.org//', '/a'), 'http://foo.org/a');
192
193
194     assert.equal(libUtil.join('http://', 'www.example.com'), 'http://www.example.com');
195     assert.equal(libUtil.join('file:///', 'www.example.com'), 'file:///www.example.com');
196     assert.equal(libUtil.join('http://', 'ftp://example.com'), 'ftp://example.com');
197
198     assert.equal(libUtil.join('http://www.example.com', '//foo.org/bar'), 'http://foo.org/bar');
199     assert.equal(libUtil.join('//www.example.com', '//foo.org/bar'), '//foo.org/bar');
200   };
201
202   // TODO Issue #128: Define and test this function properly.
203   exports['test relative()'] = function (assert, util) {
204     assert.equal(libUtil.relative('/the/root', '/the/root/one.js'), 'one.js');
205     assert.equal(libUtil.relative('/the/root', '/the/rootone.js'), '/the/rootone.js');
206
207     assert.equal(libUtil.relative('', '/the/root/one.js'), '/the/root/one.js');
208     assert.equal(libUtil.relative('.', '/the/root/one.js'), '/the/root/one.js');
209     assert.equal(libUtil.relative('', 'the/root/one.js'), 'the/root/one.js');
210     assert.equal(libUtil.relative('.', 'the/root/one.js'), 'the/root/one.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   };
215
216 });