Mercurial > dotfiles
comparison .zfun/zsh-autosuggestions/spec/options/widget_lists_spec.rb @ 467:e1ce8897030d
zsh: import df6f6f9ff41 of zsh-autosuggestions
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Mon, 03 Dec 2018 22:37:29 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
466:f248cf012d9a | 467:e1ce8897030d |
---|---|
1 describe 'a zle widget' do | |
2 let(:widget) { 'my-widget' } | |
3 let(:before_sourcing) { -> { session.run_command("#{widget}() {}; zle -N #{widget}; bindkey ^B #{widget}") } } | |
4 | |
5 context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do | |
6 let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] } | |
7 | |
8 it 'accepts the suggestion when invoked' do | |
9 with_history('echo hello') do | |
10 session.send_string('e') | |
11 wait_for { session.content }.to eq('echo hello') | |
12 session.send_keys('C-b') | |
13 wait_for { session.content(esc_seqs: true) }.to eq('echo hello') | |
14 end | |
15 end | |
16 end | |
17 | |
18 context 'when added to ZSH_AUTOSUGGEST_CLEAR_WIDGETS' do | |
19 let(:options) { ["ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(#{widget})"] } | |
20 | |
21 it 'clears the suggestion when invoked' do | |
22 with_history('echo hello') do | |
23 session.send_string('e') | |
24 wait_for { session.content }.to eq('echo hello') | |
25 session.send_keys('C-b') | |
26 wait_for { session.content }.to eq('e') | |
27 end | |
28 end | |
29 end | |
30 | |
31 context 'when added to ZSH_AUTOSUGGEST_EXECUTE_WIDGETS' do | |
32 let(:options) { ["ZSH_AUTOSUGGEST_EXECUTE_WIDGETS+=(#{widget})"] } | |
33 | |
34 it 'executes the suggestion when invoked' do | |
35 with_history('echo hello') do | |
36 session.send_string('e') | |
37 wait_for { session.content }.to eq('echo hello') | |
38 session.send_keys('C-b') | |
39 wait_for { session.content }.to end_with("\nhello") | |
40 end | |
41 end | |
42 end | |
43 | |
44 context 'when added to ZSH_AUTOSUGGEST_IGNORE_WIDGETS' do | |
45 let(:options) { ["ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(#{widget})"] } | |
46 | |
47 it 'should not be wrapped with an autosuggest widget' do | |
48 session.run_command("echo $widgets[#{widget}]") | |
49 wait_for { session.content }.to end_with("\nuser:#{widget}") | |
50 end | |
51 end | |
52 | |
53 context 'that moves the cursor forward' do | |
54 before { session.run_command("#{widget}() { zle forward-char }") } | |
55 | |
56 context 'when added to ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS' do | |
57 let(:options) { ["ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(#{widget})"] } | |
58 | |
59 it 'accepts the suggestion as far as the cursor is moved when invoked' do | |
60 with_history('echo hello') do | |
61 session.send_string('e') | |
62 wait_for { session.content }.to start_with('echo hello') | |
63 session.send_keys('C-b') | |
64 wait_for { session.content(esc_seqs: true) }.to match(/\Aec\e\[[0-9]+mho hello/) | |
65 end | |
66 end | |
67 end | |
68 end | |
69 | |
70 context 'that modifies the buffer' do | |
71 before { session.run_command("#{widget}() { BUFFER=\"foo\" }") } | |
72 | |
73 context 'when not added to any of the widget lists' do | |
74 it 'modifies the buffer and fetches a new suggestion' do | |
75 with_history('foobar') do | |
76 session.send_keys('C-b') | |
77 wait_for { session.content }.to eq('foobar') | |
78 end | |
79 end | |
80 end | |
81 end | |
82 end | |
83 | |
84 describe 'a modification to the widget lists' do | |
85 let(:widget) { 'my-widget' } | |
86 let(:before_sourcing) { -> { session.run_command("#{widget}() {}; zle -N #{widget}; bindkey ^B #{widget}") } } | |
87 before { session.run_command("ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})") } | |
88 | |
89 it 'takes effect on the next cmd line' do | |
90 with_history('echo hello') do | |
91 session.send_string('e') | |
92 wait_for { session.content }.to eq('echo hello') | |
93 session.send_keys('C-b') | |
94 wait_for { session.content(esc_seqs: true) }.to eq('echo hello') | |
95 end | |
96 end | |
97 end |