2017-02-17 03:18:03 +01:00
|
|
|
describe 'a suggestion for a given prefix' do
|
2018-11-24 17:56:30 +01:00
|
|
|
let(:history_strategy) { '_zsh_autosuggest_strategy_history() { suggestion="history" }' }
|
|
|
|
let(:foobar_strategy) { '_zsh_autosuggest_strategy_foobar() { [[ "foobar baz" = $1* ]] && suggestion="foobar baz" }' }
|
|
|
|
let(:foobaz_strategy) { '_zsh_autosuggest_strategy_foobaz() { [[ "foobaz bar" = $1* ]] && suggestion="foobaz bar" }' }
|
2017-02-17 03:18:03 +01:00
|
|
|
|
2018-11-10 21:56:31 +01:00
|
|
|
let(:after_sourcing) do
|
|
|
|
-> do
|
|
|
|
session.run_command(history_strategy)
|
|
|
|
end
|
|
|
|
end
|
2018-11-24 17:56:30 +01:00
|
|
|
|
|
|
|
it 'by default is determined by calling the `history` strategy function' do
|
|
|
|
session.send_string('h')
|
|
|
|
wait_for { session.content }.to eq('history')
|
2017-02-17 03:18:03 +01:00
|
|
|
end
|
|
|
|
|
2018-11-24 17:56:30 +01:00
|
|
|
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to an array' do
|
2018-11-10 21:56:31 +01:00
|
|
|
let(:after_sourcing) do
|
|
|
|
-> do
|
|
|
|
session.
|
|
|
|
run_command(foobar_strategy).
|
|
|
|
run_command(foobaz_strategy).
|
|
|
|
run_command('ZSH_AUTOSUGGEST_STRATEGY=(foobar foobaz)')
|
|
|
|
end
|
|
|
|
end
|
2017-02-17 03:18:03 +01:00
|
|
|
|
2018-11-24 17:56:30 +01:00
|
|
|
it 'is determined by the first strategy function to return a suggestion' do
|
|
|
|
session.send_string('foo')
|
|
|
|
wait_for { session.content }.to eq('foobar baz')
|
|
|
|
|
|
|
|
session.send_string('baz')
|
|
|
|
wait_for { session.content }.to eq('foobaz bar')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to a string' do
|
2018-11-10 21:56:31 +01:00
|
|
|
let(:after_sourcing) do
|
|
|
|
-> do
|
|
|
|
session.
|
|
|
|
run_command(foobar_strategy).
|
|
|
|
run_command(foobaz_strategy).
|
|
|
|
run_command('ZSH_AUTOSUGGEST_STRATEGY="foobar foobaz"')
|
|
|
|
end
|
|
|
|
end
|
2018-11-24 17:56:30 +01:00
|
|
|
|
|
|
|
it 'is determined by the first strategy function to return a suggestion' do
|
|
|
|
session.send_string('foo')
|
|
|
|
wait_for { session.content }.to eq('foobar baz')
|
|
|
|
|
|
|
|
session.send_string('baz')
|
|
|
|
wait_for { session.content }.to eq('foobaz bar')
|
2017-02-17 03:18:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-10 21:56:31 +01:00
|
|
|
|