diff options
| -rw-r--r-- | .config/nvim/lua/tests/init.lua | 36 | ||||
| -rw-r--r-- | .config/nvim/lua/tests/uniquify.lua | 31 |
2 files changed, 67 insertions, 0 deletions
diff --git a/.config/nvim/lua/tests/init.lua b/.config/nvim/lua/tests/init.lua new file mode 100644 index 0000000..210ca0d --- /dev/null +++ b/.config/nvim/lua/tests/init.lua @@ -0,0 +1,36 @@ +-- lua require('tests').test(TEST_SUITE_NAME) + +local M = {} + + +local T = {} + +function T.new(suite_name) + local instance = {} + instance.suite_name = suite_name + instance._index = 1 + setmetatable(instance, {__index = T}) + return instance +end + +function T:assert(expr, message) + assert(expr, ('[tests.%s:%d] %s'):format(self.suite_name, self._index, message)) + self._index = self._index + 1 +end + +function T:assert_eq(expected, actual, message) + message = message or (tostring(expected) .. ' != ' .. tostring(actual)) + assert(expected == actual, ('[tests.%s:%d] %s'):format(self.suite_name, self._index, message)) + self._index = self._index + 1 +end + + +function M.test(suite_name) + assert(suite_name, '[tests.test] suite_name is required.') + + local suite = require('tests.' .. suite_name) + suite.test(T.new(suite_name)) +end + + +return M diff --git a/.config/nvim/lua/tests/uniquify.lua b/.config/nvim/lua/tests/uniquify.lua new file mode 100644 index 0000000..9f58298 --- /dev/null +++ b/.config/nvim/lua/tests/uniquify.lua @@ -0,0 +1,31 @@ +local M = {} + +local uniquify = require('uniquify').uniquify + + +function M.test(t) + local test_cases = { + -- expected, this_path, other_paths + {'foo.txt', 'foo.txt', {}}, + {'foo.txt', 'bar/foo.txt', {}}, + {'foo.txt', 'foo.txt', {'foo.txt'}}, + {'bar/foo.txt', 'bar/foo.txt', {'foo.txt'}}, + {'bar/foo.txt', 'bar/foo.txt', {'baz/foo.txt'}}, + {'foo.txt', 'bar/foo.txt', {'bar.txt', 'baz.txt'}}, + {'foo.txt', 'bar/foo.txt', {'bar.txt', 'baz.txt'}}, + {'baz.txt', 'foo/bar/baz.txt', {}}, + {'foo/b/baz.txt', 'foo/bar/baz.txt', {'spam/bar/baz.txt'}}, + {'foo/b/baz.txt', 'foo/bar/baz.txt', {'fiz/foo/bar/baz.txt', 'spam/bar/baz.txt'}}, + {'fiz/f/b/baz.txt', 'fiz/foo/bar/baz.txt', {'foo/bar/baz.txt'}}, + } + + for _, row in ipairs(test_cases) do + local expected = row[1] + local this_path = row[2] + local other_paths = row[3] + t:assert_eq(expected, uniquify(this_path, other_paths)) + end +end + + +return M |
