robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.unit.testutil' ) 2local describe =t . describe 3local itp =t . gen_itp ( t . it ) 4 5local to_cstr =t . to_cstr 6local ffi =t . ffi 7local eq =t . eq 8 9local indent =t . cimport ( './src/nvim/indent.h' ) 10local globals =t . cimport ( './src/nvim/globals.h' ) 11 12describe ( 'get_sts_value' , function () 13itp ( [[returns 'softtabstop' when it is non-negative]] , function () 14globals . curbuf . b_p_sts =5 15eq ( 5 , indent . get_sts_value ()) 16 17globals . curbuf . b_p_sts =0 18eq ( 0 , indent . get_sts_value ()) 19end ) 20 21itp ( [[returns "effective shiftwidth" when 'softtabstop' is negative]] , function () 22local shiftwidth =2 23globals . curbuf . b_p_sw =shiftwidth 24local tabstop =5 25globals . curbuf . b_p_ts =tabstop 26globals . curbuf . b_p_sts =- 2 27eq ( shiftwidth , indent . get_sts_value ()) 28 29shiftwidth =0 30globals . curbuf . b_p_sw =shiftwidth 31eq ( tabstop , indent . get_sts_value ()) 32end ) 33end ) 34 35describe ( 'indent_size_ts()' , function () 36itp ( 'works for spaces' , function () 37local line =to_cstr (( ' ' ): rep ( 7 ) .. 'a ' ) 38eq ( 7 , indent . indent_size_ts ( line , 100 , nil )) 39end ) 40 41itp ( 'works for tabs and spaces' , function () 42local line =to_cstr ( ' \t \t \t\t a ' ) 43eq ( 19 , indent . indent_size_ts ( line , 4 , nil )) 44end ) 45 46itp ( 'works for tabs and spaces with empty vts' , function () 47local vts =ffi . new ( 'int[1]' ) -- zero initialized => first element (size) == 0 48local line =to_cstr ( ' \t \t \t\t a ' ) 49eq ( 23 , indent . indent_size_ts ( line , 4 , vts )) 50end ) 51 52itp ( 'works for tabs and spaces with vts' , function () 53local vts =ffi . new ( 'int[3]' ) 54vts [ 0 ] =2 -- zero indexed 55vts [ 1 ] =7 56vts [ 2 ] =2 57 58local line =to_cstr ( ' \t \t \t\t a ' ) 59eq ( 18 , indent . indent_size_ts ( line , 4 , vts )) 60end ) 61end )