add some tests

This commit is contained in:
Johannes Rieken
2017-03-10 10:19:33 +01:00
parent 57bb940794
commit e0bbbb8653
2 changed files with 64 additions and 23 deletions
@@ -6,7 +6,7 @@
'use strict';
import * as assert from 'assert';
import { workspace, TextDocument, window, Position, Uri, EventEmitter, WorkspaceEdit, Disposable } from 'vscode';
import { workspace, TextDocument, window, Position, Uri, EventEmitter, WorkspaceEdit, Disposable, EndOfLine } from 'vscode';
import { createRandomFile, deleteFile, cleanUp, pathEquals } from './utils';
import { join, basename } from 'path';
import * as fs from 'fs';
@@ -160,6 +160,41 @@ suite('workspace-namespace', () => {
});
});
test('eol, read', () => {
const a = createRandomFile('foo\nbar\nbar').then(file => {
return workspace.openTextDocument(file).then(doc => {
assert.equal(doc.eol, EndOfLine.LF);
});
});
const b = createRandomFile('foo\nbar\nbar\r\nbaz').then(file => {
return workspace.openTextDocument(file).then(doc => {
assert.equal(doc.eol, EndOfLine.LF);
});
});
const c = createRandomFile('foo\r\nbar\r\nbar').then(file => {
return workspace.openTextDocument(file).then(doc => {
assert.equal(doc.eol, EndOfLine.CRLF);
});
});
return Promise.all([a, b, c]);
});
test('eol, change via editor', () => {
return createRandomFile('foo\nbar\nbar').then(file => {
return workspace.openTextDocument(file).then(doc => {
assert.equal(doc.eol, EndOfLine.LF);
return window.showTextDocument(doc).then(editor => {
return editor.edit(builder => builder.setEndOfLine(EndOfLine.CRLF));
}).then(value => {
assert.ok(value);
assert.ok(doc.isDirty);
assert.equal(doc.eol, EndOfLine.CRLF);
});
});
});
});
test('events: onDidOpenTextDocument, onDidChangeTextDocument, onDidSaveTextDocument', () => {
return createRandomFile().then(file => {
let disposables: Disposable[] = [];
+28 -22
View File
@@ -1997,28 +1997,6 @@ declare module 'vscode' {
provideReferences(document: TextDocument, position: Position, context: ReferenceContext, token: CancellationToken): ProviderResult<Location[]>;
}
/**
* An end-of-line edit represents a change of the [sequence](#TextDocument.eol)
* that separates the lines in a document.
*/
export class EndOfLineEdit {
/**
* Use the line feed `\n` character.
*/
static readonly LF: EndOfLineEdit;
/**
* Use the carriage return line feed `\r\n` sequence.
*/
static readonly CRLF: EndOfLineEdit;
/**
* The new end of line sequence
*/
newEol: EndOfLine;
}
/**
* A text edit represents edits that should be applied
* to a document.
@@ -2070,6 +2048,34 @@ declare module 'vscode' {
constructor(range: Range, newText: string);
}
/**
* Represents a change of the [eol-sequence](#TextDocument.eol) that is used in a document.
*/
export class EndOfLineEdit {
/**
* Use the line feed `\n` character.
*/
static readonly LF: EndOfLineEdit;
/**
* Use the carriage return line feed `\r\n` sequence.
*/
static readonly CRLF: EndOfLineEdit;
/**
* The new end of line sequence
*/
newEol: EndOfLine;
/**
* Create a new EndOfLineEdit.
*
* @param newEol A new end of line sequence.
*/
constructor(newEol: EndOfLine);
}
/**
* A workspace edit represents textual changes for many documents.
*/