forked from nvim-neo-tree/neo-tree.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_spec.lua
66 lines (56 loc) · 2.79 KB
/
path_spec.lua
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
pcall(require, "luacov")
local utils = require("neo-tree.utils")
describe("is_subpath", function()
local common_tests = function()
-- Relative paths
assert.are.same(true, utils.is_subpath("a", "a/subpath"))
assert.are.same(false, utils.is_subpath("a", "b/c"))
assert.are.same(false, utils.is_subpath("a", "b"))
end
it("should work with unix paths", function()
local old = utils.is_windows
utils.is_windows = false
common_tests()
assert.are.same(true, utils.is_subpath("/a", "/a/subpath"))
assert.are.same(false, utils.is_subpath("/a", "/b/c"))
-- Edge cases
assert.are.same(false, utils.is_subpath("", ""))
assert.are.same(true, utils.is_subpath("/", "/"))
-- Paths with trailing slashes
assert.are.same(true, utils.is_subpath("/a/", "/a/subpath"))
assert.are.same(true, utils.is_subpath("/a/", "/a/subpath/"))
assert.are.same(true, utils.is_subpath("/a", "/a/subpath"))
assert.are.same(true, utils.is_subpath("/a", "/a/subpath/"))
-- Paths with different casing
assert.are.same(true, utils.is_subpath("/TeSt", "/TeSt/subpath"))
assert.are.same(false, utils.is_subpath("/A", "/a/subpath"))
assert.are.same(false, utils.is_subpath("/A", "/a/subpath"))
utils.is_windows = old
end)
it("should work on windows paths", function()
local old = utils.is_windows
utils.is_windows = true
common_tests()
assert.are.same(true, utils.is_subpath("C:", "C:"))
assert.are.same(false, utils.is_subpath("C:", "D:"))
assert.are.same(true, utils.is_subpath("C:/A", [[C:\A]]))
-- Test Windows paths with backslashes
assert.are.same(true, utils.is_subpath([[C:\Users\user]], [[C:\Users\user\Documents]]))
assert.are.same(false, utils.is_subpath([[C:\Users\user]], [[D:\Users\user]]))
assert.are.same(false, utils.is_subpath([[C:\Users\user]], [[C:\Users\usera]]))
-- Test Windows paths with forward slashes
assert.are.same(true, utils.is_subpath("C:/Users/user", "C:/Users/user/Documents"))
assert.are.same(false, utils.is_subpath("C:/Users/user", "D:/Users/user"))
assert.are.same(false, utils.is_subpath("C:/Users/user", "C:/Users/usera"))
-- Test Windows paths with drive letters
assert.are.same(true, utils.is_subpath("C:", "C:/Users/user"))
assert.are.same(false, utils.is_subpath("C:", "D:/Users/user"))
-- Test Windows paths with UNC paths
assert.are.same(true, utils.is_subpath([[\\server\share]], [[\\server\share\folder]]))
assert.are.same(false, utils.is_subpath([[\\server\share]], [[\\server2\share]]))
-- Test Windows paths with trailing backslashes
assert.are.same(true, utils.is_subpath([[C:\Users\user\]], [[C:\Users\user\Documents]]))
assert.are.same(true, utils.is_subpath("C:/Users/user/", "C:/Users/user/Documents"))
utils.is_windows = old
end)
end)