From f87f3ea322b1111e1929d149224ff736c8390db3 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Sun, 27 Aug 2023 18:15:04 -0700 Subject: test: add a test suite --- tests/test_util.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test_util.lua (limited to 'tests/test_util.lua') diff --git a/tests/test_util.lua b/tests/test_util.lua new file mode 100644 index 0000000..a225aec --- /dev/null +++ b/tests/test_util.lua @@ -0,0 +1,34 @@ +require("plenary.async").tests.add_to_env() +local conform = require("conform") +local M = {} + +local OUTPUT_FILE = "tests/fake_formatter_output" + +M.reset_editor = function() + vim.cmd.tabonly({ mods = { silent = true } }) + for i, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do + if i > 1 then + vim.api.nvim_win_close(winid, true) + end + end + vim.api.nvim_win_set_buf(0, vim.api.nvim_create_buf(false, true)) + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do + vim.api.nvim_buf_delete(bufnr, { force = true }) + end + conform.formatters = {} + conform.formatters_by_ft = {} + pcall(vim.api.nvim_del_augroup_by_name, "Conform") + if vim.fn.filereadable(OUTPUT_FILE) == 1 then + vim.fn.delete(OUTPUT_FILE) + end +end + +---@param lines string[] +M.set_formatter_output = function(lines) + local content = table.concat(lines, "\n") + local fd = assert(vim.loop.fs_open(OUTPUT_FILE, "w", 420)) -- 0644 + vim.loop.fs_write(fd, content) + vim.loop.fs_close(fd) +end + +return M -- cgit v1.2.3-70-g09d2