Skip to content

Commit 6ebcfd4

Browse files
committed
test(replay): also check actions
1 parent d0f2c8e commit 6ebcfd4

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

tests/helpers.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@ function M.normalize_namespace_ids(extmarks)
247247
end
248248

249249
function M.capture_output(output_buf, namespace)
250+
local renderer = require('opencode.ui.renderer')
250251
return {
251252
lines = vim.api.nvim_buf_get_lines(output_buf, 0, -1, false) or {},
252253
extmarks = vim.api.nvim_buf_get_extmarks(output_buf, namespace, 0, -1, { details = true }) or {},
254+
actions = vim.deepcopy(renderer._actions),
253255
}
254256
end
255257

tests/manual/renderer_replay.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ function M.save_output(filename)
200200
local snapshot = {
201201
lines = lines,
202202
extmarks = M.normalize_namespace_ids(extmarks),
203+
actions = vim.deepcopy(renderer._actions),
203204
timestamp = os.time(),
204205
}
205206

tests/unit/renderer_spec.lua

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local output_window = require('opencode.ui.output_window')
66
local function assert_output_matches(expected, actual)
77
local normalized_extmarks = helpers.normalize_namespace_ids(actual.extmarks)
88

9-
assert.equal(
9+
assert.are.equal(
1010
#expected.lines,
1111
#actual.lines,
1212
string.format(
@@ -20,7 +20,7 @@ local function assert_output_matches(expected, actual)
2020
)
2121

2222
for i = 1, #expected.lines do
23-
assert.equal(
23+
assert.are.equal(
2424
expected.lines[i],
2525
actual.lines[i],
2626
string.format(
@@ -32,7 +32,7 @@ local function assert_output_matches(expected, actual)
3232
)
3333
end
3434

35-
assert.equal(
35+
assert.are.equal(
3636
#expected.extmarks,
3737
#normalized_extmarks,
3838
string.format(
@@ -46,7 +46,7 @@ local function assert_output_matches(expected, actual)
4646
)
4747

4848
for i = 1, #expected.extmarks do
49-
assert.same(
49+
assert.are.same(
5050
expected.extmarks[i],
5151
normalized_extmarks[i],
5252
string.format(
@@ -57,6 +57,30 @@ local function assert_output_matches(expected, actual)
5757
)
5858
)
5959
end
60+
61+
local expected_action_count = expected.actions and #expected.actions or 0
62+
local actual_action_count = actual.actions and #actual.actions or 0
63+
64+
assert.are.equal(
65+
expected_action_count,
66+
actual_action_count,
67+
string.format('Action count mismatch: expected %d, got %d', expected_action_count, actual_action_count)
68+
)
69+
70+
if expected.actions then
71+
for i = 1, #expected.actions do
72+
assert.are.same(
73+
expected.actions[i],
74+
actual.actions[i],
75+
string.format(
76+
'Action %d mismatch:\n Expected: %s\n Actual: %s',
77+
i,
78+
vim.inspect(expected.actions[i]),
79+
vim.inspect(actual.actions[i])
80+
)
81+
)
82+
end
83+
end
6084
end
6185

6286
describe('renderer', function()

0 commit comments

Comments
 (0)