Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for visible ranges(scroll, fold) #539

Merged
merged 5 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/test/suite/fold.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as assert from "assert";
import * as vscode from "vscode";
import * as sinon from "sinon";
import { getCursorlessApi } from "../../util/getExtensionApi";
import { openNewEditor } from "../openNewEditor";

suite("fold", async function () {
this.timeout("100s");
this.retries(3);

teardown(() => {
sinon.restore();
});

test("fold made", foldMade);
test("unfold made", unfoldMade);
});

async function foldMade() {
const graph = (await getCursorlessApi()).graph!;
const editor = await openNewEditor("function myFunk() {\n\n}", "typescript");

await vscode.commands.executeCommand(
"cursorless.command",
"fold made",
"fold",
[
{
type: "primitive",
mark: {
type: "cursor",
},
},
]
);

assert.equal(editor.visibleRanges.length, 2);
assert.equal(editor.visibleRanges[0].start.line, 0);
assert.equal(editor.visibleRanges[0].end.line, 0);
assert.equal(editor.visibleRanges[1].start.line, 2);
assert.equal(editor.visibleRanges[1].start.line, 2);
}

async function unfoldMade() {
const graph = (await getCursorlessApi()).graph!;
const editor = await openNewEditor("function myFunk() {\n\n}", "typescript");
await vscode.commands.executeCommand("editor.fold", {
selectionLines: [0],
});

assert.equal(editor.visibleRanges.length, 2);

await vscode.commands.executeCommand(
"cursorless.command",
"unfold made",
"unfold",
[
{
type: "primitive",
mark: {
type: "cursor",
},
},
]
);

assert.equal(editor.visibleRanges.length, 1);
}
69 changes: 69 additions & 0 deletions src/test/suite/scroll.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as assert from "assert";
import * as vscode from "vscode";
import * as sinon from "sinon";
import { getCursorlessApi } from "../../util/getExtensionApi";
import { openNewEditor } from "../openNewEditor";

suite("scroll", async function () {
this.timeout("100s");
this.retries(3);

teardown(() => {
sinon.restore();
});

test("top whale", topWhale);
test("bottom whale", bottomWhale);
});

async function topWhale() {
const graph = (await getCursorlessApi()).graph!;
const editor = await openNewEditor("hello\nworld");
editor.selections = [new vscode.Selection(1, 0, 1, 0)];

await vscode.commands.executeCommand(
"cursorless.command",
"crown whale",
"scrollToTop",
[
{
type: "primitive",
mark: {
type: "cursor",
},
},
]
);

assert.equal(editor.visibleRanges.length, 1);
assert.equal(editor.visibleRanges[0].start.line, 1);
}

async function bottomWhale() {
const graph = (await getCursorlessApi()).graph!;
const editor = await openNewEditor("hello\nworld");
await vscode.commands.executeCommand("revealLine", {
lineNumber: 1,
at: "top",
});
editor.selections = [new vscode.Selection(1, 0, 1, 0)];

assert.equal(editor.visibleRanges[0].start.line, 1);

await vscode.commands.executeCommand(
"cursorless.command",
"bottom whale",
"scrollToBottom",
[
{
type: "primitive",
mark: {
type: "cursor",
},
},
]
);

assert.equal(editor.visibleRanges.length, 1);
assert.equal(editor.visibleRanges[0].start.line, 0);
}