1" Tests for ruby interface 2 3if !has('ruby') 4 finish 5end 6 7func Test_ruby_change_buffer() 8 call setline(line('$'), ['1 line 1']) 9 ruby Vim.command("normal /^1\n") 10 ruby $curbuf.line = "1 changed line 1" 11 call assert_equal('1 changed line 1', getline('$')) 12endfunc 13 14func Test_ruby_evaluate_list() 15 call setline(line('$'), ['2 line 2']) 16 ruby Vim.command("normal /^2\n") 17 let l = ["abc", "def"] 18 ruby << EOF 19 curline = $curbuf.line_number 20 l = Vim.evaluate("l"); 21 $curbuf.append(curline, l.join("\n")) 22EOF 23 normal j 24 .rubydo $_ = $_.gsub(/\n/, '/') 25 call assert_equal('abc/def', getline('$')) 26endfunc 27 28func Test_ruby_evaluate_dict() 29 let d = {'a': 'foo', 'b': 123} 30 redir => l:out 31 ruby d = Vim.evaluate("d"); print d 32 redir END 33 call assert_equal(['{"a"=>"foo", "b"=>123}'], split(l:out, "\n")) 34endfunc 35 36func Test_rubydo() 37 " Check deleting lines does not trigger ml_get error. 38 new 39 call setline(1, ['one', 'two', 'three']) 40 rubydo Vim.command("%d_") 41 bwipe! 42 43 " Check switching to another buffer does not trigger ml_get error. 44 new 45 let wincount = winnr('$') 46 call setline(1, ['one', 'two', 'three']) 47 rubydo Vim.command("new") 48 call assert_equal(wincount + 1, winnr('$')) 49 bwipe! 50 bwipe! 51endfunc 52 53func Test_rubyfile() 54 " Check :rubyfile does not SEGV with Ruby level exception but just fails 55 let tempfile = tempname() . '.rb' 56 call writefile(['raise "vim!"'], tempfile) 57 call assert_fails('rubyfile ' . tempfile) 58 call delete(tempfile) 59endfunc 60