From d64b2c002a51e99bafb54c6cc0dfe59f8de958dc Mon Sep 17 00:00:00 2001 From: Thomas Buckley-Houston Date: Fri, 16 Jun 2017 03:42:52 +0700 Subject: Better movement through wrapped text --- spec/novim_mode_spec.rb | 168 +++++++++++++++++++++++++++++++++++++----------- spec/spec_helper.rb | 23 +++++++ 2 files changed, 152 insertions(+), 39 deletions(-) (limited to 'spec') diff --git a/spec/novim_mode_spec.rb b/spec/novim_mode_spec.rb index 15c993f..a3d603c 100644 --- a/spec/novim_mode_spec.rb +++ b/spec/novim_mode_spec.rb @@ -2,78 +2,69 @@ # 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 +def initial(string) + @vim_options.each { |x| vim.command(x) } if @vim_options write_file_content(string) end -def after(string) +def final(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 + initial <<-EOF EOF type 'hello world' - after <<-EOF + final <<-EOF hello world EOF end + specify ' goes to first non-whitespace char' do + initial <<-EOF + justified + indented + EOF + + type '!' + + final <<-EOF + justified + !indented + EOF + end + specify 'copy and paste' do - before <<-EOF + initial <<-EOF copy me EOF - type '' + type '' - after <<-EOF + final <<-EOF copy me copy me EOF end +end +describe 'Selecting' do specify 'select all and replace' do - before <<-EOF + initial <<-EOF select me EOF type 'gone' - after <<-EOF + final <<-EOF gone EOF end specify 'paste over selection' do - before <<-EOF + initial <<-EOF cut me and paste over me EOF @@ -83,15 +74,114 @@ describe 'Basic editing' do 7.times { type '' } type '' - after <<-EOF + final <<-EOF and paste cut me EOF end + + specify 'selecting from middle of line to end' do + initial <<-EOF + a line of text + EOF + + 6.times { type '' } + type '' + type '!' + + final <<-EOF + a line! + EOF + end + + specify 'selecting from middle of line to beginning' do + initial <<-EOF + a line of text + EOF + + 7.times { type '' } + type '' + type '!' + + final <<-EOF + !of text + EOF + end end -describe 'Pane control' do - let(:options) {} +describe 'Wrapped text' do + before(:each) do + @vim_options = [ + # A single buffer can't be resized, so create a split of the buffer + 'vsplit', + 'vertical resize 6' + ] + end + + specify 'move up/down one wrapped line' do + initial <<-EOF + line line line line + EOF + + type 'down ' + type 'up ' + + final <<-EOF + line line up down line line + EOF + end + + specify 'select wrapped line below' do + initial <<-EOF + line1 line2 line3 line4 + EOF + + type '' + type '!' + final <<-EOF + line1 !line3 line4 + EOF + end + + specify 'select wrapped line above' do + initial <<-EOF + line1 line2 line3 line4 + EOF + + type '' + type '!' + + final <<-EOF + line1 !line3 line4 + EOF + end + + specify ' goes to end of wrapped line' do + initial <<-EOF + line line line line + EOF + + type '!' + + final <<-EOF + line! line line line + EOF + end + + specify ' goes to beginning of wrapped line' do + initial <<-EOF + line line line line + EOF + + type '!' + + final <<-EOF + line !line line line + EOF + end +end + +describe 'Pane control' do specify 'moving to another pane' do # Open Quickfix window (auto focuses to it) type ':copen' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f49f5a3..5b3e0ea 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,3 +19,26 @@ Vimrunner::RSpec.configure do |config| vim end end + +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 type(string) + string.scan(/<.*?>|./).each do |key| + if key =~ /<.*>/ + vim.feedkeys "\\#{key}" + else + vim.feedkeys key + end + end +end -- cgit v1.2.3-70-g09d2