perl_spec.lua 3.4 KB

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