local passed = 0
local failed = 0
local function test(name, fn)
local ok, err = pcall(fn)
if ok then
passed = passed + 1
io.write(('[PASS] %s\n'):format(name))
else
failed = failed + 1
io.write(('[FAIL] %s: %s\n'):format(name, tostring(err)))
end
end
local function assert_eq(a, b, msg)
if a ~= b then
error((msg or 'assertion failed') .. ': expected ' .. tostring(b) .. ', got ' .. tostring(a))
end
end
local function assert_true(v, msg)
if not v then
error(msg or 'expected truthy value')
end
end
test('module loads', function()
local ok, m = pcall(require, 'splitrs')
assert_true(ok, 'require("splitrs") failed: ' .. tostring(m))
assert_eq(type(m), 'table', 'module should be a table')
end)
test('setup() merges config', function()
local splitrs = require('splitrs')
splitrs.setup({ enabled = false })
assert_eq(splitrs.config.enabled, false, 'enabled should be false after setup')
end)
test('default cmd is splitrs-lsp', function()
local splitrs = require('splitrs')
splitrs.setup({}) assert_true(type(splitrs.config.cmd) == 'table', 'cmd should be a table')
assert_eq(splitrs.config.cmd[1], 'splitrs-lsp', 'first cmd token should be splitrs-lsp')
end)
test('refactor_current_file is a function', function()
local splitrs = require('splitrs')
assert_eq(type(splitrs.refactor_current_file), 'function', 'refactor_current_file should be a function')
end)
test('_start_config_watch is a function', function()
local splitrs = require('splitrs')
assert_eq(type(splitrs._start_config_watch), 'function', '_start_config_watch should be a function')
end)
test('SplitrsRefactor command registered', function()
local splitrs = require('splitrs')
splitrs.setup({ enabled = false, register_commands = true })
local cmds = vim.api.nvim_get_commands({})
assert_true(cmds['SplitrsRefactor'] ~= nil, 'SplitrsRefactor command should be registered')
end)
io.write(('\n%d passed, %d failed\n'):format(passed, failed))
if failed > 0 then
vim.cmd('cq 1')
else
vim.cmd('qa!')
end