mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
add more meaningful api tests
This commit is contained in:
@@ -6,8 +6,15 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import {workspace, TextDocument} from 'vscode';
|
||||
import {workspace, TextDocument, window, Position} from 'vscode';
|
||||
import {createRandomFile, deleteFile} from './utils';
|
||||
import {join} from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
|
||||
function rndName() {
|
||||
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
|
||||
}
|
||||
|
||||
suite('workspace-namespace', () => {
|
||||
|
||||
@@ -38,17 +45,52 @@ suite('workspace-namespace', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// test('createTextDocument', done => {
|
||||
test('events: onDidOpenTextDocument, onDidChangeTextDocument, onDidSaveTextDocument', (done) => {
|
||||
createRandomFile().then(file => {
|
||||
let onDidOpenTextDocument = false;
|
||||
workspace.onDidOpenTextDocument(e => {
|
||||
assert.equal(e.uri.fsPath, file.fsPath);
|
||||
onDidOpenTextDocument = true;
|
||||
});
|
||||
|
||||
// let text = 'Das Pferd isst keinen Reis.'
|
||||
let onDidChangeTextDocument = false;
|
||||
workspace.onDidChangeTextDocument(e => {
|
||||
assert.equal(e.document.uri.fsPath, file.fsPath);
|
||||
onDidChangeTextDocument = true;
|
||||
});
|
||||
|
||||
// workspace.createTextDocument(text).then(doc => {
|
||||
// assert.equal(doc.getText(), text);
|
||||
// assert.equal(doc.uri.scheme, 'untitled');
|
||||
// assert.equal(doc.languageId, 'plaintext');
|
||||
// done();
|
||||
// }, err => {
|
||||
// done(err);
|
||||
// });
|
||||
// });
|
||||
let onDidSaveTextDocument = false;
|
||||
workspace.onDidSaveTextDocument(e => {
|
||||
assert.equal(e.uri.fsPath, file.fsPath);
|
||||
onDidSaveTextDocument = true;
|
||||
});
|
||||
|
||||
return workspace.openTextDocument(file).then(doc => {
|
||||
return window.showTextDocument(doc).then((editor) => {
|
||||
return editor.edit((builder) => {
|
||||
builder.insert(new Position(0, 0), 'Hello World');
|
||||
}).then(applied => {
|
||||
return doc.save().then(saved => {
|
||||
assert.ok(onDidOpenTextDocument);
|
||||
assert.ok(onDidChangeTextDocument);
|
||||
assert.ok(onDidSaveTextDocument);
|
||||
|
||||
return deleteFile(file);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}).then(() => done(), (error) => done(error));
|
||||
});
|
||||
|
||||
test('findFiles', done => {
|
||||
workspace.findFiles('*.js', null).then((res) => {
|
||||
assert.equal(res.length, 1);
|
||||
assert.equal(workspace.asRelativePath(res[0]), '/far.js');
|
||||
|
||||
done();
|
||||
}, err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user