2023-03-20 14:57:28 +01:00
|
|
|
use std.nu "assert length"
|
|
|
|
use std.nu "assert equal"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-03-18 15:23:41 +01:00
|
|
|
def clean [path: path] {
|
|
|
|
cd $path
|
|
|
|
cd ..
|
|
|
|
rm -r $path
|
2023-03-16 19:23:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export def test_dirs_command [] {
|
|
|
|
# need some directories to play with
|
|
|
|
let base_path = (($nu.temp-path) | path join $"test_dirs_(random uuid)" | path expand )
|
2023-03-22 09:50:01 +01:00
|
|
|
let path_a = ($base_path | path expand | path join "a")
|
|
|
|
let path_b = ($base_path | path expand | path join "b")
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
try {
|
2023-03-22 09:50:01 +01:00
|
|
|
mkdir ($base_path | path expand) $path_a $path_b
|
|
|
|
cd ($base_path | path expand)
|
2023-03-17 18:30:35 +01:00
|
|
|
use std.nu "dirs next"
|
|
|
|
use std.nu "dirs prev"
|
|
|
|
use std.nu "dirs add"
|
|
|
|
use std.nu "dirs drop"
|
|
|
|
use std.nu "dirs show"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-03-20 14:57:28 +01:00
|
|
|
assert length $env.DIRS_LIST 1 "list is just pwd after initialization"
|
2023-03-22 09:50:01 +01:00
|
|
|
assert equal ($base_path | path expand) $env.DIRS_LIST.0 "list is just pwd after initialization"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
dirs next
|
2023-03-22 09:50:01 +01:00
|
|
|
assert equal ($base_path | path expand) $env.DIRS_LIST.0 "next wraps at end of list"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
dirs prev
|
2023-03-22 09:50:01 +01:00
|
|
|
assert equal ($base_path | path expand) $env.DIRS_LIST.0 "prev wraps at top of list"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
dirs add $path_b $path_a
|
2023-03-20 14:57:28 +01:00
|
|
|
assert equal $path_b $env.PWD "add changes PWD to first added dir"
|
|
|
|
assert length $env.DIRS_LIST 3 "add in fact adds to list"
|
|
|
|
assert equal $path_a $env.DIRS_LIST.2 "add in fact adds to list"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
dirs next 2
|
2023-03-22 09:50:01 +01:00
|
|
|
assert equal ($base_path | path expand) $env.PWD "next wraps at end of list"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
dirs prev 1
|
2023-03-20 14:57:28 +01:00
|
|
|
assert equal $path_a $env.PWD "prev wraps at start of list"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
dirs drop
|
2023-03-20 14:57:28 +01:00
|
|
|
assert length $env.DIRS_LIST 2 "drop removes from list"
|
2023-03-22 09:50:01 +01:00
|
|
|
assert equal ($base_path | path expand) $env.PWD "drop changes PWD to next in list (after dropped element)"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-03-22 09:50:01 +01:00
|
|
|
assert equal (dirs show) [[active path]; [true ($base_path | path expand)] [false $path_b]] "show table contains expected information"
|
2023-03-16 19:23:29 +01:00
|
|
|
} catch { |error|
|
2023-03-22 09:50:01 +01:00
|
|
|
clean ($base_path | path expand)
|
2023-03-18 15:23:41 +01:00
|
|
|
|
|
|
|
let error = (
|
|
|
|
$error
|
|
|
|
| get debug
|
|
|
|
| str replace "{" "("
|
|
|
|
| str replace "}" ")"
|
|
|
|
| parse 'GenericError("{msg}", "{text}", Some(Span ( start: {start}, end: {end} )), {rest})'
|
|
|
|
| reject rest
|
|
|
|
| get 0
|
|
|
|
)
|
|
|
|
error make {
|
|
|
|
msg: $error.msg
|
|
|
|
label: {
|
|
|
|
text: $error.text
|
|
|
|
start: ($error.start | into int)
|
|
|
|
end: ($error.end | into int)
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:23:29 +01:00
|
|
|
}
|
|
|
|
|
2023-03-22 09:50:01 +01:00
|
|
|
try { clean ($base_path | path expand) }
|
2023-03-17 18:30:35 +01:00
|
|
|
}
|