2019-09-14 13:31:54 -07:00
|
|
|
" Tests for ruby interface
|
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
source check.vim
|
|
|
|
CheckFeature ruby
|
2019-09-14 13:31:54 -07:00
|
|
|
|
|
|
|
func Test_ruby_change_buffer()
|
|
|
|
call setline(line('$'), ['1 line 1'])
|
|
|
|
ruby Vim.command("normal /^1\n")
|
|
|
|
ruby $curbuf.line = "1 changed line 1"
|
|
|
|
call assert_equal('1 changed line 1', getline('$'))
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_rubydo()
|
2019-09-14 14:00:52 -07:00
|
|
|
throw 'skipped: TODO: '
|
2019-09-14 13:31:54 -07:00
|
|
|
" Check deleting lines does not trigger ml_get error.
|
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
|
|
|
rubydo Vim.command("%d_")
|
|
|
|
bwipe!
|
|
|
|
|
|
|
|
" Check switching to another buffer does not trigger ml_get error.
|
|
|
|
new
|
|
|
|
let wincount = winnr('$')
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
|
|
|
rubydo Vim.command("new")
|
|
|
|
call assert_equal(wincount + 1, winnr('$'))
|
2020-10-14 14:44:14 -07:00
|
|
|
%bwipe!
|
2019-09-14 13:31:54 -07:00
|
|
|
endfunc
|
|
|
|
|
2020-12-06 15:51:06 -07:00
|
|
|
func Test_rubydo_dollar_underscore()
|
|
|
|
throw 'skipped: TODO: '
|
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two', 'three', 'four'])
|
|
|
|
2,3rubydo $_ = '[' + $_ + ']'
|
|
|
|
call assert_equal(['one', '[two]', '[three]', 'four'], getline(1, '$'))
|
|
|
|
bwipe!
|
|
|
|
|
|
|
|
call assert_fails('rubydo $_ = 0', 'E265:')
|
|
|
|
call assert_fails('rubydo (')
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
2019-09-14 13:31:54 -07:00
|
|
|
func Test_rubyfile()
|
|
|
|
" Check :rubyfile does not SEGV with Ruby level exception but just fails
|
|
|
|
let tempfile = tempname() . '.rb'
|
|
|
|
call writefile(['raise "vim!"'], tempfile)
|
|
|
|
call assert_fails('rubyfile ' . tempfile)
|
|
|
|
call delete(tempfile)
|
|
|
|
endfunc
|
2019-09-14 14:44:29 -07:00
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_set_cursor()
|
2019-09-14 14:44:29 -07:00
|
|
|
" Check that setting the cursor position works.
|
|
|
|
new
|
|
|
|
call setline(1, ['first line', 'second line'])
|
|
|
|
normal gg
|
|
|
|
rubydo $curwin.cursor = [1, 5]
|
|
|
|
call assert_equal([1, 6], [line('.'), col('.')])
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal([1, 5], rubyeval('$curwin.cursor'))
|
2019-09-14 14:44:29 -07:00
|
|
|
|
|
|
|
" Check that movement after setting cursor position keeps current column.
|
|
|
|
normal j
|
|
|
|
call assert_equal([2, 6], [line('.'), col('.')])
|
2021-11-01 10:45:21 -07:00
|
|
|
call assert_equal([2, 5], '$curwin.cursor'->rubyeval())
|
2020-10-14 14:44:14 -07:00
|
|
|
|
|
|
|
" call assert_fails('ruby $curwin.cursor = [1]',
|
|
|
|
" \ 'ArgumentError: array length must be 2')
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test buffer.count and buffer.length (number of lines in buffer)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_count()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(3, rubyeval('$curbuf.count'))
|
|
|
|
call assert_equal(3, rubyeval('$curbuf.length'))
|
2020-10-14 14:44:14 -07:00
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test buffer.name (buffer name)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_name()
|
2020-10-14 14:44:14 -07:00
|
|
|
new Xfoo
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(expand('%:p'), rubyeval('$curbuf.name'))
|
2020-10-14 14:44:14 -07:00
|
|
|
bwipe
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal('', rubyeval('$curbuf.name'))
|
2020-10-14 14:44:14 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test buffer.number (number of the buffer).
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_number()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(bufnr('%'), rubyeval('$curbuf.number'))
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(bufnr('%'), rubyeval('$curbuf.number'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
|
|
|
%bwipe
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test buffer.delete({n}) (delete line {n})
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_delete()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
|
|
|
ruby $curbuf.delete(2)
|
|
|
|
call assert_equal(['one', 'three'], getline(1, '$'))
|
|
|
|
|
|
|
|
" call assert_fails('ruby $curbuf.delete(0)', 'IndexError: line number 0 out of range')
|
|
|
|
" call assert_fails('ruby $curbuf.delete(3)', 'IndexError: line number 3 out of range')
|
|
|
|
call assert_fails('ruby $curbuf.delete(3)', 'RuntimeError: Index out of bounds')
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test buffer.append({str}, str) (append line {str} after line {n})
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_append()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
ruby $curbuf.append(0, 'one')
|
|
|
|
ruby $curbuf.append(1, 'three')
|
|
|
|
ruby $curbuf.append(1, 'two')
|
|
|
|
ruby $curbuf.append(4, 'four')
|
|
|
|
|
|
|
|
call assert_equal(['one', 'two', 'three', '', 'four'], getline(1, '$'))
|
|
|
|
|
|
|
|
" call assert_fails('ruby $curbuf.append(-1, "x")',
|
|
|
|
" \ 'IndexError: line number -1 out of range')
|
|
|
|
call assert_fails('ruby $curbuf.append(-1, "x")',
|
|
|
|
\ 'ArgumentError: Index out of bounds')
|
|
|
|
call assert_fails('ruby $curbuf.append(6, "x")',
|
|
|
|
\ 'RuntimeError: Index out of bounds')
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test buffer.line (get or set the current line)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_line()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
|
|
|
2
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal('two', rubyeval('$curbuf.line'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
|
|
|
ruby $curbuf.line = 'TWO'
|
|
|
|
call assert_equal(['one', 'TWO', 'three'], getline(1, '$'))
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test buffer.line_number (get current line number)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_line_number()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
|
|
|
2
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(2, rubyeval('$curbuf.line_number'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_get()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two'])
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal('one', rubyeval('$curbuf[1]'))
|
|
|
|
call assert_equal('two', rubyeval('$curbuf[2]'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
|
|
|
" call assert_fails('ruby $curbuf[0]',
|
|
|
|
" \ 'IndexError: line number 0 out of range')
|
|
|
|
call assert_fails('ruby $curbuf[3]',
|
|
|
|
\ 'RuntimeError: Index out of bounds')
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_buffer_set()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two'])
|
|
|
|
ruby $curbuf[2] = 'TWO'
|
|
|
|
ruby $curbuf[1] = 'ONE'
|
|
|
|
|
|
|
|
" call assert_fails('ruby $curbuf[0] = "ZERO"',
|
|
|
|
" \ 'IndexError: line number 0 out of range')
|
|
|
|
" call assert_fails('ruby $curbuf[3] = "THREE"',
|
|
|
|
" \ 'IndexError: line number 3 out of range')
|
|
|
|
call assert_fails('ruby $curbuf[3] = "THREE"',
|
|
|
|
\ 'RuntimeError: Index out of bounds')
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test window.width (get or set window height).
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_window_height()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
|
|
|
|
" Test setting window height
|
|
|
|
ruby $curwin.height = 2
|
|
|
|
call assert_equal(2, winheight(0))
|
|
|
|
|
|
|
|
" Test getting window height
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(2, rubyeval('$curwin.height'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
|
|
|
bwipe
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test window.width (get or set window width).
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_window_width()
|
2020-10-14 14:44:14 -07:00
|
|
|
vnew
|
|
|
|
|
|
|
|
" Test setting window width
|
|
|
|
ruby $curwin.width = 2
|
|
|
|
call assert_equal(2, winwidth(0))
|
|
|
|
|
|
|
|
" Test getting window width
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(2, rubyeval('$curwin.width'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
|
|
|
bwipe
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test window.buffer (get buffer object of a window object).
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_window_buffer()
|
2020-10-14 14:44:14 -07:00
|
|
|
new Xfoo1
|
|
|
|
new Xfoo2
|
|
|
|
ruby $b2 = $curwin.buffer
|
|
|
|
ruby $w2 = $curwin
|
|
|
|
wincmd j
|
|
|
|
ruby $b1 = $curwin.buffer
|
|
|
|
ruby $w1 = $curwin
|
|
|
|
|
2020-10-17 07:36:36 -07:00
|
|
|
" call assert_equal(rubyeval('$b1'), rubyeval('$w1.buffer'))
|
|
|
|
" call assert_equal(rubyeval('$b2'), rubyeval('$w2.buffer'))
|
|
|
|
call assert_equal(bufnr('Xfoo1'), rubyeval('$w1.buffer.number'))
|
|
|
|
call assert_equal(bufnr('Xfoo2'), rubyeval('$w2.buffer.number'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
|
|
|
ruby $b1, $w1, $b2, $w2 = nil
|
|
|
|
%bwipe
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::Window.current (get current window object)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_window_current()
|
2020-10-17 07:36:36 -07:00
|
|
|
let cw = rubyeval('$curwin.to_s')
|
|
|
|
" call assert_equal(cw, rubyeval('Vim::Window.current'))
|
2020-10-14 14:44:14 -07:00
|
|
|
call assert_match('^#<Neovim::Window:0x\x\+>$', cw)
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::Window.count (number of windows)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_window_count()
|
2020-10-14 14:44:14 -07:00
|
|
|
new Xfoo1
|
|
|
|
new Xfoo2
|
|
|
|
split
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(4, rubyeval('Vim::Window.count'))
|
2020-10-14 14:44:14 -07:00
|
|
|
%bwipe
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(1, rubyeval('Vim::Window.count'))
|
2020-10-14 14:44:14 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::Window[n] (get window object of window n)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_window_get()
|
2020-10-14 14:44:14 -07:00
|
|
|
new Xfoo1
|
|
|
|
new Xfoo2
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_match('Xfoo2$', rubyeval('Vim::Window[0].buffer.name'))
|
2020-10-14 14:44:14 -07:00
|
|
|
wincmd j
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_match('Xfoo1$', rubyeval('Vim::Window[1].buffer.name'))
|
2020-10-14 14:44:14 -07:00
|
|
|
wincmd j
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal('', rubyeval('Vim::Window[2].buffer.name'))
|
2020-10-14 14:44:14 -07:00
|
|
|
%bwipe
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::Buffer.current (return the buffer object of current buffer)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_buffer_current()
|
2020-10-17 07:36:36 -07:00
|
|
|
let cb = rubyeval('$curbuf.to_s')
|
|
|
|
" call assert_equal(cb, rubyeval('Vim::Buffer.current'))
|
2020-10-14 14:44:14 -07:00
|
|
|
call assert_match('^#<Neovim::Buffer:0x\x\+>$', cb)
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::Buffer:.count (return the number of buffers)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_buffer_count()
|
2020-10-14 14:44:14 -07:00
|
|
|
new Xfoo1
|
|
|
|
new Xfoo2
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(3, rubyeval('Vim::Buffer.count'))
|
2020-10-14 14:44:14 -07:00
|
|
|
%bwipe
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(1, rubyeval('Vim::Buffer.count'))
|
2020-10-14 14:44:14 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::buffer[n] (return the buffer object of buffer number n)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_buffer_get()
|
2020-10-14 14:44:14 -07:00
|
|
|
new Xfoo1
|
|
|
|
new Xfoo2
|
|
|
|
|
|
|
|
" Index of Vim::Buffer[n] goes from 0 to the number of buffers.
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal('', rubyeval('Vim::Buffer[0].name'))
|
|
|
|
call assert_match('Xfoo1$', rubyeval('Vim::Buffer[1].name'))
|
|
|
|
call assert_match('Xfoo2$', rubyeval('Vim::Buffer[2].name'))
|
2020-10-14 14:44:14 -07:00
|
|
|
call assert_fails('ruby print Vim::Buffer[3].name',
|
2024-10-05 16:28:28 -07:00
|
|
|
\ "NoMethodError: undefined method `name' for nil")
|
2020-10-14 14:44:14 -07:00
|
|
|
%bwipe
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::command({cmd}) (execute a Ex command))
|
|
|
|
" Test Vim::command({cmd})
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_command()
|
2020-10-14 14:44:14 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['one', 'two', 'three', 'four'])
|
|
|
|
ruby Vim::command('2,3d')
|
|
|
|
call assert_equal(['one', 'four'], getline(1, '$'))
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::set_option (set a vim option)
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_set_option()
|
2020-10-14 14:44:14 -07:00
|
|
|
call assert_equal(0, &number)
|
|
|
|
ruby Vim::set_option('number')
|
|
|
|
call assert_equal(1, &number)
|
|
|
|
ruby Vim::set_option('nonumber')
|
|
|
|
call assert_equal(0, &number)
|
|
|
|
endfunc
|
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_evaluate()
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(123, rubyeval('Vim::evaluate("123")'))
|
2020-10-14 14:44:14 -07:00
|
|
|
" Vim::evaluate("123").class gives Integer or Fixnum depending
|
|
|
|
" on versions of Ruby.
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_match('^Integer\|Fixnum$', rubyeval('Vim::evaluate("123").class'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
if has('float')
|
|
|
|
call assert_equal(1.23, rubyeval('Vim::evaluate("1.23")'))
|
|
|
|
call assert_equal('Float', rubyeval('Vim::evaluate("1.23").class'))
|
|
|
|
endif
|
2020-10-14 14:44:14 -07:00
|
|
|
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal('foo', rubyeval('Vim::evaluate("\"foo\"")'))
|
|
|
|
call assert_equal('String', rubyeval('Vim::evaluate("\"foo\"").class'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal([1, 2], rubyeval('Vim::evaluate("[1, 2]")'))
|
|
|
|
call assert_equal('Array', rubyeval('Vim::evaluate("[1, 2]").class'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal({'1': 2}, rubyeval('Vim::evaluate("{1:2}")'))
|
|
|
|
call assert_equal('Hash', rubyeval('Vim::evaluate("{1:2}").class'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(v:null, rubyeval('Vim::evaluate("v:null")'))
|
|
|
|
call assert_equal('NilClass', rubyeval('Vim::evaluate("v:null").class'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
2020-10-17 07:36:36 -07:00
|
|
|
" call assert_equal(v:null, rubyeval('Vim::evaluate("v:none")'))
|
|
|
|
" call assert_equal('NilClass', rubyeval('Vim::evaluate("v:none").class'))
|
2020-10-14 14:44:14 -07:00
|
|
|
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(v:true, rubyeval('Vim::evaluate("v:true")'))
|
|
|
|
call assert_equal('TrueClass', rubyeval('Vim::evaluate("v:true").class'))
|
|
|
|
call assert_equal(v:false, rubyeval('Vim::evaluate("v:false")'))
|
|
|
|
call assert_equal('FalseClass',rubyeval('Vim::evaluate("v:false").class'))
|
2020-10-14 14:44:14 -07:00
|
|
|
endfunc
|
|
|
|
|
2024-07-15 23:25:35 -07:00
|
|
|
func Test_ruby_Vim_blob()
|
|
|
|
throw 'skipped: TODO: '
|
|
|
|
call assert_equal('0z', rubyeval('Vim::blob("")'))
|
|
|
|
call assert_equal('0z31326162', rubyeval('Vim::blob("12ab")'))
|
|
|
|
call assert_equal('0z00010203', rubyeval('Vim::blob("\x00\x01\x02\x03")'))
|
|
|
|
call assert_equal('0z8081FEFF', rubyeval('Vim::blob("\x80\x81\xfe\xff")'))
|
|
|
|
endfunc
|
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_evaluate_list()
|
2020-10-14 14:44:14 -07:00
|
|
|
call setline(line('$'), ['2 line 2'])
|
|
|
|
ruby Vim.command("normal /^2\n")
|
|
|
|
let l = ["abc", "def"]
|
2023-04-28 17:12:32 -07:00
|
|
|
ruby << trim EOF
|
|
|
|
curline = $curbuf.line_number
|
|
|
|
l = Vim.evaluate("l");
|
|
|
|
$curbuf.append(curline, l.join("|"))
|
|
|
|
EOF
|
2020-10-14 14:44:14 -07:00
|
|
|
normal j
|
|
|
|
.rubydo $_ = $_.gsub(/\|/, '/')
|
|
|
|
call assert_equal('abc/def', getline('$'))
|
|
|
|
endfunc
|
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_evaluate_dict()
|
2020-10-14 14:44:14 -07:00
|
|
|
let d = {'a': 'foo', 'b': 123}
|
|
|
|
redir => l:out
|
|
|
|
ruby d = Vim.evaluate("d"); print d
|
|
|
|
redir END
|
|
|
|
call assert_equal(['{"a"=>"foo", "b"=>123}'], split(l:out, "\n"))
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" Test Vim::message({msg}) (display message {msg})
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_Vim_message()
|
2020-10-14 14:44:14 -07:00
|
|
|
throw 'skipped: TODO: '
|
|
|
|
ruby Vim::message('A message')
|
|
|
|
let messages = split(execute('message'), "\n")
|
|
|
|
call assert_equal('A message', messages[-1])
|
|
|
|
endfunc
|
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_print()
|
2020-10-17 07:36:36 -07:00
|
|
|
func RubyPrint(expr)
|
|
|
|
return trim(execute('ruby print ' . a:expr))
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
call assert_equal('123', RubyPrint('123'))
|
|
|
|
call assert_equal('1.23', RubyPrint('1.23'))
|
|
|
|
call assert_equal('Hello World!', RubyPrint('"Hello World!"'))
|
|
|
|
call assert_equal('[1, 2]', RubyPrint('[1, 2]'))
|
|
|
|
call assert_equal('{"k1"=>"v1", "k2"=>"v2"}', RubyPrint('({"k1" => "v1", "k2" => "v2"})'))
|
|
|
|
call assert_equal('true', RubyPrint('true'))
|
|
|
|
call assert_equal('false', RubyPrint('false'))
|
|
|
|
call assert_equal('', RubyPrint('nil'))
|
|
|
|
call assert_match('Vim', RubyPrint('Vim'))
|
|
|
|
call assert_match('Module', RubyPrint('Vim.class'))
|
|
|
|
|
|
|
|
delfunc RubyPrint
|
2020-10-14 14:44:14 -07:00
|
|
|
endfunc
|
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
func Test_ruby_p()
|
2020-10-14 14:44:14 -07:00
|
|
|
ruby p 'Just a test'
|
2020-10-31 19:37:39 -07:00
|
|
|
let messages = GetMessages()
|
2020-10-14 14:44:14 -07:00
|
|
|
call assert_equal('"Just a test"', messages[-1])
|
2020-10-14 14:50:46 -07:00
|
|
|
|
|
|
|
" Check return values of p method
|
|
|
|
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(123, rubyeval('p(123)'))
|
|
|
|
call assert_equal([1, 2, 3], rubyeval('p(1, 2, 3)'))
|
2020-10-14 14:50:46 -07:00
|
|
|
|
|
|
|
" Avoid the "message maintainer" line.
|
|
|
|
let $LANG = ''
|
|
|
|
messages clear
|
2020-10-17 07:36:36 -07:00
|
|
|
call assert_equal(v:true, rubyeval('p() == nil'))
|
2020-10-14 14:50:46 -07:00
|
|
|
|
2020-10-31 19:37:39 -07:00
|
|
|
let messages = GetMessages()
|
2020-10-14 14:50:46 -07:00
|
|
|
call assert_equal(0, len(messages))
|
2019-09-14 14:44:29 -07:00
|
|
|
endfunc
|
2020-12-06 15:51:06 -07:00
|
|
|
|
|
|
|
func Test_rubyeval_error()
|
|
|
|
" On Linux or Windows the error matches:
|
|
|
|
" "syntax error, unexpected end-of-input"
|
|
|
|
" whereas on macOS in CI, the error message makes less sense:
|
|
|
|
" "SyntaxError: array length must be 2"
|
|
|
|
" Unclear why. The test does not check the error message.
|
|
|
|
call assert_fails('call rubyeval("(")')
|
|
|
|
endfunc
|
|
|
|
|
2023-04-28 17:12:32 -07:00
|
|
|
" Test for various heredoc syntax
|
|
|
|
func Test_ruby_heredoc()
|
|
|
|
ruby << END
|
|
|
|
Vim.command('let s = "A"')
|
|
|
|
END
|
|
|
|
ruby <<
|
|
|
|
Vim.command('let s ..= "B"')
|
|
|
|
.
|
|
|
|
ruby << trim END
|
|
|
|
Vim.command('let s ..= "C"')
|
|
|
|
END
|
|
|
|
ruby << trim
|
|
|
|
Vim.command('let s ..= "D"')
|
|
|
|
.
|
2023-04-28 17:50:04 -07:00
|
|
|
ruby << trim eof
|
|
|
|
Vim.command('let s ..= "E"')
|
|
|
|
eof
|
|
|
|
call assert_equal('ABCDE', s)
|
2023-04-28 17:12:32 -07:00
|
|
|
endfunc
|
|
|
|
|
2020-12-06 15:51:06 -07:00
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|