Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 24, 2020
1 parent 4726868 commit 3fe9d3f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/vs/base/test/browser/dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import * as assert from 'assert';
import * as dom from 'vs/base/browser/dom';
import { Schemas } from 'vs/base/common/network';
import { isNative } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
const $ = dom.$;

suite('dom', () => {
Expand Down Expand Up @@ -135,4 +138,16 @@ suite('dom', () => {
assert.equal(firstChild.textContent, 'foobar');
});
});

test('asDomUri', function () {
const fileUri = URI.file('something');

const domUri = dom.asDomUri(fileUri);

if (isNative) {
assert.equal(domUri.scheme, Schemas.vscodeFileResource);
} else {
assert.equal(domUri.scheme, fileUri.scheme);
}
});
});
52 changes: 52 additions & 0 deletions src/vs/base/test/node/network.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { LocalFileAccess, Schemas } from 'vs/base/common/network';
import { isEqual } from 'vs/base/common/resources';

suite('network', () => {

test('LocalFileAccess', () => {

// fromModuleId()
const fromModuleId = LocalFileAccess.fromModuleId('vs/base/test/node/network.test');
assert.equal(fromModuleId.scheme, Schemas.vscodeFileResource);

// rewrite(): throws for non-file URIs
let error: Error | undefined = undefined;
try {
LocalFileAccess.rewrite(URI.parse('some:value'));
} catch (e) {
error = e;
}
assert.ok(error);

// restore(): throws for non-vscode-file URIs
error = undefined;
try {
LocalFileAccess.restore(URI.parse('some:value'), false);
} catch (e) {
error = e;
}
assert.ok(error);

// rewrite() & restore(): simple, without authority
let originalFileUri = URI.file(__filename);
let rewrittenUri = LocalFileAccess.rewrite(originalFileUri);
assert.ok(rewrittenUri.authority.length > 0);
let restoredUri = LocalFileAccess.restore(rewrittenUri, false);
assert.equal(restoredUri.authority.length, 0);
assert(isEqual(originalFileUri, restoredUri));

// rewrite() & restore(): with authority
originalFileUri = URI.file(__filename).with({ authority: 'test-authority' });
rewrittenUri = LocalFileAccess.rewrite(originalFileUri);
assert.equal(rewrittenUri.authority, originalFileUri.authority);
restoredUri = LocalFileAccess.restore(rewrittenUri, false);
assert(isEqual(originalFileUri, restoredUri));
});
});

0 comments on commit 3fe9d3f

Please sign in to comment.