From 2e29201579e5dec9e13bedf642d8221bfc993ae9 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 20 Feb 2022 15:42:46 +0900 Subject: neovim: add test code for uniquify --- .config/nvim/lua/tests/uniquify.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .config/nvim/lua/tests/uniquify.lua (limited to '.config/nvim/lua/tests/uniquify.lua') 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 -- cgit v1.2.3-70-g09d2