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