-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some unit tests for the
{cwd}
module.
To run them: set CLINK_PATH=c:\repos\flexprompt;c:\repos\flexprompt\tests The tests will automatically run. Yes, it's cheesy. But it's very lightweight and simple for me to use. Using a more sophisticated test system would not be cost effective for me at this time.
- Loading branch information
1 parent
0446158
commit e76c8b1
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
local uht = flexprompt.settings.use_home_tilde | ||
|
||
local test_cwd = "c:\\Users\\chrisant\\source\\repos\\win32-darkmode\\win32-darkmode\\x64" | ||
local test_git_dir = "c:\\Users\\chrisant\\source\\repos\\win32-darkmode\\.git" | ||
|
||
local full = "\x01c:\\Users\\chrisant\\source\\repos\\\x02win32-darkmode\\win32-darkmode\\x64" | ||
local short_all = "\x01c:\\U\\c\\s\\r\\\x02w\\w\\x64" | ||
local short_rootsmart = "\x01c:\\U\\c\\s\\r\\\x02win32-darkmode\\win32-darkmode\\x64" | ||
|
||
local tests = | ||
{ | ||
-- git colors | ||
{ false, false, "cwd", full }, | ||
{ false, false, "cwd:t=full:", full }, | ||
{ false, false, "cwd:t=smart:", full }, | ||
{ false, false, "cwd:s:", short_all }, | ||
{ false, false, "cwd:s=rootsmart:", short_all }, | ||
{ false, false, "cwd:s:t=full:", short_all }, | ||
{ false, false, "cwd:s=rootsmart:t=full:", short_all }, | ||
{ false, false, "cwd:t=folder:", "x64" }, | ||
{ false, false, "cwd:s:t=folder:", "x64" }, | ||
-- git | ||
{ true, true, "cwd", full }, | ||
{ true, false, "cwd:t=full:", full }, | ||
{ true, false, "cwd:t=smart:", "win32-darkmode\\win32-darkmode\\x64" }, | ||
{ true, true, "cwd:s:", short_all }, | ||
{ true, true, "cwd:s=rootsmart:", short_rootsmart }, | ||
{ true, false, "cwd:s:t=full:", short_all }, | ||
{ true, false, "cwd:s=rootsmart:t=full:", short_all }, | ||
{ true, false, "cwd:t=folder:", "x64" }, | ||
{ true, false, "cwd:s:t=folder:", "x64" }, | ||
} | ||
|
||
print("-- CWD MODULE TESTS ----------------------------------------------------") | ||
|
||
local i = 0 | ||
for _,e in ipairs(tests) do | ||
i = i + 1 | ||
for t = 1,2 do | ||
flexprompt.settings.use_home_tilde = (t > 1) | ||
|
||
local cwd = test_cwd | ||
local git_dir = e[1] and test_git_dir or false | ||
|
||
local r = _flexprompt_test_process_cwd_string(cwd, git_dir, e[3]) | ||
local num = tostring(i) | ||
local name = e[3] | ||
|
||
local x = e[4] | ||
if not e[2] then | ||
x = x:gsub("\x01", ""):gsub("\x02", "") | ||
end | ||
if (t > 1) then | ||
x = x:gsub("c:\\Users\\chrisant", "~"):gsub("c:\\U\\c", "~") | ||
num = num.."~" | ||
end | ||
|
||
if r == x then | ||
clink.print(num, "\x1b[32mok\x1b[m", name) | ||
else | ||
clink.print(num, "\x1b[31mFAIL\x1b[m", name) | ||
clink.print("", "", "\x1b[36mexpected:\x1b[m "..x) | ||
clink.print("", "", "\x1b[33m actual:\x1b[m "..r) | ||
end | ||
end | ||
end | ||
|
||
print("------------------------------------------------------------------------") | ||
|
||
flexprompt.settings.use_home_tilde = uht | ||
|
||
print() | ||
print() | ||
print() | ||
|