mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
add some tests
This commit is contained in:
@@ -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[] = [];
|
||||
|
||||
Vendored
+28
-22
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user