aboutsummaryrefslogtreecommitdiffhomepage
path: root/.config/nvim/lua/tests/uniquify.lua
blob: 46f7ff83745220e68bc1eb4b1cb1949e0c426ba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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'}},
      {'foo.txt',         'bar/foo.txt',         {'bar/foo.txt'}},
      {'foo.txt',         'bar/foo.txt',         {'bar/foo.txt', 'bar/foo.txt'}},
      {'bar/foo.txt',     'bar/foo.txt',         {'foo.txt'}},
      {'bar/foo.txt',     'bar/foo.txt',         {'baz/foo.txt'}},
      {'bar/foo.txt',     'qux/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',     {'qux/bar/baz.txt'}},
      {'foo/b/baz.txt',   'foo/bar/baz.txt',     {'fiz/foo/bar/baz.txt', 'qux/bar/baz.txt'}},
      {'fiz/f/b/baz.txt', 'fiz/foo/bar/baz.txt', {'foo/bar/baz.txt'}},
      {'foo.txt',         'bar/foo.txt',         {'bar/foo.txt'}},
      {'bar/foo.txt',     'fiz/bar/foo.txt',     {'bar/baz.txt', 'qux/foo.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