Skip to content

Commit e8d7a74

Browse files
committed
test: add edge case tests for output channel state, batch parsing, and search pattern
- setPatchloomLog/getPatchloomLog round-trip module state - parseBatchOperationCount rejects non-array operations values - buildSearchQuickAction preserves spaces in multi-word patterns Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent e451e03 commit e8d7a74

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

test/unit/batchApply.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ test("parseBatchOperationCount returns 0 for missing operations", () => {
4040
test("parseBatchOperationCount returns 0 for empty operations array", () => {
4141
assert.equal(parseBatchOperationCount('{"operations": []}'), 0);
4242
});
43+
44+
test("parseBatchOperationCount returns 0 when operations is not an array", () => {
45+
assert.equal(parseBatchOperationCount('{"operations": "not-an-array"}'), 0);
46+
assert.equal(parseBatchOperationCount('{"operations": 42}'), 0);
47+
assert.equal(parseBatchOperationCount('{"operations": null}'), 0);
48+
});

test/unit/outputChannel.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
3-
import { createPatchloomLog } from "../../src/logging/outputChannel.js";
3+
import { createPatchloomLog, getPatchloomLog, setPatchloomLog } from "../../src/logging/outputChannel.js";
44

55
test("createPatchloomLog lazily creates channel on first log call", () => {
66
let channelCreated = false;
@@ -103,6 +103,26 @@ test("dispose disposes channel and subsequent log creates a new one", () => {
103103
assert.equal(createCount, 2);
104104
});
105105

106+
test("setPatchloomLog and getPatchloomLog round-trip module state", () => {
107+
const original = getPatchloomLog();
108+
try {
109+
assert.equal(getPatchloomLog(), undefined);
110+
111+
const log = createPatchloomLog(() => ({
112+
appendLine() {},
113+
show() {},
114+
dispose() {}
115+
}));
116+
setPatchloomLog(log);
117+
assert.equal(getPatchloomLog(), log);
118+
119+
setPatchloomLog(undefined);
120+
assert.equal(getPatchloomLog(), undefined);
121+
} finally {
122+
setPatchloomLog(original);
123+
}
124+
});
125+
106126
test("logResult handles multiline stderr", () => {
107127
const lines: string[] = [];
108128
const log = createPatchloomLog(() => ({

test/unit/quickActions.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ test("buildCreateQuickAction builds a create command", () => {
144144
assert.deepEqual(action.targetArgIndices, [1]);
145145
});
146146

147+
test("buildSearchQuickAction preserves spaces in pattern as a single arg", () => {
148+
const action = buildSearchQuickAction("/workspace/demo", "hello world");
149+
150+
assert.deepEqual(action.args, ["search", "hello world", "/workspace/demo"]);
151+
});
152+
147153
test("buildDocGetQuickAction builds a doc get command", () => {
148154
const action = buildDocGetQuickAction("/workspace/demo/package.json", "scripts.test");
149155

0 commit comments

Comments
 (0)