mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-12-27 22:43:41 +08:00
Fix default suggestion strategy and add testing
This commit is contained in:
parent
83f78d0760
commit
976acc708c
8
Makefile
8
Makefile
|
@ -24,6 +24,9 @@ ALL_TARGETS := \
|
|||
$(PLUGIN_TARGET) \
|
||||
$(OH_MY_ZSH_LINK_TARGET)
|
||||
|
||||
TEST_FILES := \
|
||||
$(SCRIPT_DIR)/test*.zsh
|
||||
|
||||
all: $(ALL_TARGETS)
|
||||
|
||||
$(PLUGIN_TARGET): $(HEADER_FILES) $(SRC_FILES)
|
||||
|
@ -39,4 +42,7 @@ clean:
|
|||
|
||||
.PHONY: test
|
||||
test: all
|
||||
$(SCRIPT_DIR)/test.zsh
|
||||
@for test_file in $(TEST_FILES); do \
|
||||
echo "\nRunning $$test_file"; \
|
||||
$$test_file; \
|
||||
done
|
||||
|
|
80
script/test-strategy-default.zsh
Executable file
80
script/test-strategy-default.zsh
Executable file
|
@ -0,0 +1,80 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
TEST_DIR=$SCRIPT_DIR/../test
|
||||
DIST_DIR=$SCRIPT_DIR/../
|
||||
|
||||
source $TEST_DIR/stub-1.0.2.sh
|
||||
|
||||
source $DIST_DIR/zsh-autosuggestions.zsh
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Default Suggestions Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
TMPHIST_FILE=/tmp/zsh-autosuggestions-test-tmp-hist
|
||||
|
||||
# Use stub.sh for stubbing/mocking
|
||||
HISTSIZE=0 # Clear history
|
||||
HISTSIZE=100
|
||||
|
||||
cat > $TMPHIST_FILE <<-EOH
|
||||
one
|
||||
two
|
||||
three
|
||||
four
|
||||
five
|
||||
six
|
||||
seven
|
||||
eight
|
||||
nine
|
||||
ten
|
||||
eleven
|
||||
EOH
|
||||
echo >> $TMPHIST_FILE
|
||||
|
||||
fc -R $TMPHIST_FILE
|
||||
|
||||
rm $TMPHIST_FILE
|
||||
|
||||
ZSH_AUTOSUGGEST_STRATEGY=default
|
||||
|
||||
testNoMatch() {
|
||||
assertEquals \
|
||||
"Did not pick correct suggestion for prefix 'garbage'" \
|
||||
"" \
|
||||
"$(_zsh_autosuggest_suggestion garbage)"
|
||||
}
|
||||
|
||||
testMatch() {
|
||||
assertEquals \
|
||||
"Did not pick correct suggestion for prefix 'o'" \
|
||||
"one" \
|
||||
"$(_zsh_autosuggest_suggestion o)"
|
||||
|
||||
assertEquals \
|
||||
"Did not pick correct suggestion for prefix 't'" \
|
||||
"ten" \
|
||||
"$(_zsh_autosuggest_suggestion t)"
|
||||
|
||||
assertEquals \
|
||||
"Did not pick correct suggestion for prefix 'tw'" \
|
||||
"two" \
|
||||
"$(_zsh_autosuggest_suggestion tw)"
|
||||
|
||||
assertEquals \
|
||||
"Did not pick correct suggestion for prefix 'f'" \
|
||||
"five" \
|
||||
"$(_zsh_autosuggest_suggestion f)"
|
||||
|
||||
assertEquals \
|
||||
"Did not pick correct suggestion for prefix 'fo'" \
|
||||
"four" \
|
||||
"$(_zsh_autosuggest_suggestion fo)"
|
||||
}
|
||||
|
||||
setopt shwordsplit
|
||||
SHUNIT_PARENT=$0
|
||||
|
||||
source $TEST_DIR/shunit2-2.1.6/src/shunit2
|
||||
|
|
@ -10,7 +10,7 @@ _zsh_autosuggest_strategy_default() {
|
|||
local prefix="$(_zsh_autosuggest_escape_command_prefix "$1")"
|
||||
|
||||
# Get the hist number of the most recent history item that matches
|
||||
local histkey="${${(k)history[(R)$prefix*]}[1]}"
|
||||
local histkey="${${(@k)history[(R)$prefix*]}[1]}"
|
||||
|
||||
# Echo the history entry
|
||||
echo -E "${history[$histkey]}"
|
||||
|
|
|
@ -341,7 +341,7 @@ _zsh_autosuggest_strategy_default() {
|
|||
local prefix="$(_zsh_autosuggest_escape_command_prefix "$1")"
|
||||
|
||||
# Get the hist number of the most recent history item that matches
|
||||
local histkey="${${(k)history[(R)$prefix*]}[1]}"
|
||||
local histkey="${${(@k)history[(R)$prefix*]}[1]}"
|
||||
|
||||
# Echo the history entry
|
||||
echo -E "${history[$histkey]}"
|
||||
|
|
Loading…
Reference in New Issue
Block a user