2016-07-02 21:45:48 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
2021-09-01 09:42:53 -07:00
|
|
|
local assert_alive = helpers.assert_alive
|
2018-03-20 15:57:41 -07:00
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
2016-07-02 21:45:48 -07:00
|
|
|
local eq = helpers.eq
|
2020-10-17 07:36:36 -07:00
|
|
|
local exc_exec = helpers.exc_exec
|
2018-03-20 15:57:41 -07:00
|
|
|
local expect = helpers.expect
|
2016-07-02 21:45:48 -07:00
|
|
|
local feed = helpers.feed
|
2018-03-20 15:57:41 -07:00
|
|
|
local feed_command = helpers.feed_command
|
2016-07-02 21:45:48 -07:00
|
|
|
local funcs = helpers.funcs
|
|
|
|
local insert = helpers.insert
|
2018-03-20 15:57:41 -07:00
|
|
|
local meths = helpers.meths
|
2017-05-12 10:47:33 -07:00
|
|
|
local missing_provider = helpers.missing_provider
|
2019-09-06 17:17:37 -07:00
|
|
|
local matches = helpers.matches
|
2018-03-20 15:57:41 -07:00
|
|
|
local write_file = helpers.write_file
|
2019-09-06 17:17:37 -07:00
|
|
|
local pcall_err = helpers.pcall_err
|
2016-07-02 21:45:48 -07:00
|
|
|
|
|
|
|
do
|
|
|
|
clear()
|
2019-12-23 23:53:56 -07:00
|
|
|
local reason = missing_provider('ruby')
|
|
|
|
if reason then
|
2018-12-12 14:11:00 -07:00
|
|
|
it(':ruby reports E319 if provider is missing', function()
|
2019-01-11 16:52:12 -07:00
|
|
|
local expected = [[Vim%(ruby.*%):E319: No "ruby" provider found.*]]
|
2019-09-06 17:17:37 -07:00
|
|
|
matches(expected, pcall_err(command, 'ruby puts "foo"'))
|
|
|
|
matches(expected, pcall_err(command, 'rubyfile foo'))
|
2018-12-12 14:11:00 -07:00
|
|
|
end)
|
2019-12-23 23:53:56 -07:00
|
|
|
pending(string.format('Missing neovim RubyGem (%s)', reason), function() end)
|
2016-07-02 21:45:48 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('ruby feature test', function()
|
|
|
|
it('works', function()
|
|
|
|
eq(1, funcs.has('ruby'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe(':ruby command', function()
|
|
|
|
it('evaluates ruby', function()
|
|
|
|
command('ruby VIM.command("let g:set_by_ruby = [100, 0]")')
|
|
|
|
eq({100, 0}, meths.get_var('set_by_ruby'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('supports nesting', function()
|
|
|
|
command([[ruby VIM.command('ruby VIM.command("let set_by_nested_ruby = 555")')]])
|
|
|
|
eq(555, meths.get_var('set_by_nested_ruby'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe(':rubyfile command', function()
|
|
|
|
it('evaluates a ruby file', function()
|
|
|
|
local fname = 'rubyfile.rb'
|
|
|
|
write_file(fname, 'VIM.command("let set_by_rubyfile = 123")')
|
|
|
|
command('rubyfile rubyfile.rb')
|
|
|
|
eq(123, meths.get_var('set_by_rubyfile'))
|
|
|
|
os.remove(fname)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe(':rubydo command', function()
|
|
|
|
it('exposes the $_ variable for modifying lines', function()
|
|
|
|
insert('abc\ndef\nghi\njkl')
|
|
|
|
expect([[
|
|
|
|
abc
|
|
|
|
def
|
|
|
|
ghi
|
|
|
|
jkl]])
|
|
|
|
|
|
|
|
feed('ggjvj:rubydo $_.upcase!<CR>')
|
|
|
|
expect([[
|
|
|
|
abc
|
|
|
|
DEF
|
|
|
|
GHI
|
|
|
|
jkl]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('operates on all lines when not given a range', function()
|
|
|
|
insert('abc\ndef\nghi\njkl')
|
|
|
|
expect([[
|
|
|
|
abc
|
|
|
|
def
|
|
|
|
ghi
|
|
|
|
jkl]])
|
|
|
|
|
|
|
|
feed(':rubydo $_.upcase!<CR>')
|
|
|
|
expect([[
|
|
|
|
ABC
|
|
|
|
DEF
|
|
|
|
GHI
|
|
|
|
JKL]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not modify the buffer if no changes are made', function()
|
|
|
|
command('normal :rubydo 42')
|
2023-05-21 23:47:10 -07:00
|
|
|
eq(false, meths.get_option_value('modified', {}))
|
2016-07-02 21:45:48 -07:00
|
|
|
end)
|
|
|
|
end)
|
2018-03-20 15:57:41 -07:00
|
|
|
|
|
|
|
describe('ruby provider', function()
|
|
|
|
it('RPC call to expand("<afile>") during BufDelete #5245 #5617', function()
|
2019-08-28 13:47:54 -07:00
|
|
|
helpers.add_builddir_to_rtp()
|
2018-03-20 15:57:41 -07:00
|
|
|
command([=[autocmd BufDelete * ruby VIM::evaluate('expand("<afile>")')]=])
|
|
|
|
feed_command('help help')
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2018-03-20 15:57:41 -07:00
|
|
|
end)
|
|
|
|
end)
|
2020-10-17 07:36:36 -07:00
|
|
|
|
|
|
|
describe('rubyeval()', function()
|
|
|
|
it('evaluates ruby objects', function()
|
|
|
|
eq({1, 2, {['key'] = 'val'}}, funcs.rubyeval('[1, 2, {key: "val"}]'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('returns nil for empty strings', function()
|
|
|
|
eq(helpers.NIL, funcs.rubyeval(''))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('errors out when given non-string', function()
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(10)'))
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:_null_dict)'))
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:_null_list)'))
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(0.0)'))
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(function("tr"))'))
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:true)'))
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:false)'))
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:null)'))
|
|
|
|
end)
|
|
|
|
end)
|