From 3b574efbf698da6577de75e171aee38161a5fb4a Mon Sep 17 00:00:00 2001 From: Oleksandr Smirnov Date: Fri, 21 Mar 2025 22:02:50 +0200 Subject: [PATCH] test: add utils --- spec/unit/utils_test.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/unit/utils_test.lua diff --git a/spec/unit/utils_test.lua b/spec/unit/utils_test.lua new file mode 100644 index 0000000..7001261 --- /dev/null +++ b/spec/unit/utils_test.lua @@ -0,0 +1,29 @@ +local t = require "spec.testutils" +local child = MiniTest.new_child_neovim() +local T = MiniTest.new_set { + hooks = { + post_once = child.stop, + pre_case = function() + child.restart { "-u", t.mininit_path } + end, + }, +} + +T["utils"] = MiniTest.new_set() +T["utils"]["should .remove_empty_lines()"] = function() + local u = require "gopher._utils" + local inp = { "hi", "", "a", "", "", "asdf" } + + t.eq(u.remove_empty_lines(inp), { "hi", "a", "asdf" }) +end + +T["utils"]["should .readfile_joined()"] = function() + local data = "line1\nline2\nline3" + local tmp = t.tmpfile() + local u = require "gopher._utils" + + t.writefile(tmp, data) + t.eq(u.readfile_joined(tmp), data) +end + +return T