1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const chai = require("chai");
|
19 | const uri_1 = require("./uri");
|
20 | const expect = chai.expect;
|
21 | describe('uri', () => {
|
22 | describe('#getAllLocations', () => {
|
23 | it('of /foo/bar/file.txt', () => {
|
24 | expect(new uri_1.default('/foo/bar/file.txt').allLocations.map(x => x.toString()))
|
25 | .deep.equals([
|
26 | new uri_1.default('/foo/bar/file.txt').toString(),
|
27 | new uri_1.default('/foo/bar').toString(),
|
28 | new uri_1.default('/foo').toString(),
|
29 | new uri_1.default('/').toString()
|
30 | ]);
|
31 | });
|
32 | it('of foo', () => {
|
33 | expect(new uri_1.default('foo').allLocations.map(x => x.toString()))
|
34 | .deep.equals([
|
35 | new uri_1.default('foo').toString(),
|
36 | new uri_1.default('/').toString()
|
37 | ]);
|
38 | });
|
39 | it('of foo:bar.txt', () => {
|
40 | expect(new uri_1.default().withScheme('foo').withPath('bar.txt').allLocations.map(x => x.toString()))
|
41 | .deep.equals([
|
42 | 'foo:bar.txt'
|
43 | ]);
|
44 | });
|
45 | it('of foo:bar/foobar.txt', () => {
|
46 | expect(new uri_1.default().withScheme('foo').withPath('bar/foobar.txt').allLocations.map(x => x.toString()))
|
47 | .deep.equals([
|
48 | new uri_1.default().withScheme('foo').withPath('bar/foobar.txt').toString(),
|
49 | new uri_1.default().withScheme('foo').withPath('bar').toString()
|
50 | ]);
|
51 | });
|
52 | });
|
53 | describe('#getParent', () => {
|
54 | it('of file:///foo/bar.txt', () => {
|
55 | expect(new uri_1.default('file:///foo/bar.txt').parent.toString()).equals('file:///foo');
|
56 | });
|
57 | it('of file:///foo/', () => {
|
58 | expect(new uri_1.default('file:///foo/').parent.toString()).equals('file:///foo');
|
59 | });
|
60 | it('of file:///foo', () => {
|
61 | expect(new uri_1.default('file:///foo').parent.toString()).equals('file:///');
|
62 | });
|
63 | it('of file:///', () => {
|
64 | expect(new uri_1.default('file:///').parent.toString()).equals('file:///');
|
65 | });
|
66 | it('of file://', () => {
|
67 | expect(new uri_1.default('file://').parent.toString()).equals('file:///');
|
68 | });
|
69 | });
|
70 | describe('#lastSegment', () => {
|
71 | it('of file:///foo/bar.txt', () => {
|
72 | expect(new uri_1.default('file:///foo/bar.txt').path.base).equals('bar.txt');
|
73 | });
|
74 | it('of file:///foo', () => {
|
75 | expect(new uri_1.default('file:///foo').path.base).equals('foo');
|
76 | });
|
77 | it('of file:///', () => {
|
78 | expect(new uri_1.default('file:///').path.base).equals('');
|
79 | });
|
80 | it('of file://', () => {
|
81 | expect(new uri_1.default('file://').path.base).equals('');
|
82 | });
|
83 | });
|
84 | describe('#appendPath', () => {
|
85 | it("'' to file:///foo", () => {
|
86 | const uri = new uri_1.default('file:///foo');
|
87 | expect(uri.resolve('').toString()).to.be.equal(uri.toString());
|
88 | });
|
89 | it('bar to file:///foo', () => {
|
90 | expect(new uri_1.default('file:///foo').resolve('bar').toString()).to.be.equal('file:///foo/bar');
|
91 | });
|
92 | it('bar/baz to file:///foo', () => {
|
93 | expect(new uri_1.default('file:///foo').resolve('bar/baz').toString()).to.be.equal('file:///foo/bar/baz');
|
94 | });
|
95 | it("'' to file:///", () => {
|
96 | const uri = new uri_1.default('file:///');
|
97 | expect(uri.resolve('').toString()).to.be.equal(uri.toString());
|
98 | });
|
99 | it('bar to file:///', () => {
|
100 | expect(new uri_1.default('file:///').resolve('bar').toString()).to.be.equal('file:///bar');
|
101 | });
|
102 | it('bar/baz to file:///', () => {
|
103 | expect(new uri_1.default('file:///').resolve('bar/baz').toString()).to.be.equal('file:///bar/baz');
|
104 | });
|
105 | });
|
106 | describe('#path', () => {
|
107 | it('Should return with the FS path from the URI.', () => {
|
108 | expect(new uri_1.default('file:///foo/bar/baz.txt').path.toString()).equals('/foo/bar/baz.txt');
|
109 | });
|
110 | it('Should not return the encoded path', () => {
|
111 | expect(new uri_1.default('file:///foo 3/bar 4/baz 4.txt').path.toString()).equals('/foo 3/bar 4/baz 4.txt');
|
112 | });
|
113 | });
|
114 | describe('#withFragment', () => {
|
115 | it('Should replace the fragment.', () => {
|
116 | expect(new uri_1.default('file:///foo/bar/baz.txt#345345').withFragment('foo').toString()).equals('file:///foo/bar/baz.txt#foo');
|
117 | expect(new uri_1.default('file:///foo/bar/baz.txt?foo=2#345345').withFragment('foo').toString(true)).equals('file:///foo/bar/baz.txt?foo=2#foo');
|
118 | });
|
119 | it('Should remove the fragment.', () => {
|
120 | expect(new uri_1.default('file:///foo/bar/baz.txt#345345').withFragment('').toString()).equals('file:///foo/bar/baz.txt');
|
121 | });
|
122 | });
|
123 | describe('#toString()', () => {
|
124 | it('should produce the non encoded string', () => {
|
125 | function check(uri) {
|
126 | expect(new uri_1.default(uri).toString(true)).equals(uri);
|
127 | }
|
128 | check('file:///X?test=32');
|
129 | check('file:///X?test=32#345');
|
130 | check('file:///X test/ddd?test=32#345');
|
131 | });
|
132 | });
|
133 | describe('#Uri.with...()', () => {
|
134 | it('produce proper URIs', () => {
|
135 | const uri = new uri_1.default('').withScheme('file').withPath('/foo/bar.txt').withQuery('x=12').withFragment('baz');
|
136 | expect(uri.toString(true)).equals('file:///foo/bar.txt?x=12#baz');
|
137 | expect(uri.withScheme('http').toString(true)).equals('http:/foo/bar.txt?x=12#baz');
|
138 | expect(uri.withoutQuery().toString(true)).equals('file:///foo/bar.txt#baz');
|
139 | expect(uri.withoutFragment().toString(true)).equals(uri.withFragment('').toString(true));
|
140 | expect(uri.withPath('hubba-bubba').toString(true)).equals('file:///hubba-bubba?x=12#baz');
|
141 | });
|
142 | });
|
143 | describe('#relative()', () => {
|
144 | it('drive letters should be in lowercase', () => {
|
145 | const uri = new uri_1.default('file:///C:/projects/theia');
|
146 | const path = uri.relative(new uri_1.default(uri.resolve('node_modules/typescript/lib').toString()));
|
147 | expect(String(path)).equals('node_modules/typescript/lib');
|
148 | });
|
149 | });
|
150 | describe('#isEqualOrParent()', () => {
|
151 | it('should return `true` for `uris` which are equal', () => {
|
152 | const a = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
153 | const b = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
154 | expect(a.isEqualOrParent(b)).equals(true);
|
155 | });
|
156 | it('should return `false` for `uris` which are not equal', () => {
|
157 | const a = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
158 | const b = new uri_1.default('file:///C:/projects/theia/foo/b.ts');
|
159 | expect(a.isEqualOrParent(b)).equals(false);
|
160 | });
|
161 | it('should return `false` for `uris` which are not the same scheme', () => {
|
162 | const a = new uri_1.default('a:///C:/projects/theia/foo/a.ts');
|
163 | const b = new uri_1.default('b:///C:/projects/theia/foo/a.ts');
|
164 | expect(a.isEqualOrParent(b)).equals(false);
|
165 | });
|
166 | it('should return `true` for `uris` that are not case-sensitive equal, with case-sensitivity `off`', () => {
|
167 | const a = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
168 | const b = new uri_1.default('file:///C:/projects/theia/foo/A.ts');
|
169 | expect(a.isEqualOrParent(b, false)).equals(true);
|
170 | });
|
171 | it('should return `false` for `uris` that are not case-sensitive equal, with case-sensitivity `on`', () => {
|
172 | const a = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
173 | const b = new uri_1.default('file:///C:/projects/theia/foo/A.ts');
|
174 | expect(a.isEqualOrParent(b, true)).equals(false);
|
175 | });
|
176 | it('should return `true` for parent paths', () => {
|
177 | const a = new uri_1.default('file:///C:/projects/');
|
178 | const b = new uri_1.default('file:///C:/projects/theia/foo');
|
179 | expect(a.isEqualOrParent(b)).equals(true);
|
180 | });
|
181 | it('should return `false` for non-parent paths', () => {
|
182 | const a = new uri_1.default('file:///C:/projects/a/');
|
183 | const b = new uri_1.default('file:///C:/projects/theia/foo');
|
184 | expect(a.isEqualOrParent(b)).equals(false);
|
185 | });
|
186 | });
|
187 | describe('#isEqual', () => {
|
188 | it('should return `true` for `uris` which are equal', () => {
|
189 | const a = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
190 | const b = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
191 | expect(a.isEqual(b)).equals(true);
|
192 | });
|
193 | it('should return `false` for `uris` which are not equal', () => {
|
194 | const a = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
195 | const b = new uri_1.default('file:///C:/projects/theia/foo/b.ts');
|
196 | expect(a.isEqual(b)).equals(false);
|
197 | });
|
198 | it('should return `true` for `uris` that are not case-sensitive equal, with case-sensitivity `off`', () => {
|
199 | const a = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
200 | const b = new uri_1.default('file:///C:/projects/theia/foo/A.ts');
|
201 | expect(a.isEqual(b, false)).equals(true);
|
202 | });
|
203 | it('should return `false` for `uris` that are not case-sensitive equal, with case-sensitivity `on`', () => {
|
204 | const a = new uri_1.default('file:///C:/projects/theia/foo/a.ts');
|
205 | const b = new uri_1.default('file:///C:/projects/theia/foo/A.ts');
|
206 | expect(a.isEqual(b, true)).equals(false);
|
207 | });
|
208 | it('should return `false` for parent paths', () => {
|
209 | const a = new uri_1.default('file:///C:/projects/');
|
210 | const b = new uri_1.default('file:///C:/projects/theia/foo');
|
211 | expect(a.isEqual(b)).equals(false);
|
212 | });
|
213 | it('should return `false` for different schemes', () => {
|
214 | const a = new uri_1.default('a:///C:/projects/theia/foo/a.ts');
|
215 | const b = new uri_1.default('b:///C:/projects/theia/foo/a.ts');
|
216 | expect(a.isEqual(b)).equals(false);
|
217 | });
|
218 | });
|
219 | describe('#resolveToAbsolute', () => {
|
220 | function checkResolution(original, segments, expected) {
|
221 | it(`should resolve ${original.toString()} and ${segments.map(segment => segment.toString()).join(', ')} to ${expected}`, () => {
|
222 | const start = new uri_1.default(original);
|
223 | const result = start.resolveToAbsolute(...segments);
|
224 | expect(result === null || result === void 0 ? void 0 : result.toString()).equals(expected);
|
225 | });
|
226 | }
|
227 | checkResolution('file:///home/hello/', ['some-segment'], 'file:///home/hello/some-segment');
|
228 | checkResolution('file:///home/hello', ['/this/is-already/absolute'], 'file:///this/is-already/absolute');
|
229 | });
|
230 | });
|
231 |
|
\ | No newline at end of file |