2018-02-11 12:11:38 -07:00
" Tests for case-insensitive UTF-8 comparisons (utf_strnicmp() in mbyte.c)
" Also test "g~ap".
2022-02-06 14:34:20 -07:00
func Ch ( a , op , b , expected )
2018-02-11 12:11:38 -07:00
call assert_equal ( eval ( printf ( '"%s" %s "%s"' , a :a , a :op , a :b ) ) , a :expected ,
\ printf ( '"%s" %s "%s" should return %d' , a :a , a :op , a :b , a :expected ) )
2022-02-06 14:34:20 -07:00
endfunc
2018-02-11 12:11:38 -07:00
2022-02-06 14:34:20 -07:00
func Chk ( a , b , result )
2018-02-11 12:11:38 -07:00
if a :result = = 0
call Ch ( a :a , '==?' , a :b , 1 )
call Ch ( a :a , '!=?' , a :b , 0 )
call Ch ( a :a , '<=?' , a :b , 1 )
call Ch ( a :a , '>=?' , a :b , 1 )
call Ch ( a :a , '<?' , a :b , 0 )
call Ch ( a :a , '>?' , a :b , 0 )
elseif a :result > 0
call Ch ( a :a , '==?' , a :b , 0 )
call Ch ( a :a , '!=?' , a :b , 1 )
call Ch ( a :a , '<=?' , a :b , 0 )
call Ch ( a :a , '>=?' , a :b , 1 )
call Ch ( a :a , '<?' , a :b , 0 )
call Ch ( a :a , '>?' , a :b , 1 )
else
call Ch ( a :a , '==?' , a :b , 0 )
call Ch ( a :a , '!=?' , a :b , 1 )
call Ch ( a :a , '<=?' , a :b , 1 )
call Ch ( a :a , '>=?' , a :b , 0 )
call Ch ( a :a , '<?' , a :b , 1 )
call Ch ( a :a , '>?' , a :b , 0 )
endif
2020-11-29 23:08:27 -07:00
endfunc
2018-02-11 12:11:38 -07:00
2020-11-29 23:08:27 -07:00
func Check ( a , b , result )
2018-02-11 12:11:38 -07:00
call Chk ( a :a , a :b , a :result )
call Chk ( a :b , a :a , - a :result )
2020-11-29 23:08:27 -07:00
endfunc
2018-02-11 12:11:38 -07:00
2020-11-29 23:08:27 -07:00
func LT ( a , b )
2018-02-11 12:11:38 -07:00
call Check ( a :a , a :b , -1 )
2020-11-29 23:08:27 -07:00
endfunc
2018-02-11 12:11:38 -07:00
2020-11-29 23:08:27 -07:00
func GT ( a , b )
2018-02-11 12:11:38 -07:00
call Check ( a :a , a :b , 1 )
2020-11-29 23:08:27 -07:00
endfunc
2018-02-11 12:11:38 -07:00
2020-11-29 23:08:27 -07:00
func EQ ( a , b )
2018-02-11 12:11:38 -07:00
call Check ( a :a , a :b , 0 )
2020-11-29 23:08:27 -07:00
endfunc
2018-02-11 12:11:38 -07:00
2020-11-29 23:08:27 -07:00
func Test_comparisons ( )
2018-02-11 12:11:38 -07:00
call EQ ( '' , '' )
call LT ( '' , 'a' )
call EQ ( 'abc' , 'abc' )
call EQ ( 'Abc' , 'abC' )
call LT ( 'ab' , 'abc' )
call LT ( 'AB' , 'abc' )
call LT ( 'ab' , 'aBc' )
call EQ ( '\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd' , '\xd0\xb9\xd0\xa6\xd0\xa3\xd0\xba\xd0\x95\xd0\xbd' )
call LT ( '\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd' , '\xd0\xaf\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd' )
call EQ ( '\xe2\x84\xaa' , 'k' )
call LT ( '\xe2\x84\xaa' , 'kkkkkk' )
call EQ ( '\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa' , 'kkk' )
call LT ( 'kk' , '\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa' )
call EQ ( '\xe2\x84\xaa\xe2\x84\xa6k\xe2\x84\xaak\xcf\x89' , 'k\xcf\x89\xe2\x84\xaakk\xe2\x84\xa6' )
call EQ ( 'Abc\x80' , 'AbC\x80' )
call LT ( 'Abc\x80' , 'AbC\x81' )
call LT ( 'Abc' , 'AbC\x80' )
call LT ( 'abc\x80DEF' , 'abc\x80def' ) " case folding stops at the first bad character
call LT ( '\xc3XYZ' , '\xc3xyz' )
call EQ ( '\xef\xbc\xba' , '\xef\xbd\x9a' ) " FF3A (upper), FF5A (lower)
call GT ( '\xef\xbc\xba' , '\xef\xbc\xff' ) " first string is ok and equals \xef\xbd\x9a after folding, second string is illegal and was left unchanged, then the strings were bytewise compared
call LT ( '\xc3' , '\xc3\x83' )
call EQ ( '\xc3\xa3xYz' , '\xc3\x83XyZ' )
for n in range ( 0 x60 , 0 xFF)
call LT ( printf ( 'xYz\x%.2X' , n -1 ) , printf ( 'XyZ\x%.2X' , n ) )
endfor
for n in range ( 0 x80 , 0 xBF)
call EQ ( printf ( 'xYz\xc2\x%.2XUvW' , n ) , printf ( 'XyZ\xc2\x%.2XuVw' , n ) )
endfor
for n in range ( 0 xC0 , 0 xFF)
call LT ( printf ( 'xYz\xc2\x%.2XUvW' , n ) , printf ( 'XyZ\xc2\x%.2XuVw' , n ) )
endfor
2020-11-29 23:08:27 -07:00
endfunc
2018-02-11 12:11:38 -07:00
" test that g~ap changes one paragraph only.
2020-11-29 23:08:27 -07:00
func Test_gap ( )
2018-02-11 12:11:38 -07:00
new
2022-02-03 18:23:54 -07:00
" setup text
call feedkeys ( "iabcd\<cr>\<cr>defg" , "tx" )
" modify only first line
call feedkeys ( "gg0g~ap" , "tx" )
2018-02-11 12:11:38 -07:00
call assert_equal ( ["ABCD" , "" , "defg" ], getline ( 1 , 3 ) )
2020-11-29 23:08:27 -07:00
endfunc
2024-02-12 16:38:12 -07:00
2024-02-13 15:39:47 -07:00
" test that g~, ~ and gU correctly upper-cases ß
2024-02-12 16:38:12 -07:00
func Test_uppercase_sharp_ss ( )
new
call setline ( 1 , repeat ( ['ß' ], 4 ) )
call cursor ( 1 , 1 )
norm ! ~
call assert_equal ( 'ẞ' , getline ( line ( '.' ) ) )
norm ! ~
call assert_equal ( 'ß' , getline ( line ( '.' ) ) )
call cursor ( 2 , 1 )
norm ! g ~ l
call assert_equal ( 'ẞ' , getline ( line ( '.' ) ) )
norm ! g ~ l
call assert_equal ( 'ß' , getline ( line ( '.' ) ) )
call cursor ( 3 , 1 )
norm ! gUl
call assert_equal ( 'ẞ' , getline ( line ( '.' ) ) )
norm ! vgU
call assert_equal ( 'ẞ' , getline ( line ( '.' ) ) )
norm ! vgu
call assert_equal ( 'ß' , getline ( line ( '.' ) ) )
norm ! gul
call assert_equal ( 'ß' , getline ( line ( '.' ) ) )
call cursor ( 4 , 1 )
norm ! vgU
call assert_equal ( 'ẞ' , getline ( line ( '.' ) ) )
norm ! vgu
call assert_equal ( 'ß' , getline ( line ( '.' ) ) )
bw !
endfunc
" vim: shiftwidth=2 sts=2 expandtab