robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each , pending =t . describe , t . it , t . before_each , t . pending 6local clear =n . clear 7local connect =n . connect 8local get_session =n . get_session 9local eq =t . eq 10local fn =n . fn 11local is_os =t . is_os 12local nvim_prog =n . nvim_prog 13 14describe ( 'has()' , function () 15before_each ( clear ) 16 17it ( '"nvim-x.y.z"' , function () 18eq ( 0 , fn . has ( 'nvim-' )) 19eq ( 0 , fn . has ( 'nvim- ' )) 20eq ( 0 , fn . has ( 'nvim- \t ' )) 21eq ( 0 , fn . has ( 'nvim-0. 1. 1' )) 22eq ( 0 , fn . has ( 'nvim-0. 1.1' )) 23eq ( 0 , fn . has ( 'nvim-0.1. 1' )) 24eq ( 0 , fn . has ( 'nvim-a' )) 25eq ( 0 , fn . has ( 'nvim-a.b.c' )) 26eq ( 0 , fn . has ( 'nvim-0.b.c' )) 27eq ( 0 , fn . has ( 'nvim-0.0.c' )) 28eq ( 0 , fn . has ( 'nvim-0.b.0' )) 29eq ( 0 , fn . has ( 'nvim-a.b.0' )) 30eq ( 0 , fn . has ( 'nvim-.0.0.0' )) 31eq ( 0 , fn . has ( 'nvim-.0' )) 32eq ( 0 , fn . has ( 'nvim-0.' )) 33eq ( 0 , fn . has ( 'nvim-0..' )) 34eq ( 0 , fn . has ( 'nvim-.' )) 35eq ( 0 , fn . has ( 'nvim-..' )) 36eq ( 0 , fn . has ( 'nvim-...' )) 37eq ( 0 , fn . has ( 'nvim-42' )) 38eq ( 0 , fn . has ( 'nvim-9999' )) 39eq ( 0 , fn . has ( 'nvim-99.001.05' )) 40 41eq ( 1 , fn . has ( 'nvim' )) 42eq ( 1 , fn . has ( 'nvim-0' )) 43eq ( 1 , fn . has ( 'nvim-0.1' )) 44eq ( 1 , fn . has ( 'nvim-0.0.0' )) 45eq ( 1 , fn . has ( 'nvim-0.1.1.' )) 46eq ( 1 , fn . has ( 'nvim-0.1.1.abc' )) 47eq ( 1 , fn . has ( 'nvim-0.1.1..' )) 48eq ( 1 , fn . has ( 'nvim-0.1.1.. ..' )) 49eq ( 1 , fn . has ( 'nvim-0.1.1.... ' )) 50eq ( 1 , fn . has ( 'nvim-0.0.0' )) 51eq ( 1 , fn . has ( 'nvim-0.0.1' )) 52eq ( 1 , fn . has ( 'nvim-0.1.0' )) 53eq ( 1 , fn . has ( 'nvim-0.1.1' )) 54eq ( 1 , fn . has ( 'nvim-0.1.5' )) 55eq ( 1 , fn . has ( 'nvim-0000.001.05' )) 56eq ( 1 , fn . has ( 'nvim-0.01.005' )) 57eq ( 1 , fn . has ( 'nvim-00.001.05' )) 58end ) 59 60it ( '"unnamedplus"' , function () 61if ( not is_os ( 'win' )) and fn . has ( 'clipboard' ) == 1 then 62eq ( 1 , fn . has ( 'unnamedplus' )) 63else 64eq ( 0 , fn . has ( 'unnamedplus' )) 65end 66end ) 67 68it ( '"terminfo"' , function () 69local version =n . exec_capture ( 'verbose version' ) 70local compilation_string =version : match ( 'Compilation: (.*)' ) 71-- zig builds currently show only TODO for the compilation string 72if not compilation_string or compilation_string : match ( 'TODO' ) then 73pending ( 'no compilation string present' ) 74end 75-- Looks like "HAVE_UNIBILIUM ", "HAVE_UNIBILIUM=1", "HAVE_UNIBILIUM off", …. 76-- Capture group returns the "1"/"off"/…. 77local build_flag = 78vim . trim (( compilation_string : match ( 'HAVE_UNIBILIUM([^-]+)' ) or 'missing' ): lower ()) 79local is_enabled =not ( 80build_flag == 'missing' 81or build_flag == 'false' 82or build_flag == '0' 83or build_flag == 'off' 84) 85eq ( is_enabled and 1 or 0 , fn . has ( 'terminfo' )) 86end ) 87 88it ( '"wsl"' , function () 89local is_wsl =vim . uv . os_uname ()[ 'release' ]: lower (): match ( 'microsoft' ) and true or false 90if is_wsl then 91eq ( 1 , fn . has ( 'wsl' )) 92else 93eq ( 0 , fn . has ( 'wsl' )) 94end 95end ) 96 97it ( '"gui_running"' , function () 98eq ( 0 , fn . has ( 'gui_running' )) 99local tui_session =get_session () 100local gui_session =connect ( fn . serverstart ()) 101eq ( 0 , fn . has ( 'gui_running' )) 102local tui =Screen . new ( 50 , 5 , { rgb =true , stdin_tty =true , stdout_tty =true } , tui_session ) 103eq ( 0 , fn . has ( 'gui_running' )) 104local gui =Screen . new ( 50 , 15 , { ext_multigrid =true , rgb =true } , gui_session ) 105eq ( 1 , fn . has ( 'gui_running' )) 106tui : detach () 107eq ( 1 , fn . has ( 'gui_running' )) 108gui : detach () 109eq ( 0 , fn . has ( 'gui_running' )) 110end ) 111 112it ( 'does not change v:shell_error' , function () 113fn . system ( { nvim_prog , '-es' , '+73cquit' } ) 114fn . has ( 'python3' ) -- use a call whose implementation shells out 115eq ( 73 , fn . eval ( 'v:shell_error' )) 116end ) 117 118it ( '"patch[0-9]\\+"' , function () 119eq ( 1 , fn . has ( 'patch0' )) 120eq ( 1 , fn . has ( 'patch1' )) 121end ) 122 123it ( '"patch-x.y.z"' , function () 124-- versions older than current v:version always succeed 125-- unless minor version has 2+ digits 126eq ( 1 , fn . has ( 'patch-7.4.0' )) 127eq ( 0 , fn . has ( 'patch-7.40.0' )) 128eq ( 1 , fn . has ( 'patch-8.0.0' )) 129eq ( 0 , fn . has ( 'patch-8.00.0' )) 130 131eq ( 1 , fn . has ( 'patch-8.1.0' )) 132eq ( 1 , fn . has ( 'patch-8.1.1' )) 133eq ( 1 , fn . has ( 'patch-8.1.0001' )) 134eq ( 1 , fn . has ( 'patch-8.1.1939' )) 135eq ( 1 , fn . has ( 'patch-8.1.2424' )) 136 137eq ( 0 , fn . has ( 'patch-8.2.0' )) 138eq ( 1 , fn . has ( 'patch-8.2.1' )) 139eq ( 1 , fn . has ( 'patch-8.2.2999' )) 140eq ( 1 , fn . has ( 'patch-8.2.5171' )) 141 142eq ( 0 , fn . has ( 'patch-9.0.0' )) 143eq ( 1 , fn . has ( 'patch-9.0.1' )) 144eq ( 1 , fn . has ( 'patch-9.0.998' )) 145eq ( 1 , fn . has ( 'patch-9.0.2190' )) 146 147eq ( 1 , fn . has ( 'patch-9.1.0' )) 148eq ( 1 , fn . has ( 'patch-9.1.1' )) 149eq ( 1 , fn . has ( 'patch-9.1.690' )) 150eq ( 1 , fn . has ( 'patch-9.1.1934' )) 151end ) 152end )