2016-03-15 00:38:37 +01:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
|
|
|
source "${0:a:h}/../test_helper.zsh"
|
|
|
|
|
|
|
|
oneTimeSetUp() {
|
|
|
|
source_autosuggestions
|
|
|
|
}
|
|
|
|
|
2016-03-15 16:05:55 +01:00
|
|
|
setUp() {
|
2016-03-15 00:38:37 +01:00
|
|
|
BUFFER=''
|
|
|
|
POSTDISPLAY=''
|
2016-07-18 11:55:19 +02:00
|
|
|
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=''
|
2016-03-15 16:05:55 +01:00
|
|
|
}
|
2016-03-15 00:38:37 +01:00
|
|
|
|
2016-03-15 16:05:55 +01:00
|
|
|
tearDown() {
|
|
|
|
restore _zsh_autosuggest_invoke_original_widget
|
|
|
|
restore _zsh_autosuggest_suggestion
|
|
|
|
}
|
|
|
|
|
|
|
|
testModify() {
|
2016-03-15 00:38:37 +01:00
|
|
|
stub_and_eval \
|
|
|
|
_zsh_autosuggest_invoke_original_widget \
|
|
|
|
'BUFFER+="e"'
|
|
|
|
|
|
|
|
stub_and_echo \
|
|
|
|
_zsh_autosuggest_suggestion \
|
|
|
|
'echo hello'
|
|
|
|
|
|
|
|
_zsh_autosuggest_modify 'original-widget'
|
|
|
|
|
|
|
|
assertTrue \
|
|
|
|
'original widget not invoked' \
|
|
|
|
'stub_called _zsh_autosuggest_invoke_original_widget'
|
|
|
|
|
|
|
|
assertEquals \
|
|
|
|
'BUFFER was not modified' \
|
|
|
|
'e' \
|
|
|
|
"$BUFFER"
|
|
|
|
|
|
|
|
assertEquals \
|
|
|
|
'POSTDISPLAY does not contain suggestion' \
|
|
|
|
'cho hello' \
|
|
|
|
"$POSTDISPLAY"
|
2016-04-07 01:10:34 +02:00
|
|
|
}
|
|
|
|
|
2016-07-15 10:39:33 +02:00
|
|
|
testModifyBufferTooLarge() {
|
|
|
|
|
2016-07-18 11:55:19 +02:00
|
|
|
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE='20'
|
2016-07-15 10:39:33 +02:00
|
|
|
|
|
|
|
stub_and_eval \
|
|
|
|
_zsh_autosuggest_invoke_original_widget \
|
|
|
|
'BUFFER+="012345678901234567890"'
|
|
|
|
|
|
|
|
stub_and_echo \
|
|
|
|
_zsh_autosuggest_suggestion \
|
|
|
|
'012345678901234567890123456789'
|
|
|
|
|
|
|
|
_zsh_autosuggest_modify 'original-widget'
|
|
|
|
|
|
|
|
assertTrue \
|
|
|
|
'original widget not invoked' \
|
|
|
|
'stub_called _zsh_autosuggest_invoke_original_widget'
|
|
|
|
|
|
|
|
assertEquals \
|
|
|
|
'BUFFER was not modified' \
|
|
|
|
'012345678901234567890' \
|
|
|
|
"$BUFFER"
|
|
|
|
|
|
|
|
assertEquals \
|
|
|
|
'POSTDISPLAY does not contain suggestion' \
|
|
|
|
'' \
|
|
|
|
"$POSTDISPLAY"
|
|
|
|
}
|
|
|
|
|
2016-04-07 01:10:34 +02:00
|
|
|
testRetval() {
|
|
|
|
stub_and_eval \
|
|
|
|
_zsh_autosuggest_invoke_original_widget \
|
|
|
|
'return 1'
|
|
|
|
|
|
|
|
_zsh_autosuggest_widget_modify 'original-widget'
|
2016-03-15 00:38:37 +01:00
|
|
|
|
2016-04-07 01:10:34 +02:00
|
|
|
assertEquals \
|
|
|
|
'Did not return correct value from original widget' \
|
|
|
|
'1' \
|
|
|
|
"$?"
|
2016-03-15 00:38:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
run_tests "$0"
|