vim-patch:8.1.1056: no eval function for Ruby

Problem:    No eval function for Ruby.
Solution:   Add rubyeval(). (Ozaki Kiichi, closes vim/vim#4152)
e99be0e6d2
This commit is contained in:
Alex Genco
2020-10-17 07:36:36 -07:00
parent 0f590ae2a8
commit ed0a70087a
6 changed files with 119 additions and 63 deletions

View File

@@ -5,6 +5,7 @@ local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq
local eval = helpers.eval
local exc_exec = helpers.exc_exec
local expect = helpers.expect
local feed = helpers.feed
local feed_command = helpers.feed_command
@@ -109,3 +110,24 @@ describe('ruby provider', function()
eq(2, eval('1+1')) -- Still alive?
end)
end)
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)