Vim/test/operator/put.test.ts

67 lines
2.5 KiB
TypeScript
Raw Normal View History

2016-04-25 15:24:49 +03:00
"use strict";
import * as assert from 'assert';
import * as vscode from 'vscode';
2016-04-28 15:20:37 +03:00
import { copy } from "copy-paste";
2016-04-25 15:24:49 +03:00
import { ModeHandler } from "../../src/mode/modeHandler";
import { PutOperator } from "../../src/operator/put";
import { TextEditor } from '../../src/textEditor';
import { Position, PositionOptions } from "../../src/motion/position";
import { setupWorkspace, cleanUpWorkspace } from '../testUtils';
suite("put operator", () => {
suiteSetup(setupWorkspace);
suiteTeardown(cleanUpWorkspace);
test("put 'the dog' into empty file", async () => {
const expectedText = "the dog";
const position = new Position(0, 0, PositionOptions.CharacterWiseExclusive);
const mode = new ModeHandler();
const put = new PutOperator(mode);
await new Promise(resolve => {
copy(expectedText, () => resolve());
});
2016-04-25 15:24:49 +03:00
await put.run(position, position);
const actualText = TextEditor.readLineAt(0);
const cursorPosition = vscode.window.activeTextEditor.selection.active;
assert.equal(actualText, expectedText,
"did not paste expected content");
assert.equal(cursorPosition.line, position.getRight().line,
"cursor should be on the same line");
assert.equal(cursorPosition.character, position.getRight().character,
"cursor should be on start of put content");
});
test("put ' brown' into 'the dog'", async () => {
const phrase = "brown ";
const expectedText = `the ${phrase}dog`;
const position = new Position(0, 3, PositionOptions.CharacterWiseExclusive);
const mode = new ModeHandler();
const put = new PutOperator(mode);
await new Promise(resolve => {
copy(phrase, () => resolve());
});
2016-04-25 15:24:49 +03:00
// using ^ to show the cusor position
// before : the dog
// ^
// after : the brown dog
// ^
await put.run(position, position);
const actualText = TextEditor.readLineAt(0);
const cursorPosition = vscode.window.activeTextEditor.selection.active;
assert.equal(actualText, expectedText,
"did not paste expected content");
assert.equal(cursorPosition.line, position.getRight().line,
"cursor should be on the same line");
assert.equal(cursorPosition.character, position.getRight().character,
"cursor should be on start of put content");
});
});