UNPKG

3.07 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const os = require("os");
19const path = require("path");
20const chai = require("chai");
21const file_uri_1 = require("./file-uri");
22const os_1 = require("../common/os");
23const expect = chai.expect;
24describe('file-uri', () => {
25 const filePaths = ['with.txt', 'with spaces.txt', 'with:colon.txt', 'with_Ö.txt'].map(filePath => path.join(os.tmpdir(), 'file-uri-folder', filePath));
26 it('create -> fsPath -> create should be symmetric', () => {
27 const orderedPaths = filePaths.map(filePath => filePath.toLowerCase()).sort();
28 expect(orderedPaths.map(filePath => file_uri_1.FileUri.create(filePath)).map(uri => file_uri_1.FileUri.fsPath(uri).toLowerCase()).sort()).to.be.deep.equal(orderedPaths);
29 });
30 it('fsPath -> create -> fsPath should be symmetric', () => {
31 filePaths.forEach(filePath => {
32 const expectedUri = file_uri_1.FileUri.create(filePath);
33 const convertedPath = file_uri_1.FileUri.fsPath(expectedUri);
34 const actualUri = file_uri_1.FileUri.create(convertedPath);
35 expect(actualUri.toString()).to.be.equal(expectedUri.toString());
36 });
37 });
38 it('from /', () => {
39 const uri = file_uri_1.FileUri.create('/');
40 expect(uri.toString(true)).to.be.equal('file:///');
41 });
42 it('from //', () => {
43 const uri = file_uri_1.FileUri.create('//');
44 expect(uri.toString(true)).to.be.equal('file:///');
45 });
46 it('from c:', () => {
47 const uri = file_uri_1.FileUri.create('c:');
48 expect(uri.toString(true)).to.be.equal('file:///c:');
49 });
50 it('from /c:', () => {
51 const uri = file_uri_1.FileUri.create('/c:');
52 expect(uri.toString(true)).to.be.equal('file:///c:');
53 });
54 it('from /c:/', () => {
55 const uri = file_uri_1.FileUri.create('/c:/');
56 expect(uri.toString(true)).to.be.equal('file:///c:/');
57 });
58 it('from file:///c%3A', function () {
59 if (!os_1.isWindows) {
60 this.skip();
61 return;
62 }
63 const fsPath = file_uri_1.FileUri.fsPath('file:///c%3A');
64 expect(fsPath).to.be.equal('c:\\');
65 });
66});
67//# sourceMappingURL=file-uri.spec.js.map
\No newline at end of file