Skip to content

Commit

Permalink
a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon McLean committed Sep 3, 2024
1 parent dc6be31 commit 1a6d9fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
16 changes: 9 additions & 7 deletions tests/tests.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
local assert = require 'luassert'
local u = require 'tests.utils'
local test_runner = require 'tests.test_runner'
local run_tests = test_runner.run_tests
local test = test_runner.test
local api = vim.api

local function open_triptych(callback)
local cwd = vim.fn.getcwd()
local opening_dir = u.join_path(cwd, 'tests/test_playground/level_1/level_2/level_3')

u.open_triptych(opening_dir)
u.on_all_wins_updated(callback)
end

test_runner.run_tests {
local function close_triptych(callback)
u.on_event('TriptychDidClose', callback)
u.press_key 'q'
end

run_tests {
test('when opened - populates windows with files and folders', function(done)
local expected_lines = {
child = { 'level_5/', 'level_4_file_1.lua' },
Expand All @@ -30,13 +34,12 @@ test_runner.run_tests {

open_triptych(function()
result = u.get_state()
u.on_event('TriptychDidClose', function()
close_triptych(function()
done(function()
assert.same(expected_lines, result.lines)
assert.same(expected_winbars, result.winbars)
end)
end)
u.press_key 'q'
end)
end),

Expand All @@ -58,13 +61,12 @@ test_runner.run_tests {
u.press_key 'l'
u.on_all_wins_updated(function()
local result = u.get_state()
u.on_event('TriptychDidClose', function()
close_triptych(function()
done(function()
assert.same(expected_lines, result.lines)
assert.same(expected_winbars, result.winbars)
end)
end)
u.press_key 'q'
end)
end)
end),
Expand Down
22 changes: 0 additions & 22 deletions tests/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ function M.join_path(...)
return table.concat({ ... }, '/')
end

---@param n integer
---@param callback function
function M.wait_ticks(n, callback)
local function tick()
if n == 0 then
callback()
else
n = n - 1
vim.schedule(tick)
end
end
tick()
end

function M.get_lines(buf)
return vim.api.nvim_buf_get_lines(buf, 0, -1, false)
end
Expand Down Expand Up @@ -126,14 +112,6 @@ function M.get_state()
}
end

function M.await(fn)
local co = coroutine.running()
fn(function()
coroutine.resume(co)
end)
return coroutine.yield
end

function M.press_key(k)
local input_parsed = api.nvim_replace_termcodes(k, true, true, true)
api.nvim_feedkeys(input_parsed, 'normal', false)
Expand Down

0 comments on commit 1a6d9fb

Please sign in to comment.