robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
3.4 KiB142 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, teardown, pending =
5  t.describe, t.it, t.before_each, t.teardown, t.pending
6local eq, clear = t.eq, n.clear
7local missing_provider = n.missing_provider
8local command = n.command
9local write_file = t.write_file
10local eval = n.eval
11local retry = t.retry
12local api = n.api
13local insert = n.insert
14local expect = n.expect
15local feed = n.feed
16
17do
18  clear()
19  local reason = missing_provider('perl')
20  if reason then
21    pending(
22      string.format('N/A: Missing perl host, or perl version is too old (%s)', reason),
23      function() end
24    )
25    return
26  end
27end
28
29before_each(function()
30  clear()
31end)
32
33describe('legacy perl provider', function()
34  it('feature test', function()
35    eq(1, eval('has("perl")'))
36  end)
37
38  it(':perl command', function()
39    command('perl $vim->vars->{set_by_perl} = [100, 0];')
40    eq({ 100, 0 }, eval('g:set_by_perl'))
41  end)
42
43  it(':perlfile command', function()
44    local fname = 'perlfile.pl'
45    write_file(fname, '$vim->command("let set_by_perlfile = 123")')
46    command('perlfile perlfile.pl')
47    eq(123, eval('g:set_by_perlfile'))
48    os.remove(fname)
49  end)
50
51  it(':perldo command', function()
52    -- :perldo 1; doesn't change $_,
53    -- the buffer should not be changed
54    command('normal :perldo 1;')
55    eq(false, api.nvim_get_option_value('modified', {}))
56    -- insert some text
57    insert('abc\ndef\nghi')
58    expect([[
59      abc
60      def
61      ghi]])
62    -- go to top and select and replace the first two lines
63    feed('ggvj:perldo $_ = reverse ($_)."$linenr"<CR>')
64    expect([[
65      cba1
66      fed2
67      ghi]])
68  end)
69
70  it('perleval()', function()
71    eq({ 1, 2, { ['key'] = 'val' } }, eval([[perleval('[1, 2, {"key" => "val"}]')]]))
72  end)
73end)
74
75describe('perl provider', function()
76  teardown(function()
77    os.remove('Xtest-perl-hello.pl')
78    os.remove('Xtest-perl-hello-plugin.pl')
79  end)
80
81  it('works', function()
82    local fname = 'Xtest-perl-hello.pl'
83    write_file(
84      fname,
85      [[
86      package main;
87      use strict;
88      use warnings;
89      use Neovim::Ext;
90      use Neovim::Ext::MsgPack::RPC;
91
92      my $session = Neovim::Ext::MsgPack::RPC::socket_session($ENV{NVIM});
93      my $nvim = Neovim::Ext::from_session($session);
94      $nvim->command('let g:job_out = "hello"');
95      1;
96    ]]
97    )
98    command('let g:job_id = jobstart(["perl", "' .. fname .. '"])')
99    retry(nil, 3000, function()
100      eq('hello', eval('g:job_out'))
101    end)
102  end)
103
104  it('plugin works', function()
105    local fname = 'Xtest-perl-hello-plugin.pl'
106    write_file(
107      fname,
108      [[
109      package TestPlugin;
110      use strict;
111      use warnings;
112      use parent qw(Neovim::Ext::Plugin);
113
114      __PACKAGE__->register;
115
116      @{TestPlugin::commands} = ();
117      @{TestPlugin::specs} = ();
118      sub test_command :nvim_command('TestCommand')
119      {
120        my ($this) = @_;
121        $this->nvim->command('let g:job_out = "hello-plugin"');
122      }
123
124      package main;
125      use strict;
126      use warnings;
127      use Neovim::Ext;
128      use Neovim::Ext::MsgPack::RPC;
129
130      my $session = Neovim::Ext::MsgPack::RPC::socket_session($ENV{NVIM});
131      my $nvim = Neovim::Ext::from_session($session);
132      my $plugin = TestPlugin->new($nvim);
133      $plugin->test_command();
134      1;
135    ]]
136    )
137    command('let g:job_id = jobstart(["perl", "' .. fname .. '"])')
138    retry(nil, 3000, function()
139      eq('hello-plugin', eval('g:job_out'))
140    end)
141  end)
142end)