aboutsummaryrefslogtreecommitdiff
path: root/spec/novim_mode_spec.rb
blob: b960b104fa135eb1742b8e5727a04b7def4f4f1a (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Tip of the hat to terryma/vim-multiple-cursors for this style
# of testing Vim.
require 'spec_helper'

TEST_FILE = 'test_file.txt'.freeze

def write_file_content(string)
  string = normalize_string_indent(string)
  File.open(TEST_FILE, 'w') { |f| f.write(string) }
  vim.edit TEST_FILE
end

def load_file_content
  vim.write
  IO.read(TEST_FILE).strip
end

def before(string)
  options.each { |x| vim.command(x) } if options
  write_file_content(string)
end

def after(string)
  expect(load_file_content).to eq normalize_string_indent(string)
end

def type(string)
  string.scan(/<.*?>|./).each do |key|
    if key =~ /<.*>/
      vim.feedkeys "\\#{key}"
    else
      vim.feedkeys key
    end
  end
end

describe 'Basic editing' do
  let(:options) {}

  specify 'writing simple text' do
    before <<-EOF
    EOF

    type 'hello world'

    after <<-EOF
      hello world
    EOF
  end

  specify 'copy and paste' do
    before <<-EOF
      copy me
    EOF

    # Conventional behaviour shouldn't need the <End> right?
    type '<S-End><C-c><End><Space><C-v>'

    after <<-EOF
      copy me copy me
    EOF
  end

  specify 'select all and replace' do
    before <<-EOF
      select me
    EOF

    # Conventional behaviour shouldn't need the <End>?
    type '<C-a>gone'

    after <<-EOF
      gone
    EOF
  end
end

describe 'Pane control' do
  let(:options) {}

  specify 'moving to another pane' do
    # Open Quickfix window (auto focuses to it)
    type '<M-;>:copen<CR>'
    pane_type = vim.command 'echo &buftype'
    expect(pane_type).to eq 'quickfix'

    # Focus back to file
    type '<M-Up>'
    pane_type = vim.command 'echo &buftype'

    expect(pane_type).to eq ''
  end

  specify 'closing a pane' do
    # Open Netrw file manager in a sidebar
    type '<M-;>:Vexplore<CR>'
    buffer_id = vim.command "echo bufnr('%')"
    expect(buffer_id).to eq '2'

    # Close Netrw pane
    type '<C-w>'
    buffer_id = vim.command "echo bufnr('%')"
    expect(buffer_id).to eq '1'
  end
end