|
| 1 | +import * as assert from "assert"; |
| 2 | +import * as vscode from "vscode"; |
| 3 | +import * as sinon from "sinon"; |
| 4 | +import { getCursorlessApi } from "../../util/getExtensionApi"; |
| 5 | +import HatTokenMap from "../../core/HatTokenMap"; |
| 6 | + |
| 7 | +suite("Group by document", async function () { |
| 8 | + this.timeout("100s"); |
| 9 | + this.retries(3); |
| 10 | + |
| 11 | + teardown(() => { |
| 12 | + sinon.restore(); |
| 13 | + }); |
| 14 | + |
| 15 | + test("Group by document", runTest); |
| 16 | +}); |
| 17 | + |
| 18 | +async function runTest() { |
| 19 | + const graph = (await getCursorlessApi()).graph!; |
| 20 | + |
| 21 | + await vscode.commands.executeCommand("workbench.action.closeAllEditors"); |
| 22 | + |
| 23 | + const document = await vscode.workspace.openTextDocument({ |
| 24 | + language: "plaintext", |
| 25 | + content: "hello world", |
| 26 | + }); |
| 27 | + |
| 28 | + const editor1 = await vscode.window.showTextDocument(document); |
| 29 | + const editor2 = await vscode.window.showTextDocument( |
| 30 | + document, |
| 31 | + vscode.ViewColumn.Beside |
| 32 | + ); |
| 33 | + |
| 34 | + await graph.hatTokenMap.addDecorations(); |
| 35 | + const hatMap = await graph.hatTokenMap.getReadableMap(false); |
| 36 | + |
| 37 | + const hat1 = hatMap |
| 38 | + .getEntries() |
| 39 | + .find(([, token]) => token.editor === editor1 && token.text === "hello"); |
| 40 | + const hat2 = hatMap |
| 41 | + .getEntries() |
| 42 | + .find(([, token]) => token.editor === editor2 && token.text === "world"); |
| 43 | + |
| 44 | + const { hatStyle: hatStyle1, character: char1 } = HatTokenMap.splitKey( |
| 45 | + hat1![0] |
| 46 | + ); |
| 47 | + const { hatStyle: hatStyle2, character: char2 } = HatTokenMap.splitKey( |
| 48 | + hat2![0] |
| 49 | + ); |
| 50 | + |
| 51 | + await vscode.commands.executeCommand( |
| 52 | + "cursorless.command", |
| 53 | + "swap each with whale", |
| 54 | + "swapTargets", |
| 55 | + [ |
| 56 | + { |
| 57 | + type: "primitive", |
| 58 | + mark: { |
| 59 | + type: "decoratedSymbol", |
| 60 | + symbolColor: hatStyle1, |
| 61 | + character: char1, |
| 62 | + }, |
| 63 | + }, |
| 64 | + { |
| 65 | + type: "primitive", |
| 66 | + mark: { |
| 67 | + type: "decoratedSymbol", |
| 68 | + symbolColor: hatStyle2, |
| 69 | + character: char2, |
| 70 | + }, |
| 71 | + }, |
| 72 | + ] |
| 73 | + ); |
| 74 | + |
| 75 | + assert.deepStrictEqual(document.getText(), "world hello"); |
| 76 | +} |
0 commit comments