robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
b2f7a3aaad
master
1" Tests for case-insensitive UTF-8 comparisons (utf_strnicmp() in mbyte.c) 2" Also test "g~ap". 3 4func Ch ( a , op , b , expected ) 5call assert_equal ( eval ( printf ( '"%s" %s "%s"' , a: a , a: op , a: b )), a: expected , 6 \printf ( '"%s" %s "%s" should return %d' , a: a , a: op , a: b , a: expected )) 7endfunc 8 9func Chk ( a , b , result ) 10if a: result == 0 11call Ch ( a: a , '==?' , a: b , 1 ) 12call Ch ( a: a , '!=?' , a: b , 0 ) 13call Ch ( a: a , '<=?' , a: b , 1 ) 14call Ch ( a: a , '>=?' , a: b , 1 ) 15call Ch ( a: a , '<?' , a: b , 0 ) 16call Ch ( a: a , '>?' , a: b , 0 ) 17elseif a: result > 0 18call Ch ( a: a , '==?' , a: b , 0 ) 19call Ch ( a: a , '!=?' , a: b , 1 ) 20call Ch ( a: a , '<=?' , a: b , 0 ) 21call Ch ( a: a , '>=?' , a: b , 1 ) 22call Ch ( a: a , '<?' , a: b , 0 ) 23call Ch ( a: a , '>?' , a: b , 1 ) 24else 25call Ch ( a: a , '==?' , a: b , 0 ) 26call Ch ( a: a , '!=?' , a: b , 1 ) 27call Ch ( a: a , '<=?' , a: b , 1 ) 28call Ch ( a: a , '>=?' , a: b , 0 ) 29call Ch ( a: a , '<?' , a: b , 1 ) 30call Ch ( a: a , '>?' , a: b , 0 ) 31endif 32endfunc 33 34func Check ( a , b , result ) 35call Chk ( a: a , a: b , a: result ) 36call Chk ( a: b , a: a , - a: result ) 37endfunc 38 39func LT ( a , b ) 40call Check ( a: a , a: b , -1 ) 41endfunc 42 43func GT ( a , b ) 44call Check ( a: a , a: b , 1 ) 45endfunc 46 47func EQ ( a , b ) 48call Check ( a: a , a: b , 0 ) 49endfunc 50 51func Test_comparisons () 52call EQ ( '' , '' ) 53call LT ( '' , 'a' ) 54call EQ ( 'abc' , 'abc' ) 55call EQ ( 'Abc' , 'abC' ) 56call LT ( 'ab' , 'abc' ) 57call LT ( 'AB' , 'abc' ) 58call LT ( 'ab' , 'aBc' ) 59call 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' ) 60call 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' ) 61call EQ ( '\xe2\x84\xaa' , 'k' ) 62call LT ( '\xe2\x84\xaa' , 'kkkkkk' ) 63call EQ ( '\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa' , 'kkk' ) 64call LT ( 'kk' , '\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa' ) 65call EQ ( '\xe2\x84\xaa\xe2\x84\xa6k\xe2\x84\xaak\xcf\x89' , 'k\xcf\x89\xe2\x84\xaakk\xe2\x84\xa6' ) 66call EQ ( 'Abc\x80' , 'AbC\x80' ) 67call LT ( 'Abc\x80' , 'AbC\x81' ) 68call LT ( 'Abc' , 'AbC\x80' ) 69call LT ( 'abc\x80DEF' , 'abc\x80def' ) " case folding stops at the first bad character 70call LT ( '\xc3XYZ' , '\xc3xyz' ) 71call EQ ( '\xef\xbc\xba' , '\xef\xbd\x9a' ) " FF3A (upper), FF5A (lower) 72call 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 73call LT ( '\xc3' , '\xc3\x83' ) 74call EQ ( '\xc3\xa3xYz' , '\xc3\x83XyZ' ) 75for n in range ( 0x60 , 0xFF ) 76call LT ( printf ( 'xYz\x%.2X' , n - 1 ), printf ( 'XyZ\x%.2X' , n )) 77endfor 78for n in range ( 0x80 , 0xBF ) 79call EQ ( printf ( 'xYz\xc2\x%.2XUvW' , n ), printf ( 'XyZ\xc2\x%.2XuVw' , n )) 80endfor 81for n in range ( 0xC0 , 0xFF ) 82call LT ( printf ( 'xYz\xc2\x%.2XUvW' , n ), printf ( 'XyZ\xc2\x%.2XuVw' , n )) 83endfor 84endfunc 85 86" test that g~ap changes one paragraph only. 87func Test_gap () 88new 89" setup text 90call feedkeys ( "iabcd\<cr>\<cr>defg" , "tx" ) 91" modify only first line 92call feedkeys ( "gg0g~ap" , "tx" ) 93call assert_equal ([ "ABCD" , "" , "defg" ], getline ( 1 , 3 )) 94endfunc 95 96" test that g~, ~ and gU correctly upper-cases ß 97func Test_uppercase_sharp_ss () 98new 99call setline ( 1 , repeat ([ 'ß' ], 4 )) 100 101call cursor ( 1 , 1 ) 102norm ! ~ 103call assert_equal ( 'ẞ' , getline ( line ( '.' ))) 104norm ! ~ 105call assert_equal ( 'ß' , getline ( line ( '.' ))) 106 107call cursor ( 2 , 1 ) 108norm ! g~l 109call assert_equal ( 'ẞ' , getline ( line ( '.' ))) 110norm ! g~l 111call assert_equal ( 'ß' , getline ( line ( '.' ))) 112 113call cursor ( 3 , 1 ) 114norm ! gUl 115call assert_equal ( 'ẞ' , getline ( line ( '.' ))) 116norm ! vgU 117call assert_equal ( 'ẞ' , getline ( line ( '.' ))) 118norm ! vgu 119call assert_equal ( 'ß' , getline ( line ( '.' ))) 120norm ! gul 121call assert_equal ( 'ß' , getline ( line ( '.' ))) 122 123call cursor ( 4 , 1 ) 124norm ! vgU 125call assert_equal ( 'ẞ' , getline ( line ( '.' ))) 126norm ! vgu 127call assert_equal ( 'ß' , getline ( line ( '.' ))) 128bw ! 129endfunc 130 131" vim: shiftwidth=2 sts=2 expandtab