From e00abb7772d53f118ca8662a0fcca03e2423c25d Mon Sep 17 00:00:00 2001 From: Thomas Buckley-Houston Date: Tue, 25 Jul 2017 16:48:43 +0700 Subject: Better non-wrapped HOME/END. Use system clipboard. --- spec/novim_mode_spec.rb | 82 +++++++++++++++++++++++++++++++++++++++++++------ spec/spec_helper.rb | 31 ++++++++++++++++--- 2 files changed, 99 insertions(+), 14 deletions(-) (limited to 'spec') diff --git a/spec/novim_mode_spec.rb b/spec/novim_mode_spec.rb index a3d603c..965fbb0 100644 --- a/spec/novim_mode_spec.rb +++ b/spec/novim_mode_spec.rb @@ -2,15 +2,6 @@ # of testing Vim. require 'spec_helper' -def initial(string) - @vim_options.each { |x| vim.command(x) } if @vim_options - write_file_content(string) -end - -def final(string) - expect(load_file_content).to eq normalize_string_indent(string) -end - describe 'Basic editing' do specify 'writing simple text' do initial <<-EOF @@ -48,6 +39,18 @@ describe 'Basic editing' do copy me copy me EOF end + + specify 'CTRL+ARROW jumps by word' do + initial <<-EOF + one two three four + EOF + + type 'XYZ' + + final <<-EOF + one Xtwo ZYthree four + EOF + end end describe 'Selecting' do @@ -106,6 +109,66 @@ describe 'Selecting' do !of text EOF end + + specify 'CTRL+D selects the word under the cursor' do + initial <<-EOF + a line of text + EOF + + 4.times { type '' } + type 'X' + + final <<-EOF + a X of text + EOF + end +end + +describe 'Home/End behaviour for long, non-wrapped code lines' do + before(:each) do + # We need a small screen so that lines go off the edge of it. + @vim_options = [ + # A single buffer can't be resized, so create a split of the buffer + 'vsplit', + 'vertical resize 6' + ] + end + + specify 'HOME/END move to start/end of line off-screen' do + initial <<-EOF + line line line line + EOF + + type 'XY' + + final <<-EOF + Yline line line lineX + EOF + end + + specify 'SHIFT+END selects line, even if off-screen' do + initial <<-EOF + line line line line! + EOF + + type 'x' + + final <<-EOF + x! + EOF + end + + specify 'SHIFT+HOME selects line, even if off-screen' do + initial <<-EOF + !line line line line + EOF + + type 'x' + + final <<-EOF + !x + EOF + end end describe 'Wrapped text' do @@ -115,6 +178,7 @@ describe 'Wrapped text' do 'vsplit', 'vertical resize 6' ] + use_extension 'txt' end specify 'move up/down one wrapped line' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5b3e0ea..cfe5a51 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,17 +20,24 @@ Vimrunner::RSpec.configure do |config| end end -TEST_FILE = 'test_file.txt'.freeze +RSpec.configure do |config| + config.before :each do + # Default to setting the filetype to shell to enable + # code-like behaviour. + @ext = 'sh' + end +end -def write_file_content(string) +def write_file_content(string, ext = 'sh') + @file = "file.#{ext}" string = normalize_string_indent(string) - File.open(TEST_FILE, 'w') { |f| f.write(string) } - vim.edit TEST_FILE + File.open(@file, 'w') { |f| f.write(string) } + vim.edit @file end def load_file_content vim.write - IO.read(TEST_FILE).strip + IO.read(@file).strip end def type(string) @@ -42,3 +49,17 @@ def type(string) end end end + +def initial(string) + @vim_options.each { |x| vim.command(x) } if @vim_options + write_file_content(string, @ext) +end + +def final(string) + expected = normalize_string_indent(string) + expect(load_file_content).to eq expected +end + +def use_extension(ext) + @ext = ext +end -- cgit v1.2.3-70-g09d2