Skip to content

Commit

Permalink
Merge pull request #26 from tsukimizake/main
Browse files Browse the repository at this point in the history
assertAiderBufferString
  • Loading branch information
nekowasabi authored Oct 12, 2024
2 parents 1bba75a + b5b617e commit 71de448
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
14 changes: 3 additions & 11 deletions denops/aider/mockAiderCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,11 @@ export const commands: AiderCommand = {
await denops.cmd("b#"); // hide buffer
},

sendPrompt: async (
denops: Denops,
_jobId: number,
prompt: string,
): Promise<undefined> => {
await fn.feedkeys(denops, `input: ${prompt}\n`);
sendPrompt: async (denops: Denops, _jobId: number, prompt: string): Promise<undefined> => {
await fn.feedkeys(denops, `ainput: ${prompt}\n`, "x");
},

exit: async (
denops: Denops,
_jobId: number,
_bufnr: number,
): Promise<undefined> => {
exit: async (denops: Denops, _jobId: number, _bufnr: number): Promise<undefined> => {
if (mockAiderBufnr === undefined) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion tests/aider_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This comment for vim-test plugin: Use denops' test() instead of built-in Deno.test()
import { sleep } from "./assertions.ts";
import { assertAiderBufferString, sleep } from "./assertions.ts";
import { assertAiderBufferAlive } from "./assertions.ts";
import { test } from "./testRunner.ts";

Expand All @@ -19,10 +19,12 @@ test("floating", "AiderAddCurrentFile should work", async (denops) => {
await denops.cmd("AiderAddCurrentFile");
await sleep(10);
await assertAiderBufferAlive(denops);
await assertAiderBufferString(denops, "input: /add \n");
});

test("vsplit", "AiderAddCurrentFile should work", async (denops) => {
await denops.cmd("AiderAddCurrentFile");
await sleep(10);
await assertAiderBufferAlive(denops);
await assertAiderBufferString(denops, ""); // "Run Command again." messgae is shown
});
12 changes: 10 additions & 2 deletions tests/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { assert } from "https://deno.land/std@0.217.0/assert/assert.ts";
import { ensure, is } from "https://deno.land/x/unknownutil@v3.17.0/mod.ts";
import type { Denops } from "https://deno.land/x/denops_std@v6.4.0/mod.ts";
import * as buffer from "../denops/aider/bufferOperation.ts";

export const sleep = (msec: number) =>
new Promise((resolve) => setTimeout(resolve, msec));
export const sleep = (msec: number) => new Promise((resolve) => setTimeout(resolve, msec));

/**
* Aiderバッファが開かれており、ウィンドウに表示されているかをアサートします
Expand Down Expand Up @@ -32,3 +32,11 @@ export async function assertAiderBufferAlive(denops: Denops): Promise<void> {
const buf = await buffer.getAiderBuffer(denops);
assert(buf !== undefined);
}

export async function assertAiderBufferString(denops: Denops, expected: string): Promise<void> {
const buf = await buffer.getAiderBuffer(denops);
assert(buf !== undefined);
const lines = ensure(await denops.call("getbufline", buf.bufnr, 1, "$"), is.ArrayOf(is.String));
const actual = lines.join("\n");
assert(actual === expected, `Buffer content mismatch.\nExpected:\n${expected}\nActual:\n${actual}`);
}

0 comments on commit 71de448

Please sign in to comment.