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