mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge VS Code 1.21 source code (#1067)
* Initial VS Code 1.21 file copy with patches * A few more merges * Post npm install * Fix batch of build breaks * Fix more build breaks * Fix more build errors * Fix more build breaks * Runtime fixes 1 * Get connection dialog working with some todos * Fix a few packaging issues * Copy several node_modules to package build to fix loader issues * Fix breaks from master * A few more fixes * Make tests pass * First pass of license header updates * Second pass of license header updates * Fix restore dialog issues * Remove add additional themes menu items * fix select box issues where the list doesn't show up * formatting * Fix editor dispose issue * Copy over node modules to correct location on all platforms
This commit is contained in:
@@ -8,13 +8,13 @@
|
||||
import Uri from 'vs/base/common/uri';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IResolveContentOptions, IUpdateContentOptions } from 'vs/platform/files/common/files';
|
||||
import { IRawTextSource } from 'vs/editor/common/model/textSource';
|
||||
import { IResolveContentOptions, IUpdateContentOptions, ITextSnapshot } from 'vs/platform/files/common/files';
|
||||
import { ITextBufferFactory } from 'vs/editor/common/model';
|
||||
|
||||
export const IBackupFileService = createDecorator<IBackupFileService>('backupFileService');
|
||||
|
||||
export const BACKUP_FILE_RESOLVE_OPTIONS: IResolveContentOptions = { acceptTextOnly: true, encoding: 'utf-8' };
|
||||
export const BACKUP_FILE_UPDATE_OPTIONS: IUpdateContentOptions = { encoding: 'utf-8' };
|
||||
export const BACKUP_FILE_RESOLVE_OPTIONS: IResolveContentOptions = { acceptTextOnly: true, encoding: 'utf8' };
|
||||
export const BACKUP_FILE_UPDATE_OPTIONS: IUpdateContentOptions = { encoding: 'utf8' };
|
||||
|
||||
/**
|
||||
* A service that handles any I/O and state associated with the backup system.
|
||||
@@ -40,14 +40,22 @@ export interface IBackupFileService {
|
||||
*/
|
||||
loadBackupResource(resource: Uri): TPromise<Uri>;
|
||||
|
||||
/**
|
||||
* Given a resource, returns the associated backup resource.
|
||||
*
|
||||
* @param resource The resource to get the backup resource for.
|
||||
* @return The backup resource.
|
||||
*/
|
||||
toBackupResource(resource: Uri): Uri;
|
||||
|
||||
/**
|
||||
* Backs up a resource.
|
||||
*
|
||||
* @param resource The resource to back up.
|
||||
* @param content The content of the resource.
|
||||
* @param content The content of the resource as snapshot.
|
||||
* @param versionId The version id of the resource to backup.
|
||||
*/
|
||||
backupResource(resource: Uri, content: string, versionId?: number): TPromise<void>;
|
||||
backupResource(resource: Uri, content: ITextSnapshot, versionId?: number): TPromise<void>;
|
||||
|
||||
/**
|
||||
* Gets a list of file backups for the current workspace.
|
||||
@@ -57,13 +65,12 @@ export interface IBackupFileService {
|
||||
getWorkspaceFileBackups(): TPromise<Uri[]>;
|
||||
|
||||
/**
|
||||
* Parses backup raw text content into the content, removing the metadata that is also stored
|
||||
* in the file.
|
||||
* Resolves the backup for the given resource.
|
||||
*
|
||||
* @param rawText The IRawTextProvider from a backup resource.
|
||||
* @return The backup file's backed up content.
|
||||
* @param value The contents from a backup resource as stream.
|
||||
* @return The backup file's backed up content as text buffer factory.
|
||||
*/
|
||||
parseBackupContent(textSource: IRawTextSource): string;
|
||||
resolveBackupContent(backup: Uri): TPromise<ITextBufferFactory>;
|
||||
|
||||
/**
|
||||
* Discards the backup associated with a resource if it exists..
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
|
||||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
import pfs = require('vs/base/node/pfs');
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
import Uri from 'vs/base/common/uri';
|
||||
import { ResourceQueue } from 'vs/base/common/async';
|
||||
import { IBackupFileService, BACKUP_FILE_UPDATE_OPTIONS } from 'vs/workbench/services/backup/common/backup';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { IBackupFileService, BACKUP_FILE_UPDATE_OPTIONS, BACKUP_FILE_RESOLVE_OPTIONS } from 'vs/workbench/services/backup/common/backup';
|
||||
import { IFileService, ITextSnapshot } from 'vs/platform/files/common/files';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { readToMatchingString } from 'vs/base/node/stream';
|
||||
import { TextSource, IRawTextSource } from 'vs/editor/common/model/textSource';
|
||||
import { DefaultEndOfLine } from 'vs/editor/common/editorCommon';
|
||||
import { ITextBufferFactory } from 'vs/editor/common/model';
|
||||
import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel';
|
||||
|
||||
export interface IBackupFilesModel {
|
||||
resolve(backupRoot: string): TPromise<IBackupFilesModel>;
|
||||
@@ -28,6 +28,28 @@ export interface IBackupFilesModel {
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
export class BackupSnapshot implements ITextSnapshot {
|
||||
private preambleHandled: boolean;
|
||||
|
||||
constructor(private snapshot: ITextSnapshot, private preamble: string) {
|
||||
}
|
||||
|
||||
public read(): string {
|
||||
let value = this.snapshot.read();
|
||||
if (!this.preambleHandled) {
|
||||
this.preambleHandled = true;
|
||||
|
||||
if (typeof value === 'string') {
|
||||
value = this.preamble + value;
|
||||
} else {
|
||||
value = this.preamble;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
export class BackupFilesModel implements IBackupFilesModel {
|
||||
private cache: { [resource: string]: number /* version ID */ } = Object.create(null);
|
||||
|
||||
@@ -135,7 +157,7 @@ export class BackupFileService implements IBackupFileService {
|
||||
|
||||
public loadBackupResource(resource: Uri): TPromise<Uri> {
|
||||
return this.ready.then(model => {
|
||||
const backupResource = this.getBackupResource(resource);
|
||||
const backupResource = this.toBackupResource(resource);
|
||||
if (!backupResource) {
|
||||
return void 0;
|
||||
}
|
||||
@@ -149,13 +171,13 @@ export class BackupFileService implements IBackupFileService {
|
||||
});
|
||||
}
|
||||
|
||||
public backupResource(resource: Uri, content: string, versionId?: number): TPromise<void> {
|
||||
public backupResource(resource: Uri, content: ITextSnapshot, versionId?: number): TPromise<void> {
|
||||
if (this.isShuttingDown) {
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
return this.ready.then(model => {
|
||||
const backupResource = this.getBackupResource(resource);
|
||||
const backupResource = this.toBackupResource(resource);
|
||||
if (!backupResource) {
|
||||
return void 0;
|
||||
}
|
||||
@@ -164,18 +186,18 @@ export class BackupFileService implements IBackupFileService {
|
||||
return void 0; // return early if backup version id matches requested one
|
||||
}
|
||||
|
||||
// Add metadata to top of file
|
||||
content = `${resource.toString()}${BackupFileService.META_MARKER}${content}`;
|
||||
|
||||
return this.ioOperationQueues.queueFor(backupResource).queue(() => {
|
||||
return this.fileService.updateContent(backupResource, content, BACKUP_FILE_UPDATE_OPTIONS).then(() => model.add(backupResource, versionId));
|
||||
const preamble = `${resource.toString()}${BackupFileService.META_MARKER}`;
|
||||
|
||||
// Update content with value
|
||||
return this.fileService.updateContent(backupResource, new BackupSnapshot(content, preamble), BACKUP_FILE_UPDATE_OPTIONS).then(() => model.add(backupResource, versionId));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public discardResourceBackup(resource: Uri): TPromise<void> {
|
||||
return this.ready.then(model => {
|
||||
const backupResource = this.getBackupResource(resource);
|
||||
const backupResource = this.toBackupResource(resource);
|
||||
if (!backupResource) {
|
||||
return void 0;
|
||||
}
|
||||
@@ -213,12 +235,30 @@ export class BackupFileService implements IBackupFileService {
|
||||
});
|
||||
}
|
||||
|
||||
public parseBackupContent(rawTextSource: IRawTextSource): string {
|
||||
const textSource = TextSource.fromRawTextSource(rawTextSource, DefaultEndOfLine.LF);
|
||||
return textSource.lines.slice(1).join(textSource.EOL); // The first line of a backup text file is the file name
|
||||
public resolveBackupContent(backup: Uri): TPromise<ITextBufferFactory> {
|
||||
return this.fileService.resolveStreamContent(backup, BACKUP_FILE_RESOLVE_OPTIONS).then(content => {
|
||||
|
||||
// Add a filter method to filter out everything until the meta marker
|
||||
let metaFound = false;
|
||||
const metaPreambleFilter = (chunk: string) => {
|
||||
if (!metaFound && chunk) {
|
||||
const metaIndex = chunk.indexOf(BackupFileService.META_MARKER);
|
||||
if (metaIndex === -1) {
|
||||
return ''; // meta not yet found, return empty string
|
||||
}
|
||||
|
||||
metaFound = true;
|
||||
return chunk.substr(metaIndex + 1); // meta found, return everything after
|
||||
}
|
||||
|
||||
return chunk;
|
||||
};
|
||||
|
||||
return createTextBufferFactoryFromStream(content.value, metaPreambleFilter);
|
||||
});
|
||||
}
|
||||
|
||||
protected getBackupResource(resource: Uri): Uri {
|
||||
public toBackupResource(resource: Uri): Uri {
|
||||
if (!this.backupEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,10 +16,13 @@ import pfs = require('vs/base/node/pfs');
|
||||
import Uri from 'vs/base/common/uri';
|
||||
import { BackupFileService, BackupFilesModel } from 'vs/workbench/services/backup/node/backupFileService';
|
||||
import { FileService } from 'vs/workbench/services/files/node/fileService';
|
||||
import { RawTextSource } from 'vs/editor/common/model/textSource';
|
||||
import { TestContextService, TestTextResourceConfigurationService, getRandomTestPath, TestLifecycleService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { TextModel, createTextBufferFactory } from 'vs/editor/common/model/textModel';
|
||||
import { TestContextService, TestTextResourceConfigurationService, getRandomTestPath, TestLifecycleService, TestEnvironmentService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { Workspace, toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
|
||||
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
|
||||
import { DefaultEndOfLine } from 'vs/editor/common/model';
|
||||
import { snapshotToString } from 'vs/platform/files/common/files';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
|
||||
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupfileservice');
|
||||
const backupHome = path.join(parentDir, 'Backups');
|
||||
@@ -29,20 +32,20 @@ const workspaceResource = Uri.file(platform.isWindows ? 'c:\\workspace' : '/work
|
||||
const workspaceBackupPath = path.join(backupHome, crypto.createHash('md5').update(workspaceResource.fsPath).digest('hex'));
|
||||
const fooFile = Uri.file(platform.isWindows ? 'c:\\Foo' : '/Foo');
|
||||
const barFile = Uri.file(platform.isWindows ? 'c:\\Bar' : '/Bar');
|
||||
const untitledFile = Uri.from({ scheme: 'untitled', path: 'Untitled-1' });
|
||||
const untitledFile = Uri.from({ scheme: Schemas.untitled, path: 'Untitled-1' });
|
||||
const fooBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(fooFile.fsPath).digest('hex'));
|
||||
const barBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(barFile.fsPath).digest('hex'));
|
||||
const untitledBackupPath = path.join(workspaceBackupPath, 'untitled', crypto.createHash('md5').update(untitledFile.fsPath).digest('hex'));
|
||||
|
||||
class TestBackupFileService extends BackupFileService {
|
||||
constructor(workspace: Uri, backupHome: string, workspacesJsonPath: string) {
|
||||
const fileService = new FileService(new TestContextService(new Workspace(workspace.fsPath, workspace.fsPath, toWorkspaceFolders([{ path: workspace.fsPath }]))), new TestTextResourceConfigurationService(), new TestConfigurationService(), new TestLifecycleService(), { disableWatcher: true });
|
||||
const fileService = new FileService(new TestContextService(new Workspace(workspace.fsPath, workspace.fsPath, toWorkspaceFolders([{ path: workspace.fsPath }]))), TestEnvironmentService, new TestTextResourceConfigurationService(), new TestConfigurationService(), new TestLifecycleService(), { disableWatcher: true });
|
||||
|
||||
super(workspaceBackupPath, fileService);
|
||||
}
|
||||
|
||||
public getBackupResource(resource: Uri): Uri {
|
||||
return super.getBackupResource(resource);
|
||||
public toBackupResource(resource: Uri): Uri {
|
||||
return super.toBackupResource(resource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,16 +76,16 @@ suite('BackupFileService', () => {
|
||||
const workspaceHash = crypto.createHash('md5').update(workspaceResource.fsPath).digest('hex');
|
||||
const filePathHash = crypto.createHash('md5').update(backupResource.fsPath).digest('hex');
|
||||
const expectedPath = Uri.file(path.join(backupHome, workspaceHash, 'file', filePathHash)).fsPath;
|
||||
assert.equal(service.getBackupResource(backupResource).fsPath, expectedPath);
|
||||
assert.equal(service.toBackupResource(backupResource).fsPath, expectedPath);
|
||||
});
|
||||
|
||||
test('should get the correct backup path for untitled files', () => {
|
||||
// Format should be: <backupHome>/<workspaceHash>/<scheme>/<filePath>
|
||||
const backupResource = Uri.from({ scheme: 'untitled', path: 'Untitled-1' });
|
||||
const backupResource = Uri.from({ scheme: Schemas.untitled, path: 'Untitled-1' });
|
||||
const workspaceHash = crypto.createHash('md5').update(workspaceResource.fsPath).digest('hex');
|
||||
const filePathHash = crypto.createHash('md5').update(backupResource.fsPath).digest('hex');
|
||||
const expectedPath = Uri.file(path.join(backupHome, workspaceHash, 'untitled', filePathHash)).fsPath;
|
||||
assert.equal(service.getBackupResource(backupResource).fsPath, expectedPath);
|
||||
assert.equal(service.toBackupResource(backupResource).fsPath, expectedPath);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -105,7 +108,7 @@ suite('BackupFileService', () => {
|
||||
|
||||
suite('backupResource', () => {
|
||||
test('text file', function (done: () => void) {
|
||||
service.backupResource(fooFile, 'test').then(() => {
|
||||
service.backupResource(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath), `${fooFile.toString()}\ntest`);
|
||||
@@ -114,18 +117,68 @@ suite('BackupFileService', () => {
|
||||
});
|
||||
|
||||
test('untitled file', function (done: () => void) {
|
||||
service.backupResource(untitledFile, 'test').then(() => {
|
||||
service.backupResource(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.equal(fs.existsSync(untitledBackupPath), true);
|
||||
assert.equal(fs.readFileSync(untitledBackupPath), `${untitledFile.toString()}\ntest`);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('text file (ITextSnapshot)', function (done: () => void) {
|
||||
const model = TextModel.createFromString('test');
|
||||
|
||||
service.backupResource(fooFile, model.createSnapshot()).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath), `${fooFile.toString()}\ntest`);
|
||||
model.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('untitled file (ITextSnapshot)', function (done: () => void) {
|
||||
const model = TextModel.createFromString('test');
|
||||
|
||||
service.backupResource(untitledFile, model.createSnapshot()).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.equal(fs.existsSync(untitledBackupPath), true);
|
||||
assert.equal(fs.readFileSync(untitledBackupPath), `${untitledFile.toString()}\ntest`);
|
||||
model.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('text file (large file, ITextSnapshot)', function (done: () => void) {
|
||||
const largeString = (new Array(10 * 1024)).join('Large String\n');
|
||||
const model = TextModel.createFromString(largeString);
|
||||
|
||||
service.backupResource(fooFile, model.createSnapshot()).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath), `${fooFile.toString()}\n${largeString}`);
|
||||
model.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('untitled file (large file, ITextSnapshot)', function (done: () => void) {
|
||||
const largeString = (new Array(10 * 1024)).join('Large String\n');
|
||||
const model = TextModel.createFromString(largeString);
|
||||
|
||||
service.backupResource(untitledFile, model.createSnapshot()).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.equal(fs.existsSync(untitledBackupPath), true);
|
||||
assert.equal(fs.readFileSync(untitledBackupPath), `${untitledFile.toString()}\n${largeString}`);
|
||||
model.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('discardResourceBackup', () => {
|
||||
test('text file', function (done: () => void) {
|
||||
service.backupResource(fooFile, 'test').then(() => {
|
||||
service.backupResource(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
service.discardResourceBackup(fooFile).then(() => {
|
||||
assert.equal(fs.existsSync(fooBackupPath), false);
|
||||
@@ -136,7 +189,7 @@ suite('BackupFileService', () => {
|
||||
});
|
||||
|
||||
test('untitled file', function (done: () => void) {
|
||||
service.backupResource(untitledFile, 'test').then(() => {
|
||||
service.backupResource(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
service.discardResourceBackup(untitledFile).then(() => {
|
||||
assert.equal(fs.existsSync(untitledBackupPath), false);
|
||||
@@ -149,9 +202,9 @@ suite('BackupFileService', () => {
|
||||
|
||||
suite('discardAllWorkspaceBackups', () => {
|
||||
test('text file', function (done: () => void) {
|
||||
service.backupResource(fooFile, 'test').then(() => {
|
||||
service.backupResource(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
service.backupResource(barFile, 'test').then(() => {
|
||||
service.backupResource(barFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 2);
|
||||
service.discardAllWorkspaceBackups().then(() => {
|
||||
assert.equal(fs.existsSync(fooBackupPath), false);
|
||||
@@ -164,7 +217,7 @@ suite('BackupFileService', () => {
|
||||
});
|
||||
|
||||
test('untitled file', function (done: () => void) {
|
||||
service.backupResource(untitledFile, 'test').then(() => {
|
||||
service.backupResource(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
service.discardAllWorkspaceBackups().then(() => {
|
||||
assert.equal(fs.existsSync(untitledBackupPath), false);
|
||||
@@ -176,7 +229,7 @@ suite('BackupFileService', () => {
|
||||
|
||||
test('should disable further backups', function (done: () => void) {
|
||||
service.discardAllWorkspaceBackups().then(() => {
|
||||
service.backupResource(untitledFile, 'test').then(() => {
|
||||
service.backupResource(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
assert.equal(fs.existsSync(workspaceBackupPath), false);
|
||||
done();
|
||||
});
|
||||
@@ -186,10 +239,10 @@ suite('BackupFileService', () => {
|
||||
|
||||
suite('getWorkspaceFileBackups', () => {
|
||||
test('("file") - text file', done => {
|
||||
service.backupResource(fooFile, `test`).then(() => {
|
||||
service.backupResource(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
service.getWorkspaceFileBackups().then(textFiles => {
|
||||
assert.deepEqual(textFiles.map(f => f.fsPath), [fooFile.fsPath]);
|
||||
service.backupResource(barFile, `test`).then(() => {
|
||||
service.backupResource(barFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
service.getWorkspaceFileBackups().then(textFiles => {
|
||||
assert.deepEqual(textFiles.map(f => f.fsPath), [fooFile.fsPath, barFile.fsPath]);
|
||||
done();
|
||||
@@ -200,7 +253,7 @@ suite('BackupFileService', () => {
|
||||
});
|
||||
|
||||
test('("file") - untitled file', done => {
|
||||
service.backupResource(untitledFile, `test`).then(() => {
|
||||
service.backupResource(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
service.getWorkspaceFileBackups().then(textFiles => {
|
||||
assert.deepEqual(textFiles.map(f => f.fsPath), [untitledFile.fsPath]);
|
||||
done();
|
||||
@@ -209,7 +262,7 @@ suite('BackupFileService', () => {
|
||||
});
|
||||
|
||||
test('("untitled") - untitled file', done => {
|
||||
service.backupResource(untitledFile, `test`).then(() => {
|
||||
service.backupResource(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
service.getWorkspaceFileBackups().then(textFiles => {
|
||||
assert.deepEqual(textFiles.map(f => f.fsPath), ['Untitled-1']);
|
||||
done();
|
||||
@@ -218,10 +271,29 @@ suite('BackupFileService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('parseBackupContent', () => {
|
||||
test('should separate metadata from content', () => {
|
||||
const textSource = RawTextSource.fromString('metadata\ncontent');
|
||||
assert.equal(service.parseBackupContent(textSource), 'content');
|
||||
test('resolveBackupContent', () => {
|
||||
test('should restore the original contents (untitled file)', () => {
|
||||
const contents = 'test\nand more stuff';
|
||||
service.backupResource(untitledFile, createTextBufferFactory(contents).create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
service.resolveBackupContent(service.toBackupResource(untitledFile)).then(factory => {
|
||||
assert.equal(contents, snapshotToString(factory.create(platform.isWindows ? DefaultEndOfLine.CRLF : DefaultEndOfLine.LF).createSnapshot(true)));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should restore the original contents (text file)', () => {
|
||||
const contents = [
|
||||
'Lorem ipsum ',
|
||||
'dolor öäü sit amet ',
|
||||
'consectetur ',
|
||||
'adipiscing ßß elit',
|
||||
].join('');
|
||||
|
||||
service.backupResource(fooFile, createTextBufferFactory(contents).create(DefaultEndOfLine.LF).createSnapshot(false)).then(() => {
|
||||
service.resolveBackupContent(service.toBackupResource(untitledFile)).then(factory => {
|
||||
assert.equal(contents, snapshotToString(factory.create(platform.isWindows ? DefaultEndOfLine.CRLF : DefaultEndOfLine.LF).createSnapshot(true)));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user