2023-04-08 14:35:16 +02:00
|
|
|
use std "assert length"
|
|
|
|
use std "assert equal"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
export def setup [] {
|
|
|
|
{base_path: ($nu.temp-path | path join $"test_dirs_(random uuid)")}
|
|
|
|
}
|
|
|
|
|
|
|
|
export def teardown [] {
|
|
|
|
let base_path = $in.base_path
|
|
|
|
cd $base_path
|
2023-03-18 15:23:41 +01:00
|
|
|
cd ..
|
2023-04-10 22:42:11 +02:00
|
|
|
rm -r $base_path
|
2023-03-16 19:23:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export def test_dirs_command [] {
|
|
|
|
# need some directories to play with
|
2023-04-10 22:42:11 +02:00
|
|
|
let base_path = $in.base_path
|
2023-03-23 13:08:01 +01:00
|
|
|
let path_a = ($base_path | path join "a")
|
|
|
|
let path_b = ($base_path | path join "b")
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
mkdir $base_path $path_a $path_b
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
cd $base_path
|
|
|
|
use std "dirs next"
|
|
|
|
use std "dirs prev"
|
|
|
|
use std "dirs add"
|
|
|
|
use std "dirs drop"
|
|
|
|
use std "dirs show"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
assert length $env.DIRS_LIST 1 "list is just pwd after initialization"
|
|
|
|
assert equal $base_path $env.DIRS_LIST.0 "list is just pwd after initialization"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
dirs next
|
|
|
|
assert equal $base_path $env.DIRS_LIST.0 "next wraps at end of list"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
dirs prev
|
|
|
|
assert equal $base_path $env.DIRS_LIST.0 "prev wraps at top of list"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
dirs add $path_b $path_a
|
|
|
|
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
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
dirs next 2
|
|
|
|
assert equal $base_path $env.PWD "next wraps at end of list"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
dirs prev 1
|
|
|
|
assert equal $path_a $env.PWD "prev wraps at start of list"
|
2023-03-18 15:23:41 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
dirs drop
|
|
|
|
assert length $env.DIRS_LIST 2 "drop removes from list"
|
|
|
|
assert equal $base_path $env.PWD "drop changes PWD to next in list (after dropped element)"
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-04-10 22:42:11 +02:00
|
|
|
assert equal (dirs show) [[active path]; [true $base_path] [false $path_b]] "show table contains expected information"
|
2023-03-17 18:30:35 +01:00
|
|
|
}
|