forked from ab9rf/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
38 lines (32 loc) · 1.12 KB
/
Copy pathcore.lua
File metadata and controls
38 lines (32 loc) · 1.12 KB
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
local function clean_path(p)
-- todo: replace with dfhack.filesystem call?
return p:gsub('\\', '/'):gsub('//', '/'):gsub('/$', '')
end
local fs = dfhack.filesystem
local old_cwd = clean_path(fs.getcwd())
local function restore_cwd()
fs.chdir(old_cwd)
end
function test.getDFPath()
expect.eq(clean_path(dfhack.getDFPath()), old_cwd)
end
function test.get_initial_cwd()
expect.eq(clean_path(dfhack.filesystem.get_initial_cwd()), clean_path(dfhack.getDFPath()))
end
function test.getDFPath_chdir()
dfhack.with_finalize(restore_cwd, function()
fs.chdir('data')
expect.eq(clean_path(dfhack.getDFPath()), old_cwd)
expect.ne(clean_path(dfhack.getDFPath()), clean_path(fs.getcwd()))
end)
end
function test.getHackPath()
expect.eq(clean_path(dfhack.getHackPath()), clean_path(dfhack.getDFPath() .. '/hack/'))
end
function test.getHackPath_chdir()
dfhack.with_finalize(restore_cwd, function()
fs.chdir('hack')
expect.eq(clean_path(dfhack.getHackPath()), clean_path(old_cwd .. '/hack/'))
expect.eq(clean_path(dfhack.getHackPath()), clean_path(fs.getcwd()))
end)
end