blob: ae27b39cd31453657877927d6dc924b8da1a9dd8 [file] [log] [blame]
Bram Moolenaar85babd62016-06-21 22:59:28 +02001" 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
Bram Moolenaarc593fee2017-01-29 23:11:25 +010035
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
Bram Moolenaar37badc82018-01-31 20:15:30 +010052
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
Bram Moolenaar53901442018-07-25 22:02:36 +020060
61func 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('.')])
72endfunc