2017-02-17 10:18:03 +08:00
|
|
|
describe 'a zle widget' do
|
2017-02-19 02:12:10 +08:00
|
|
|
let(:widget) { 'my-widget' }
|
|
|
|
let(:before_sourcing) { -> { session.run_command("#{widget}() {}; zle -N #{widget}; bindkey ^B #{widget}") } }
|
2017-02-17 10:18:03 +08:00
|
|
|
|
|
|
|
context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do
|
2017-02-19 02:12:10 +08:00
|
|
|
let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] }
|
2017-02-17 10:18:03 +08:00
|
|
|
|
2019-06-24 02:37:08 +08:00
|
|
|
it 'accepts the suggestion and moves the cursor to the end of the buffer when invoked' do
|
2017-02-17 10:18:03 +08:00
|
|
|
with_history('echo hello') do
|
|
|
|
session.send_string('e')
|
|
|
|
wait_for { session.content }.to eq('echo hello')
|
|
|
|
session.send_keys('C-b')
|
|
|
|
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
|
2019-06-24 02:37:08 +08:00
|
|
|
wait_for { session.cursor }.to eq([10, 0])
|
2017-02-17 10:18:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when added to ZSH_AUTOSUGGEST_CLEAR_WIDGETS' do
|
2017-02-19 02:12:10 +08:00
|
|
|
let(:options) { ["ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(#{widget})"] }
|
2017-02-17 10:18:03 +08:00
|
|
|
|
|
|
|
it 'clears the suggestion when invoked' do
|
|
|
|
with_history('echo hello') do
|
|
|
|
session.send_string('e')
|
|
|
|
wait_for { session.content }.to eq('echo hello')
|
|
|
|
session.send_keys('C-b')
|
|
|
|
wait_for { session.content }.to eq('e')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when added to ZSH_AUTOSUGGEST_EXECUTE_WIDGETS' do
|
2017-02-19 02:12:10 +08:00
|
|
|
let(:options) { ["ZSH_AUTOSUGGEST_EXECUTE_WIDGETS+=(#{widget})"] }
|
2017-02-17 10:18:03 +08:00
|
|
|
|
|
|
|
it 'executes the suggestion when invoked' do
|
|
|
|
with_history('echo hello') do
|
|
|
|
session.send_string('e')
|
|
|
|
wait_for { session.content }.to eq('echo hello')
|
|
|
|
session.send_keys('C-b')
|
|
|
|
wait_for { session.content }.to end_with("\nhello")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-19 02:12:10 +08:00
|
|
|
context 'when added to ZSH_AUTOSUGGEST_IGNORE_WIDGETS' do
|
|
|
|
let(:options) { ["ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(#{widget})"] }
|
2017-02-17 10:18:03 +08:00
|
|
|
|
2017-02-19 02:12:10 +08:00
|
|
|
it 'should not be wrapped with an autosuggest widget' do
|
|
|
|
session.run_command("echo $widgets[#{widget}]")
|
|
|
|
wait_for { session.content }.to end_with("\nuser:#{widget}")
|
2017-02-17 10:18:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-19 02:12:10 +08:00
|
|
|
context 'that moves the cursor forward' do
|
|
|
|
before { session.run_command("#{widget}() { zle forward-char }") }
|
2017-02-17 10:18:03 +08:00
|
|
|
|
2017-02-19 02:12:10 +08:00
|
|
|
context 'when added to ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS' do
|
|
|
|
let(:options) { ["ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(#{widget})"] }
|
2017-02-17 10:18:03 +08:00
|
|
|
|
2017-02-19 02:12:10 +08:00
|
|
|
it 'accepts the suggestion as far as the cursor is moved when invoked' do
|
|
|
|
with_history('echo hello') do
|
|
|
|
session.send_string('e')
|
|
|
|
wait_for { session.content }.to start_with('echo hello')
|
|
|
|
session.send_keys('C-b')
|
|
|
|
wait_for { session.content(esc_seqs: true) }.to match(/\Aec\e\[[0-9]+mho hello/)
|
|
|
|
end
|
|
|
|
end
|
2017-02-17 10:18:03 +08:00
|
|
|
end
|
|
|
|
end
|
2017-03-01 02:13:29 +08:00
|
|
|
|
|
|
|
context 'that modifies the buffer' do
|
|
|
|
before { session.run_command("#{widget}() { BUFFER=\"foo\" }") }
|
|
|
|
|
|
|
|
context 'when not added to any of the widget lists' do
|
|
|
|
it 'modifies the buffer and fetches a new suggestion' do
|
|
|
|
with_history('foobar') do
|
|
|
|
session.send_keys('C-b')
|
|
|
|
wait_for { session.content }.to eq('foobar')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-17 10:18:03 +08:00
|
|
|
end
|
2017-02-19 02:12:55 +08:00
|
|
|
|
|
|
|
describe 'a modification to the widget lists' do
|
|
|
|
let(:widget) { 'my-widget' }
|
|
|
|
let(:before_sourcing) { -> { session.run_command("#{widget}() {}; zle -N #{widget}; bindkey ^B #{widget}") } }
|
|
|
|
before { session.run_command("ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})") }
|
|
|
|
|
|
|
|
it 'takes effect on the next cmd line' do
|
|
|
|
with_history('echo hello') do
|
|
|
|
session.send_string('e')
|
|
|
|
wait_for { session.content }.to eq('echo hello')
|
|
|
|
session.send_keys('C-b')
|
|
|
|
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
|
|
|
|
end
|
|
|
|
end
|
2019-04-11 01:41:20 +08:00
|
|
|
|
|
|
|
context 'when manual rebind is enabled' do
|
|
|
|
let(:options) { ["ZSH_AUTOSUGGEST_MANUAL_REBIND=true"] }
|
|
|
|
|
|
|
|
it 'does not take effect until bind command is re-run' do
|
|
|
|
with_history('echo hello') do
|
|
|
|
session.send_string('e')
|
|
|
|
wait_for { session.content }.to eq('echo hello')
|
|
|
|
session.send_keys('C-b')
|
|
|
|
sleep 1
|
|
|
|
expect(session.content(esc_seqs: true)).not_to eq('echo hello')
|
|
|
|
|
|
|
|
session.send_keys('C-c')
|
|
|
|
session.run_command('_zsh_autosuggest_bind_widgets').clear_screen
|
|
|
|
wait_for { session.content }.to eq('')
|
|
|
|
|
|
|
|
session.send_string('e')
|
|
|
|
wait_for { session.content }.to eq('echo hello')
|
|
|
|
session.send_keys('C-b')
|
|
|
|
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-19 02:12:55 +08:00
|
|
|
end
|