robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
3.8 KiB133 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, pending = t.describe, t.it, t.before_each, t.pending
5local assert_alive = n.assert_alive
6local clear = n.clear
7local command = n.command
8local eq = t.eq
9local expect = n.expect
10local feed = n.feed
11local feed_command = n.feed_command
12local fn = n.fn
13local insert = n.insert
14local api = n.api
15local missing_provider = n.missing_provider
16local matches = t.matches
17local write_file = t.write_file
18local pcall_err = t.pcall_err
19
20do
21  clear()
22  local reason = missing_provider('ruby')
23  if reason then
24    it(':ruby reports E319 if provider is missing', function()
25      local expected = [[Vim%(ruby.*%):E319: No "ruby" provider found.*]]
26      matches(expected, pcall_err(command, 'ruby puts "foo"'))
27      matches(expected, pcall_err(command, 'rubyfile foo'))
28    end)
29    pending(string.format('N/A: Missing neovim RubyGem (%s)', reason), function() end)
30    return
31  end
32end
33
34before_each(function()
35  clear()
36end)
37
38describe('ruby feature test', function()
39  it('works', function()
40    eq(1, fn.has('ruby'))
41  end)
42end)
43
44describe(':ruby command', function()
45  it('evaluates ruby', function()
46    command('ruby VIM.command("let g:set_by_ruby = [100, 0]")')
47    eq({ 100, 0 }, api.nvim_get_var('set_by_ruby'))
48  end)
49
50  it('supports nesting', function()
51    command([[ruby VIM.command('ruby VIM.command("let set_by_nested_ruby = 555")')]])
52    eq(555, api.nvim_get_var('set_by_nested_ruby'))
53  end)
54end)
55
56describe(':rubyfile command', function()
57  it('evaluates a ruby file', function()
58    local fname = 'rubyfile.rb'
59    write_file(fname, 'VIM.command("let set_by_rubyfile = 123")')
60    command('rubyfile rubyfile.rb')
61    eq(123, api.nvim_get_var('set_by_rubyfile'))
62    os.remove(fname)
63  end)
64end)
65
66describe(':rubydo command', function()
67  it('exposes the $_ variable for modifying lines', function()
68    insert('abc\ndef\nghi\njkl')
69    expect([[
70      abc
71      def
72      ghi
73      jkl]])
74
75    feed('ggjvj:rubydo $_.upcase!<CR>')
76    expect([[
77      abc
78      DEF
79      GHI
80      jkl]])
81  end)
82
83  it('operates on all lines when not given a range', function()
84    insert('abc\ndef\nghi\njkl')
85    expect([[
86      abc
87      def
88      ghi
89      jkl]])
90
91    feed(':rubydo $_.upcase!<CR>')
92    expect([[
93      ABC
94      DEF
95      GHI
96      JKL]])
97  end)
98
99  it('does not modify the buffer if no changes are made', function()
100    command('normal :rubydo 42')
101    eq(false, api.nvim_get_option_value('modified', {}))
102  end)
103end)
104
105describe('ruby provider', function()
106  it('RPC call to expand("<afile>") during BufDelete #5245 #5617', function()
107    n.add_builddir_to_rtp()
108    command([=[autocmd BufDelete * ruby VIM::evaluate('expand("<afile>")')]=])
109    feed_command('help help')
110    assert_alive()
111  end)
112end)
113
114describe('rubyeval()', function()
115  it('evaluates ruby objects', function()
116    eq({ 1, 2, { ['key'] = 'val' } }, fn.rubyeval('[1, 2, {key: "val"}]'))
117  end)
118
119  it('returns nil for empty strings', function()
120    eq(vim.NIL, fn.rubyeval(''))
121  end)
122
123  it('errors out when given non-string', function()
124    eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(10)'))
125    eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:_null_dict)'))
126    eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:_null_list)'))
127    eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(0.0)'))
128    eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(function("tr"))'))
129    eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:true)'))
130    eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:false)'))
131    eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:null)'))
132  end)
133end)