Add search command

This commit is contained in:
The Magician 2023-12-08 17:29:26 +00:00
parent ab5425d59d
commit 542095a49b
3 changed files with 42 additions and 14 deletions

View File

@ -5,11 +5,28 @@ setup() {
}
test_get_command_returns_list_for_substring() {
commands="list new"
expected="list"
for arg in l li lis list; do
result="$(get_command "$commands" "$arg")"
result="$(get_command "$ZKCOMMANDS" "$arg")"
assert_equals "$expected" "$result"
done
}
test_get_command_returns_search_for_substring() {
expected="search"
for arg in s se sea sear searc search; do
result="$(get_command "$ZKCOMMANDS" "$arg")"
assert_equals "$expected" "$result"
done
}
test_get_command_returns_new_for_substring() {
expected="new"
for arg in n ne new; do
result="$(get_command "$ZKCOMMANDS" "$arg")"
assert_equals "$expected" "$result"
done
}

View File

@ -4,9 +4,29 @@ setup() {
source ../zk
}
test_main_calls_list_when_list_command_passed() {
expected="_zk_list"
fake get_command 'echo list'
fake _zk_list "echo $expected"
result="$(main)"
assert_equals "$expected" "$result"
}
test_main_calls_search_when_search_command_passed() {
expected="_zk_search"
fake get_command 'echo search'
fake _zk_search "echo $expected"
result="$(main)"
assert_equals "$expected" "$result"
}
test_main_calls_new_when_new_command_passed() {
expected="_zk_new"
fake get_commands 'echo new'
fake get_command 'echo new'
fake _zk_new "echo $expected"
result="$(main)"
@ -14,12 +34,3 @@ test_main_calls_new_when_new_command_passed() {
assert_equals "$expected" "$result"
}
test_main_calls_list_when_list_command_passed() {
expected="_zk_list"
fake get_commands 'echo list'
fake _zk_list "echo $expected"
result="$(main)"
assert_equals "$expected" "$result"
}

4
zk
View File

@ -1,7 +1,7 @@
#!/bin/sh
ZKDIR="$HOME/.local/share/zk/"
COMMANDS='list new'
ZKCOMMANDS='list search new'
get_command() {
commands="$1"
@ -36,7 +36,7 @@ _zk_new() {
}
main() {
subcommand="$(get_commands "$COMMANDS" "$1")"
subcommand="$(get_command "$ZKCOMMANDS" "$1")"
_zk_"$subcommand"
}