未验证 提交 f48e3d3a 编写于 作者: B Benjamin Pasero 提交者: GitHub

tests - use a common toResource() method (#68959)

上级 a46fd8af
......@@ -6,6 +6,7 @@
import { join } from 'vs/base/common/path';
import { URI } from 'vs/base/common/uri';
import { canceled } from 'vs/base/common/errors';
import { isWindows } from 'vs/base/common/platform';
export type ValueCallback<T = any> = (value: T | Promise<T>) => void;
......@@ -49,7 +50,11 @@ export class DeferredPromise<T> {
}
export function toResource(this: any, path: string) {
return URI.file(join('C:\\', Buffer.from(this.test.fullTitle()).toString('base64'), path));
if (isWindows) {
return URI.file(join('C:\\', Buffer.from(this.test.fullTitle()).toString('base64'), path));
}
return URI.file(join('/', Buffer.from(this.test.fullTitle()).toString('base64'), path));
}
export function suiteRepeat(n: number, description: string, callback: (this: any) => void): void {
......
......@@ -6,36 +6,32 @@
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { isEqual, isEqualOrParent } from 'vs/base/common/extpath';
import { join } from 'vs/base/common/path';
import { FileChangeType, FileChangesEvent, isParent } from 'vs/platform/files/common/files';
import { isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
import { toResource } from 'vs/base/test/common/utils';
suite('Files', () => {
function toResource(path) {
return URI.file(join('C:\\', path));
}
test('FileChangesEvent', () => {
test('FileChangesEvent', function () {
let changes = [
{ resource: toResource('/foo/updated.txt'), type: FileChangeType.UPDATED },
{ resource: toResource('/foo/otherupdated.txt'), type: FileChangeType.UPDATED },
{ resource: toResource('/added.txt'), type: FileChangeType.ADDED },
{ resource: toResource('/bar/deleted.txt'), type: FileChangeType.DELETED },
{ resource: toResource('/bar/folder'), type: FileChangeType.DELETED }
{ resource: toResource.call(this, '/foo/updated.txt'), type: FileChangeType.UPDATED },
{ resource: toResource.call(this, '/foo/otherupdated.txt'), type: FileChangeType.UPDATED },
{ resource: toResource.call(this, '/added.txt'), type: FileChangeType.ADDED },
{ resource: toResource.call(this, '/bar/deleted.txt'), type: FileChangeType.DELETED },
{ resource: toResource.call(this, '/bar/folder'), type: FileChangeType.DELETED }
];
let r1 = new FileChangesEvent(changes);
assert(!r1.contains(toResource('/foo'), FileChangeType.UPDATED));
assert(r1.contains(toResource('/foo/updated.txt'), FileChangeType.UPDATED));
assert(!r1.contains(toResource('/foo/updated.txt'), FileChangeType.ADDED));
assert(!r1.contains(toResource('/foo/updated.txt'), FileChangeType.DELETED));
assert(!r1.contains(toResource.call(this, '/foo'), FileChangeType.UPDATED));
assert(r1.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.UPDATED));
assert(!r1.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.ADDED));
assert(!r1.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.DELETED));
assert(r1.contains(toResource('/bar/folder'), FileChangeType.DELETED));
assert(r1.contains(toResource('/bar/folder/somefile'), FileChangeType.DELETED));
assert(r1.contains(toResource('/bar/folder/somefile/test.txt'), FileChangeType.DELETED));
assert(!r1.contains(toResource('/bar/folder2/somefile'), FileChangeType.DELETED));
assert(r1.contains(toResource.call(this, '/bar/folder'), FileChangeType.DELETED));
assert(r1.contains(toResource.call(this, '/bar/folder/somefile'), FileChangeType.DELETED));
assert(r1.contains(toResource.call(this, '/bar/folder/somefile/test.txt'), FileChangeType.DELETED));
assert(!r1.contains(toResource.call(this, '/bar/folder2/somefile'), FileChangeType.DELETED));
assert.strictEqual(5, r1.changes.length);
assert.strictEqual(1, r1.getAdded().length);
......
......@@ -5,7 +5,7 @@
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { join } from 'vs/base/common/path';
import { toResource } from 'vs/base/test/common/utils';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { workbenchInstantiationService, TestTextFileService } from 'vs/workbench/test/workbenchTestServices';
......@@ -17,10 +17,6 @@ import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textF
import { IModelService } from 'vs/editor/common/services/modelService';
import { timeout } from 'vs/base/common/async';
function toResource(self, path) {
return URI.file(join('C:\\', Buffer.from(self.test.fullTitle()).toString('base64'), path));
}
class ServiceAccessor {
constructor(
@IEditorService public editorService: IEditorService,
......@@ -41,9 +37,9 @@ suite('Files - FileEditorInput', () => {
});
test('Basics', function () {
let input = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/file.js'), undefined);
const otherInput = instantiationService.createInstance(FileEditorInput, toResource(this, 'foo/bar/otherfile.js'), undefined);
const otherInputSame = instantiationService.createInstance(FileEditorInput, toResource(this, 'foo/bar/file.js'), undefined);
let input = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/file.js'), undefined);
const otherInput = instantiationService.createInstance(FileEditorInput, toResource.call(this, 'foo/bar/otherfile.js'), undefined);
const otherInputSame = instantiationService.createInstance(FileEditorInput, toResource.call(this, 'foo/bar/file.js'), undefined);
assert(input.matches(input));
assert(input.matches(otherInputSame));
......@@ -55,13 +51,13 @@ suite('Files - FileEditorInput', () => {
assert.strictEqual('file.js', input.getName());
assert.strictEqual(toResource(this, '/foo/bar/file.js').fsPath, input.getResource().fsPath);
assert.strictEqual(toResource.call(this, '/foo/bar/file.js').fsPath, input.getResource().fsPath);
assert(input.getResource() instanceof URI);
input = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar.html'), undefined);
input = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar.html'), undefined);
const inputToResolve: FileEditorInput = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/file.js'), undefined);
const sameOtherInput: FileEditorInput = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/file.js'), undefined);
const inputToResolve: FileEditorInput = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/file.js'), undefined);
const sameOtherInput: FileEditorInput = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/file.js'), undefined);
return inputToResolve.resolve().then(resolved => {
assert.ok(inputToResolve.isResolved());
......@@ -100,10 +96,10 @@ suite('Files - FileEditorInput', () => {
});
test('matches', function () {
const input1 = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/updatefile.js'), undefined);
const input2 = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/updatefile.js'), undefined);
const input3 = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/other.js'), undefined);
const input2Upper = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/UPDATEFILE.js'), undefined);
const input1 = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/updatefile.js'), undefined);
const input2 = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/updatefile.js'), undefined);
const input3 = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/other.js'), undefined);
const input2Upper = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/UPDATEFILE.js'), undefined);
assert.strictEqual(input1.matches(null), false);
assert.strictEqual(input1.matches(input1), true);
......@@ -114,7 +110,7 @@ suite('Files - FileEditorInput', () => {
});
test('getEncoding/setEncoding', function () {
const input = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/updatefile.js'), undefined);
const input = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/updatefile.js'), undefined);
input.setEncoding('utf16', EncodingMode.Encode);
assert.equal(input.getEncoding(), 'utf16');
......@@ -127,7 +123,7 @@ suite('Files - FileEditorInput', () => {
});
test('save', function () {
const input = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/updatefile.js'), undefined);
const input = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/updatefile.js'), undefined);
return input.resolve().then((resolved: TextFileEditorModel) => {
resolved.textEditorModel.setValue('changed');
......@@ -142,7 +138,7 @@ suite('Files - FileEditorInput', () => {
});
test('revert', function () {
const input = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/updatefile.js'), undefined);
const input = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/updatefile.js'), undefined);
return input.resolve().then((resolved: TextFileEditorModel) => {
resolved.textEditorModel.setValue('changed');
......@@ -157,7 +153,7 @@ suite('Files - FileEditorInput', () => {
});
test('resolve handles binary files', function () {
const input = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/updatefile.js'), undefined);
const input = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/updatefile.js'), undefined);
accessor.textFileService.setResolveTextContentErrorOnce(new FileOperationError('error', FileOperationResult.FILE_IS_BINARY));
......@@ -169,7 +165,7 @@ suite('Files - FileEditorInput', () => {
});
test('resolve handles too large files', function () {
const input = instantiationService.createInstance(FileEditorInput, toResource(this, '/foo/bar/updatefile.js'), undefined);
const input = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/updatefile.js'), undefined);
accessor.textFileService.setResolveTextContentErrorOnce(new FileOperationError('error', FileOperationResult.FILE_TOO_LARGE));
......
......@@ -5,8 +5,7 @@
import * as assert from 'assert';
import { FileEditorTracker } from 'vs/workbench/contrib/files/browser/editors/fileEditorTracker';
import { URI } from 'vs/base/common/uri';
import { join } from 'vs/base/common/path';
import { toResource } from 'vs/base/test/common/utils';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { workbenchInstantiationService, TestTextFileService, TestFileService } from 'vs/workbench/test/workbenchTestServices';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -16,10 +15,6 @@ import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textF
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { timeout } from 'vs/base/common/async';
function toResource(self: any, path: string) {
return URI.file(join('C:\\', Buffer.from(self.test.fullTitle()).toString('base64'), path));
}
class ServiceAccessor {
constructor(
@IEditorService public editorService: IEditorService,
......@@ -43,7 +38,7 @@ suite('Files - FileEditorTracker', () => {
test('file change event updates model', function () {
const tracker = instantiationService.createInstance(FileEditorTracker);
const resource = toResource(this, '/path/index.txt');
const resource = toResource.call(this, '/path/index.txt');
return accessor.textFileService.models.loadOrCreate(resource).then((model: TextFileEditorModel) => {
model.textEditorModel.setValue('Super Good');
......
......@@ -9,40 +9,33 @@ import { URI } from 'vs/base/common/uri';
import { join } from 'vs/base/common/path';
import { validateFileName } from 'vs/workbench/contrib/files/electron-browser/fileActions';
import { ExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel';
import { toResource } from 'vs/base/test/common/utils';
function createStat(path: string, name: string, isFolder: boolean, hasChildren: boolean, size: number, mtime: number): ExplorerItem {
return new ExplorerItem(toResource(path), null, isFolder, false, false, name, mtime);
function createStat(this: any, path: string, name: string, isFolder: boolean, hasChildren: boolean, size: number, mtime: number): ExplorerItem {
return new ExplorerItem(toResource.call(this, path), null, isFolder, false, false, name, mtime);
}
function toResource(path) {
if (isWindows) {
return URI.file(join('C:\\', path));
} else {
return URI.file(join('/home/john', path));
}
}
suite('Files - View Model', () => {
suite('Files - View Model', function () {
test('Properties', () => {
test('Properties', function () {
const d = new Date().getTime();
let s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
let s = createStat.call(this, '/path/to/stat', 'sName', true, true, 8096, d);
assert.strictEqual(s.isDirectoryResolved, false);
assert.strictEqual(s.resource.fsPath, toResource('/path/to/stat').fsPath);
assert.strictEqual(s.resource.fsPath, toResource.call(this, '/path/to/stat').fsPath);
assert.strictEqual(s.name, 'sName');
assert.strictEqual(s.isDirectory, true);
assert.strictEqual(s.mtime, new Date(d).getTime());
s = createStat('/path/to/stat', 'sName', false, false, 8096, d);
s = createStat.call(this, '/path/to/stat', 'sName', false, false, 8096, d);
});
test('Add and Remove Child, check for hasChild', function () {
const d = new Date().getTime();
const s = createStat('/path/to/stat', 'sName', true, false, 8096, d);
const s = createStat.call(this, '/path/to/stat', 'sName', true, false, 8096, d);
const child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
const child4 = createStat('/otherpath/to/other/otherbar.html', 'otherbar.html', false, false, 8096, d);
const child1 = createStat.call(this, '/path/to/stat/foo', 'foo', true, false, 8096, d);
const child4 = createStat.call(this, '/otherpath/to/other/otherbar.html', 'otherbar.html', false, false, 8096, d);
s.addChild(child1);
......@@ -57,16 +50,16 @@ suite('Files - View Model', () => {
// Assert that adding a child updates its path properly
s.addChild(child4);
assert.strictEqual(child4.resource.fsPath, toResource('/path/to/stat/' + child4.name).fsPath);
assert.strictEqual(child4.resource.fsPath, toResource.call(this, '/path/to/stat/' + child4.name).fsPath);
});
test('Move', () => {
test('Move', function () {
const d = new Date().getTime();
const s1 = createStat('/', '/', true, false, 8096, d);
const s2 = createStat('/path', 'path', true, false, 8096, d);
const s3 = createStat('/path/to', 'to', true, false, 8096, d);
const s4 = createStat('/path/to/stat', 'stat', false, false, 8096, d);
const s1 = createStat.call(this, '/', '/', true, false, 8096, d);
const s2 = createStat.call(this, '/path', 'path', true, false, 8096, d);
const s3 = createStat.call(this, '/path/to', 'to', true, false, 8096, d);
const s4 = createStat.call(this, '/path/to/stat', 'stat', false, false, 8096, d);
s1.addChild(s2);
s2.addChild(s3);
......@@ -75,12 +68,12 @@ suite('Files - View Model', () => {
s4.move(s1);
// Assert the new path of the moved element
assert.strictEqual(s4.resource.fsPath, toResource('/' + s4.name).fsPath);
assert.strictEqual(s4.resource.fsPath, toResource.call(this, '/' + s4.name).fsPath);
// Move a subtree with children
const leaf = createStat('/leaf', 'leaf', true, false, 8096, d);
const leafC1 = createStat('/leaf/folder', 'folder', true, false, 8096, d);
const leafCC2 = createStat('/leaf/folder/index.html', 'index.html', true, false, 8096, d);
const leaf = createStat.call(this, '/leaf', 'leaf', true, false, 8096, d);
const leafC1 = createStat.call(this, '/leaf/folder', 'folder', true, false, 8096, d);
const leafCC2 = createStat.call(this, '/leaf/folder/index.html', 'index.html', true, false, 8096, d);
leaf.addChild(leafC1);
leafC1.addChild(leafCC2);
......@@ -91,47 +84,47 @@ suite('Files - View Model', () => {
assert.strictEqual(leafCC2.resource.fsPath, URI.file(leafC1.resource.fsPath + '/' + leafCC2.name).fsPath);
});
test('Rename', () => {
test('Rename', function () {
const d = new Date().getTime();
const s1 = createStat('/', '/', true, false, 8096, d);
const s2 = createStat('/path', 'path', true, false, 8096, d);
const s3 = createStat('/path/to', 'to', true, false, 8096, d);
const s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
const s1 = createStat.call(this, '/', '/', true, false, 8096, d);
const s2 = createStat.call(this, '/path', 'path', true, false, 8096, d);
const s3 = createStat.call(this, '/path/to', 'to', true, false, 8096, d);
const s4 = createStat.call(this, '/path/to/stat', 'stat', true, false, 8096, d);
s1.addChild(s2);
s2.addChild(s3);
s3.addChild(s4);
assert.strictEqual(s1.getChild(s2.name), s2);
const s2renamed = createStat('/otherpath', 'otherpath', true, true, 8096, d);
const s2renamed = createStat.call(this, '/otherpath', 'otherpath', true, true, 8096, d);
s2.rename(s2renamed);
assert.strictEqual(s1.getChild(s2.name), s2);
// Verify the paths have changed including children
assert.strictEqual(s2.name, s2renamed.name);
assert.strictEqual(s2.resource.fsPath, s2renamed.resource.fsPath);
assert.strictEqual(s3.resource.fsPath, toResource('/otherpath/to').fsPath);
assert.strictEqual(s4.resource.fsPath, toResource('/otherpath/to/stat').fsPath);
assert.strictEqual(s3.resource.fsPath, toResource.call(this, '/otherpath/to').fsPath);
assert.strictEqual(s4.resource.fsPath, toResource.call(this, '/otherpath/to/stat').fsPath);
const s4renamed = createStat('/otherpath/to/statother.js', 'statother.js', true, false, 8096, d);
const s4renamed = createStat.call(this, '/otherpath/to/statother.js', 'statother.js', true, false, 8096, d);
s4.rename(s4renamed);
assert.strictEqual(s3.getChild(s4.name), s4);
assert.strictEqual(s4.name, s4renamed.name);
assert.strictEqual(s4.resource.fsPath, s4renamed.resource.fsPath);
});
test('Find', () => {
test('Find', function () {
const d = new Date().getTime();
const s1 = createStat('/', '/', true, false, 8096, d);
const s2 = createStat('/path', 'path', true, false, 8096, d);
const s3 = createStat('/path/to', 'to', true, false, 8096, d);
const s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
const s4Upper = createStat('/path/to/STAT', 'stat', true, false, 8096, d);
const s1 = createStat.call(this, '/', '/', true, false, 8096, d);
const s2 = createStat.call(this, '/path', 'path', true, false, 8096, d);
const s3 = createStat.call(this, '/path/to', 'to', true, false, 8096, d);
const s4 = createStat.call(this, '/path/to/stat', 'stat', true, false, 8096, d);
const s4Upper = createStat.call(this, '/path/to/STAT', 'stat', true, false, 8096, d);
const child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
const child2 = createStat('/path/to/stat/foo/bar.html', 'bar.html', false, false, 8096, d);
const child1 = createStat.call(this, '/path/to/stat/foo', 'foo', true, false, 8096, d);
const child2 = createStat.call(this, '/path/to/stat/foo/bar.html', 'bar.html', false, false, 8096, d);
s1.addChild(s2);
s2.addChild(s3);
......@@ -151,22 +144,22 @@ suite('Files - View Model', () => {
assert.strictEqual(s1.find(s4Upper.resource), s4);
}
assert.strictEqual(s1.find(toResource('foobar')), null);
assert.strictEqual(s1.find(toResource.call(this, 'foobar')), null);
assert.strictEqual(s1.find(toResource('/')), s1);
// assert.strictEqual(s1.find(toResource('')), s1); //TODO@isidor this fails with proper paths usage
assert.strictEqual(s1.find(toResource.call(this, '/')), s1);
// assert.strictEqual(s1.find(toResource.call(this, '')), s1); //TODO@isidor this fails with proper paths usage
});
test('Find with mixed case', function () {
const d = new Date().getTime();
const s1 = createStat('/', '/', true, false, 8096, d);
const s2 = createStat('/path', 'path', true, false, 8096, d);
const s3 = createStat('/path/to', 'to', true, false, 8096, d);
const s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
const s1 = createStat.call(this, '/', '/', true, false, 8096, d);
const s2 = createStat.call(this, '/path', 'path', true, false, 8096, d);
const s3 = createStat.call(this, '/path/to', 'to', true, false, 8096, d);
const s4 = createStat.call(this, '/path/to/stat', 'stat', true, false, 8096, d);
const child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
const child2 = createStat('/path/to/stat/foo/bar.html', 'bar.html', false, false, 8096, d);
const child1 = createStat.call(this, '/path/to/stat/foo', 'foo', true, false, 8096, d);
const child2 = createStat.call(this, '/path/to/stat/foo/bar.html', 'bar.html', false, false, 8096, d);
s1.addChild(s2);
s2.addChild(s3);
......@@ -175,18 +168,18 @@ suite('Files - View Model', () => {
child1.addChild(child2);
if (isLinux) { // linux is case sensitive
assert.ok(!s1.find(toResource('/path/to/stat/Foo')));
assert.ok(!s1.find(toResource('/Path/to/stat/foo/bar.html')));
assert.ok(!s1.find(toResource.call(this, '/path/to/stat/Foo')));
assert.ok(!s1.find(toResource.call(this, '/Path/to/stat/foo/bar.html')));
} else {
assert.ok(s1.find(toResource('/path/to/stat/Foo')));
assert.ok(s1.find(toResource('/Path/to/stat/foo/bar.html')));
assert.ok(s1.find(toResource.call(this, '/path/to/stat/Foo')));
assert.ok(s1.find(toResource.call(this, '/Path/to/stat/foo/bar.html')));
}
});
test('Validate File Name (For Create)', function () {
const d = new Date().getTime();
const s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
const sChild = createStat('/path/to/stat/alles.klar', 'alles.klar', true, true, 8096, d);
const s = createStat.call(this, '/path/to/stat', 'sName', true, true, 8096, d);
const sChild = createStat.call(this, '/path/to/stat/alles.klar', 'alles.klar', true, true, 8096, d);
s.addChild(sChild);
assert(validateFileName(s, null!) !== null);
......@@ -210,8 +203,8 @@ suite('Files - View Model', () => {
test('Validate File Name (For Rename)', function () {
const d = new Date().getTime();
const s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
const sChild = createStat('/path/to/stat/alles.klar', 'alles.klar', true, true, 8096, d);
const s = createStat.call(this, '/path/to/stat', 'sName', true, true, 8096, d);
const sChild = createStat.call(this, '/path/to/stat/alles.klar', 'alles.klar', true, true, 8096, d);
s.addChild(sChild);
assert(validateFileName(s, 'alles.klar') === null);
......@@ -226,7 +219,7 @@ suite('Files - View Model', () => {
test('Validate Multi-Path File Names', function () {
const d = new Date().getTime();
const wsFolder = createStat('/', 'workspaceFolder', true, false, 8096, d);
const wsFolder = createStat.call(this, '/', 'workspaceFolder', true, false, 8096, d);
assert(validateFileName(wsFolder, 'foo/bar') === null);
assert(validateFileName(wsFolder, 'foo\\bar') === null);
......@@ -235,13 +228,13 @@ suite('Files - View Model', () => {
assert(validateFileName(wsFolder, '/slashAtBeginning') !== null);
// attempting to add a child to a deeply nested file
const s1 = createStat('/path', 'path', true, false, 8096, d);
const s2 = createStat('/path/to', 'to', true, false, 8096, d);
const s3 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
const s1 = createStat.call(this, '/path', 'path', true, false, 8096, d);
const s2 = createStat.call(this, '/path/to', 'to', true, false, 8096, d);
const s3 = createStat.call(this, '/path/to/stat', 'stat', true, false, 8096, d);
wsFolder.addChild(s1);
s1.addChild(s2);
s2.addChild(s3);
const fileDeeplyNested = createStat('/path/to/stat/fileNested', 'fileNested', false, false, 8096, d);
const fileDeeplyNested = createStat.call(this, '/path/to/stat/fileNested', 'fileNested', false, false, 8096, d);
s3.addChild(fileDeeplyNested);
assert(validateFileName(wsFolder, '/path/to/stat/fileNested/aChild') !== null);
......
......@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { join } from 'vs/base/common/path';
import { IEditorModel } from 'vs/platform/editor/common/editor';
import { URI } from 'vs/base/common/uri';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
......@@ -27,6 +26,7 @@ import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorIn
import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { CancellationToken } from 'vs/base/common/cancellation';
import { timeout } from 'vs/base/common/async';
import { toResource } from 'vs/base/test/common/utils';
export class TestEditorControl extends BaseEditor {
......@@ -180,11 +180,11 @@ suite('Editor service', () => {
const service: EditorService = <any>instantiationService.createInstance(EditorService);
// Cached Input (Files)
const fileResource1 = toFileResource(this, '/foo/bar/cache1.js');
const fileResource1 = toResource.call(this, '/foo/bar/cache1.js');
const fileInput1 = service.createInput({ resource: fileResource1 });
assert.ok(fileInput1);
const fileResource2 = toFileResource(this, '/foo/bar/cache2.js');
const fileResource2 = toResource.call(this, '/foo/bar/cache2.js');
const fileInput2 = service.createInput({ resource: fileResource2 });
assert.ok(fileInput2);
......@@ -202,11 +202,11 @@ suite('Editor service', () => {
assert.ok(!fileInput1AgainAndAgain.isDisposed());
// Cached Input (Resource)
const resource1 = toResource.call(this, '/foo/bar/cache1.js');
const resource1 = URI.from({ scheme: 'custom', path: '/foo/bar/cache1.js' });
const input1 = service.createInput({ resource: resource1 });
assert.ok(input1);
const resource2 = toResource.call(this, '/foo/bar/cache2.js');
const resource2 = URI.from({ scheme: 'custom', path: '/foo/bar/cache2.js' });
const input2 = service.createInput({ resource: resource2 });
assert.ok(input2);
......@@ -229,13 +229,13 @@ suite('Editor service', () => {
const service: EditorService = <any>instantiationService.createInstance(EditorService);
// Untyped Input (file)
let input = service.createInput({ resource: toFileResource(this, '/index.html'), options: { selection: { startLineNumber: 1, startColumn: 1 } } });
let input = service.createInput({ resource: toResource.call(this, '/index.html'), options: { selection: { startLineNumber: 1, startColumn: 1 } } });
assert(input instanceof FileEditorInput);
let contentInput = <FileEditorInput>input;
assert.strictEqual(contentInput.getResource().fsPath, toFileResource(this, '/index.html').fsPath);
assert.strictEqual(contentInput.getResource().fsPath, toResource.call(this, '/index.html').fsPath);
// Untyped Input (file, encoding)
input = service.createInput({ resource: toFileResource(this, '/index.html'), encoding: 'utf16le', options: { selection: { startLineNumber: 1, startColumn: 1 } } });
input = service.createInput({ resource: toResource.call(this, '/index.html'), encoding: 'utf16le', options: { selection: { startLineNumber: 1, startColumn: 1 } } });
assert(input instanceof FileEditorInput);
contentInput = <FileEditorInput>input;
assert.equal(contentInput.getPreferredEncoding(), 'utf16le');
......@@ -598,11 +598,3 @@ suite('Editor service', () => {
assert.ok(!failingEditor);
});
});
function toResource(path: string) {
return URI.from({ scheme: 'custom', path });
}
function toFileResource(self: any, path: string) {
return URI.file(join('C:\\', Buffer.from(self.test.fullTitle()).toString('base64'), path));
}
......@@ -7,12 +7,12 @@ import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager';
import { join } from 'vs/base/common/path';
import { workbenchInstantiationService, TestFileService } from 'vs/workbench/test/workbenchTestServices';
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
import { IFileService, FileChangesEvent, FileChangeType } from 'vs/platform/files/common/files';
import { IModelService } from 'vs/editor/common/services/modelService';
import { timeout } from 'vs/base/common/async';
import { toResource } from 'vs/base/test/common/utils';
export class TestTextFileEditorModelManager extends TextFileEditorModelManager {
......@@ -29,10 +29,6 @@ class ServiceAccessor {
}
}
function toResource(path: string): URI {
return URI.file(join('C:\\', path));
}
suite('Files - TextFileEditorModelManager', () => {
let instantiationService: IInstantiationService;
......@@ -46,9 +42,9 @@ suite('Files - TextFileEditorModelManager', () => {
test('add, remove, clear, get, getAll', function () {
const manager: TestTextFileEditorModelManager = instantiationService.createInstance(TestTextFileEditorModelManager);
const model1: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource('/path/random1.txt'), 'utf8');
const model2: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource('/path/random2.txt'), 'utf8');
const model3: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource('/path/random3.txt'), 'utf8');
const model1: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/random1.txt'), 'utf8');
const model2: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/random2.txt'), 'utf8');
const model3: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/random3.txt'), 'utf8');
manager.add(URI.file('/test.html'), model1);
manager.add(URI.file('/some/other.html'), model2);
......@@ -126,9 +122,9 @@ suite('Files - TextFileEditorModelManager', () => {
test('removed from cache when model disposed', function () {
const manager: TestTextFileEditorModelManager = instantiationService.createInstance(TestTextFileEditorModelManager);
const model1: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource('/path/random1.txt'), 'utf8');
const model2: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource('/path/random2.txt'), 'utf8');
const model3: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource('/path/random3.txt'), 'utf8');
const model1: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/random1.txt'), 'utf8');
const model2: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/random2.txt'), 'utf8');
const model3: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/random3.txt'), 'utf8');
manager.add(URI.file('/test.html'), model1);
manager.add(URI.file('/some/other.html'), model2);
......@@ -143,14 +139,14 @@ suite('Files - TextFileEditorModelManager', () => {
model3.dispose();
});
test('events', () => {
test('events', function () {
TextFileEditorModel.DEFAULT_CONTENT_CHANGE_BUFFER_DELAY = 0;
TextFileEditorModel.DEFAULT_ORPHANED_CHANGE_BUFFER_DELAY = 0;
const manager: TestTextFileEditorModelManager = instantiationService.createInstance(TestTextFileEditorModelManager);
const resource1 = toResource('/path/index.txt');
const resource2 = toResource('/path/other.txt');
const resource1 = toResource.call(this, '/path/index.txt');
const resource2 = toResource.call(this, '/path/other.txt');
let dirtyCounter = 0;
let revertedCounter = 0;
......@@ -235,8 +231,8 @@ suite('Files - TextFileEditorModelManager', () => {
test('events debounced', function () {
const manager: TestTextFileEditorModelManager = instantiationService.createInstance(TestTextFileEditorModelManager);
const resource1 = toResource('/path/index.txt');
const resource2 = toResource('/path/other.txt');
const resource1 = toResource.call(this, '/path/index.txt');
const resource2 = toResource.call(this, '/path/other.txt');
let dirtyCounter = 0;
let revertedCounter = 0;
......@@ -293,7 +289,7 @@ suite('Files - TextFileEditorModelManager', () => {
test('disposing model takes it out of the manager', function () {
const manager: TestTextFileEditorModelManager = instantiationService.createInstance(TestTextFileEditorModelManager);
const resource = toResource('/path/index_something.txt');
const resource = toResource.call(this, '/path/index_something.txt');
return manager.loadOrCreate(resource, { encoding: 'utf8' }).then(model => {
model.dispose();
......@@ -308,7 +304,7 @@ suite('Files - TextFileEditorModelManager', () => {
test('dispose prevents dirty model from getting disposed', function () {
const manager: TestTextFileEditorModelManager = instantiationService.createInstance(TestTextFileEditorModelManager);
const resource = toResource('/path/index_something.txt');
const resource = toResource.call(this, '/path/index_something.txt');
return manager.loadOrCreate(resource, { encoding: 'utf8' }).then(model => {
model.textEditorModel.setValue('make dirty');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册