Browse Source

Add spec for `completion` strategy

pull/344/head
Eric Freese 6 years ago
parent
commit
973205005c
4 changed files with 39 additions and 3 deletions
  1. +30
    -0
      spec/strategies/completion_spec.rb
  2. +1
    -1
      spec/strategies/match_prev_cmd_spec.rb
  3. +4
    -1
      src/strategies/completion.zsh
  4. +4
    -1
      zsh-autosuggestions.zsh

+ 30
- 0
spec/strategies/completion_spec.rb View File

@ -0,0 +1,30 @@
describe 'the `completion` suggestion strategy' do
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=completion'] }
let(:before_sourcing) do
-> do
session.
run_command('autoload compinit && compinit').
run_command('_foo() { compadd bar }').
run_command('compdef _foo baz')
end
end
it 'suggests the first completion result' do
session.send_string('baz ')
wait_for { session.content }.to eq('baz bar')
end
context 'when async mode is enabled' do
before do
skip 'Async mode not supported below v5.0.8' if session.zsh_version < Gem::Version.new('5.0.8')
end
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=completion'] }
it 'suggests the first completion result' do
session.send_string('baz ')
wait_for { session.content }.to eq('baz bar')
end
end
end

+ 1
- 1
spec/strategies/match_prev_cmd_spec.rb View File

@ -1,6 +1,6 @@
require 'strategies/special_characters_helper' require 'strategies/special_characters_helper'
describe 'the match_prev_cmd strategy' do
describe 'the `match_prev_cmd` strategy' do
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=match_prev_cmd'] } let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=match_prev_cmd'] }
it 'suggests the last matching history entry after the previous command' do it 'suggests the last matching history entry after the previous command' do

+ 4
- 1
src/strategies/completion.zsh View File

@ -9,7 +9,10 @@
_zsh_autosuggest_capture_setup() { _zsh_autosuggest_capture_setup() {
zmodload zsh/zutil # For `zparseopts` zmodload zsh/zutil # For `zparseopts`
autoload compinit && compinit
# Ensure completions have been initialized
if ! whence compdef >/dev/null; then
autoload -Uz compinit && compinit
fi
# There is a bug in zpty module (fixed in zsh/master) by which a # There is a bug in zpty module (fixed in zsh/master) by which a
# zpty that exits will kill all zpty processes that were forked # zpty that exits will kill all zpty processes that were forked

+ 4
- 1
zsh-autosuggestions.zsh View File

@ -506,7 +506,10 @@ zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle
_zsh_autosuggest_capture_setup() { _zsh_autosuggest_capture_setup() {
zmodload zsh/zutil # For `zparseopts` zmodload zsh/zutil # For `zparseopts`
autoload compinit && compinit
# Ensure completions have been initialized
if ! whence compdef >/dev/null; then
autoload -Uz compinit && compinit
fi
# There is a bug in zpty module (fixed in zsh/master) by which a # There is a bug in zpty module (fixed in zsh/master) by which a
# zpty that exits will kill all zpty processes that were forked # zpty that exits will kill all zpty processes that were forked

Loading…
Cancel
Save