summaryrefslogtreecommitdiff
path: root/home-config/zsh/zsh-autosuggestions/spec/integrations/vi_mode_spec.rb
blob: 0a295c23b3a71180235162de57d83598e5cb0313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
describe 'when using vi mode' do
  let(:before_sourcing) do
    -> do
      session.run_command('bindkey -v')
    end
  end

  describe 'moving the cursor after exiting insert mode' do
    it 'should not clear the current suggestion' do
      with_history('foobar foo') do
        session.
          send_string('foo').
          send_keys('escape').
          send_keys('h')

        wait_for { session.content }.to eq('foobar foo')
      end
    end
  end

  describe '`vi-forward-word-end`' do
    it 'should accept through the end of the current word' do
      with_history('foobar foo') do
        session.
          send_string('foo').
          send_keys('escape').
          send_keys('e'). # vi-forward-word-end
          send_keys('a'). # vi-add-next
          send_string('baz')

        wait_for { session.content }.to eq('foobarbaz')
      end
    end
  end

  describe '`vi-forward-word`' do
    it 'should accept through the first character of the next word' do
      with_history('foobar foo') do
        session.
          send_string('foo').
          send_keys('escape').
          send_keys('w'). # vi-forward-word
          send_keys('a'). # vi-add-next
          send_string('az')

        wait_for { session.content }.to eq('foobar faz')
      end
    end
  end

  describe '`vi-find-next-char`' do
    it 'should accept through the next occurrence of the character' do
      with_history('foobar foo') do
        session.
          send_string('foo').
          send_keys('escape').
          send_keys('f'). # vi-find-next-char
          send_keys('o').
          send_keys('a'). # vi-add-next
          send_string('b')

        wait_for { session.content }.to eq('foobar fob')
      end
    end
  end

  describe '`vi-delete`' do
    it 'should be able to remove the last character in the buffer' do
      skip 'deleting last char did not work below zsh version 5.0.8' if session.zsh_version < Gem::Version.new('5.0.8')

      session.
        send_string('echo foo').
        send_keys('escape').
        send_keys('d').
        send_keys('l')

      wait_for { session.content }.to eq('echo fo')
    end
  end
end