aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorThomas Buckley-Houston2017-05-30 09:24:00 +0000
committerThomas Buckley-Houston2017-05-30 09:24:00 +0000
commit79bd6b4273325f891d2fcdb2a79ede59e313e414 (patch)
tree48028cfaf00bdd6ef82b83afb638317db4a9a53d /spec
parent37905d1bad1dd19cca13fd36022b0cffb811b699 (diff)
Formalise plugin: functions, autoload, tests
Diffstat (limited to 'spec')
-rw-r--r--spec/novim_mode_spec.rb105
-rw-r--r--spec/spec_helper.rb21
2 files changed, 126 insertions, 0 deletions
diff --git a/spec/novim_mode_spec.rb b/spec/novim_mode_spec.rb
new file mode 100644
index 0000000..b960b10
--- /dev/null
+++ b/spec/novim_mode_spec.rb
@@ -0,0 +1,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
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..fa8e548
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,21 @@
+require 'vimrunner'
+require 'vimrunner/rspec'
+
+Vimrunner::RSpec.configure do |config|
+ # Use a single Vim instance for the test suite. Set to false to use an
+ # instance per test (slower, but can be easier to manage).
+ config.reuse_server = false
+
+ # Decide how to start a Vim instance. In this block, an instance should be
+ # spawned and set up with anything project-specific.
+ config.start_vim do
+ vim = Vimrunner.start
+
+ # Setup your plugin in the Vim instance
+ plugin_path = File.expand_path('../..', __FILE__)
+ vim.add_plugin(plugin_path, 'plugin/novim_mode.vim')
+
+ # The returned value is the Client available in the tests.
+ vim
+ end
+end