Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit a6382b7

Browse files
committed
Add more tests for special chars
1 parent ced93d6 commit a6382b7

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

src/test/fs.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ describe('fs.ts', () => {
2222
temp.mkdir('local-fs', (err: Error, dirPath: string) => err ? reject(err) : resolve(dirPath));
2323
});
2424
baseUri = path2uri(new URL('file:///'), temporaryDir + path.sep);
25-
await fs.mkdir(path.join(temporaryDir, 'f💩o'));
25+
await fs.mkdir(path.join(temporaryDir, 'foo'));
2626
await fs.mkdir(path.join(temporaryDir, '@types'));
2727
await fs.mkdir(path.join(temporaryDir, '@types', 'diff'));
28+
await fs.writeFile(path.join(temporaryDir, '💩'), 'hi');
2829
await fs.writeFile(path.join(temporaryDir, 'tweedledee'), 'hi');
2930
await fs.writeFile(path.join(temporaryDir, 'tweedledum'), 'bye');
30-
await fs.writeFile(path.join(temporaryDir, 'f💩o', 'bar.ts'), 'baz');
31+
await fs.writeFile(path.join(temporaryDir, 'foo', 'bar.ts'), 'baz');
3132
await fs.writeFile(path.join(temporaryDir, '@types', 'diff', 'index.d.ts'), 'baz');
3233
fileSystem = new LocalFileSystem(baseUri);
3334
});
@@ -43,19 +44,20 @@ describe('fs.ts', () => {
4344
assert.sameMembers(files, [
4445
baseUri + 'tweedledee',
4546
baseUri + 'tweedledum',
46-
baseUri + 'f%F0%9F%92%A9o/bar.ts',
47-
baseUri + '@types/diff/index.d.ts'
47+
baseUri + '%F0%9F%92%A9',
48+
baseUri + 'foo/bar.ts',
49+
baseUri + '%40types/diff/index.d.ts'
4850
]);
4951
});
5052
it('should return all files under specific root', async () => {
51-
const files = iterate(await fileSystem.getWorkspaceFiles(new URL('f%F0%9F%92%A9o', baseUri.href))).map(uri => uri.href).toArray();
53+
const files = iterate(await fileSystem.getWorkspaceFiles(new URL('foo', baseUri.href))).map(uri => uri.href).toArray();
5254
assert.sameMembers(files, [
53-
baseUri + 'f%F0%9F%92%A9o/bar.ts'
55+
baseUri + 'foo/bar.ts'
5456
]);
5557
});
5658
});
5759
describe('getTextDocumentContent()', () => {
58-
it('should read files denoted by absolute URI', async () => {
60+
it('should return the content of a file by URI', async () => {
5961
assert.equal(await fileSystem.getTextDocumentContent(new URL('tweedledee', baseUri.href)), 'hi');
6062
});
6163
});

src/test/util-test.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,42 @@ import { path2uri, symbolDescriptorMatch, uri2path } from '../util';
55
describe('util', () => {
66
describe('path2uri()', () => {
77
it('should convert a Unix file path to a URI', () => {
8-
const uri = path2uri(new URL('file://host/foo/bar'), '/baz/@qux');
9-
assert.equal(uri.href, 'file://host/baz/%40qux');
8+
const uri = path2uri(new URL('file:///foo/bar'), '/baz/qux');
9+
assert.equal(uri.href, 'file:///baz/qux');
1010
});
1111
it('should convert a Windows file path to a URI', () => {
12-
// Host is dropped because of https://github.com/jsdom/whatwg-url/issues/84
13-
const uri = path2uri(new URL('file:///foo/bar'), 'C:\\baz\\@qux');
14-
assert.equal(uri.href, 'file:///C:/baz/%40qux');
12+
const uri = path2uri(new URL('file:///foo/bar'), 'C:\\baz\\qux');
13+
assert.equal(uri.href, 'file:///C:/baz/qux');
14+
});
15+
it('should encode special characters', () => {
16+
const uri = path2uri(new URL('file:///foo/bar'), '/💩');
17+
assert.equal(uri.href, 'file:///%F0%9F%92%A9');
18+
});
19+
it('should encode unreserved special characters', () => {
20+
const uri = path2uri(new URL('file:///foo/bar'), '/@baz');
21+
assert.equal(uri.href, 'file:///%40baz');
1522
});
1623
});
1724
describe('uri2path()', () => {
1825
it('should convert a Unix file URI to a file path', () => {
19-
const filePath = uri2path(new URL('file:///baz/%40qux'));
20-
assert.equal(filePath, '/baz/@qux');
26+
const filePath = uri2path(new URL('file:///baz/qux'));
27+
assert.equal(filePath, '/baz/qux');
2128
});
2229
it('should convert a Windows file URI to a file path', () => {
23-
const filePath = uri2path(new URL('file:///c:/baz/%40qux'));
24-
assert.equal(filePath, 'c:\\baz\\@qux');
30+
const filePath = uri2path(new URL('file:///c:/baz/qux'));
31+
assert.equal(filePath, 'c:\\baz\\qux');
2532
});
2633
it('should convert a Windows file URI with uppercase drive letter to a file path', () => {
27-
const filePath = uri2path(new URL('file:///C:/baz/%40qux'));
28-
assert.equal(filePath, 'C:\\baz\\@qux');
34+
const filePath = uri2path(new URL('file:///C:/baz/qux'));
35+
assert.equal(filePath, 'C:\\baz\\qux');
36+
});
37+
it('should decode special characters', () => {
38+
const filePath = uri2path(new URL('file:///%F0%9F%92%A9'));
39+
assert.equal(filePath, '/💩');
40+
});
41+
it('should decode unreserved special characters', () => {
42+
const filePath = uri2path(new URL('file:///%40foo'));
43+
assert.equal(filePath, '/@foo');
2944
});
3045
});
3146
describe('symbolDescriptorMatch', () => {

0 commit comments

Comments
 (0)