Bram Moolenaar | 85babd6 | 2016-06-21 22:59:28 +0200 | [diff] [blame] | 1 | " Tests for ruby interface |
| 2 | |
| 3 | if !has('ruby') |
| 4 | finish |
| 5 | end |
| 6 | |
| 7 | func 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('$')) |
| 12 | endfunc |
| 13 | |
| 14 | func 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")) |
| 22 | EOF |
| 23 | normal j |
| 24 | .rubydo $_ = $_.gsub(/\n/, '/') |
| 25 | call assert_equal('abc/def', getline('$')) |
| 26 | endfunc |
| 27 | |
| 28 | func 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")) |
| 34 | endfunc |
Bram Moolenaar | c593fee | 2017-01-29 23:11:25 +0100 | [diff] [blame] | 35 | |
| 36 | func 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! |
| 51 | endfunc |
Bram Moolenaar | 37badc8 | 2018-01-31 20:15:30 +0100 | [diff] [blame] | 52 | |
| 53 | func 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) |
| 59 | endfunc |
Bram Moolenaar | 5390144 | 2018-07-25 22:02:36 +0200 | [diff] [blame] | 60 | |
| 61 | func Test_set_cursor() |
| 62 | " Check that setting the cursor position works. |
| 63 | new |
| 64 | call setline(1, ['first line', 'second line']) |
| 65 | normal gg |
| 66 | rubydo $curwin.cursor = [1, 5] |
| 67 | call assert_equal([1, 6], [line('.'), col('.')]) |
| 68 | |
| 69 | " Check that movement after setting cursor position keeps current column. |
| 70 | normal j |
| 71 | call assert_equal([2, 6], [line('.'), col('.')]) |
| 72 | endfunc |