robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Tests for digraphs 2 3source check.vim 4CheckFeature digraphs 5source term_util.vim 6 7func Put_Dig ( chars ) 8exe "norm! o\<c-k>" . a: chars 9endfu 10 11func Put_Dig_BS ( char1 , char2 ) 12exe "norm! o" . a: char1 . "\<bs>" . a: char2 13endfu 14 15func Test_digraphs () 16new 17call Put_Dig ( "00" ) 18call assert_equal ( "∞" , getline ( '.' )) 19" not a digraph 20call Put_Dig ( "el" ) 21call assert_equal ( "l" , getline ( '.' )) 22call Put_Dig ( "ht" ) 23call assert_equal ( "þ" , getline ( '.' )) 24" digraph "ab" is the same as "ba" 25call Put_Dig ( "ab" ) 26call Put_Dig ( "ba" ) 27call assert_equal ([ "ば" , "ば" ], getline ( line ( '.' ) - 1 , line ( '.' ))) 28" Euro sign 29call Put_Dig ( "e=" ) 30call Put_Dig ( "=e" ) 31call Put_Dig ( "Eu" ) 32call Put_Dig ( "uE" ) 33call assert_equal ([ 'е' ] + repeat ([ "€" ], 3 ), getline ( line ( '.' ) - 3 , line ( '.' ))) 34" Rouble sign 35call Put_Dig ( "R=" ) 36call Put_Dig ( "=R" ) 37call Put_Dig ( "=P" ) 38call Put_Dig ( "P=" ) 39call assert_equal ([ 'Р' ] + repeat ([ "₽" ], 2 ) + [ 'П' ], getline ( line ( '.' ) - 3 , line ( '.' ))) 40" Quadruple prime 41call Put_Dig ( "'4" ) 42call assert_equal ( "⁗" , getline ( '.' )) 43" APPROACHES THE LIMIT 44call Put_Dig ( ".=" ) 45call assert_equal ( "≐" , getline ( '.' )) 46" Not a digraph 47call Put_Dig ( "a\<bs>" ) 48call Put_Dig ( "\<bs>a" ) 49call assert_equal ([ "<BS>" , "<BS>a" ], getline ( line ( '.' ) - 1 , line ( '.' ))) 50" Grave 51call Put_Dig ( "a!" ) 52call Put_Dig ( "!e" ) 53call Put_Dig ( "b!" ) " not defined 54call assert_equal ([ "à" , "è" , "!" ], getline ( line ( '.' ) - 2 , line ( '.' ))) 55" Acute accent 56call Put_Dig ( "a'" ) 57call Put_Dig ( "'e" ) 58call Put_Dig ( "b'" ) " not defined 59call assert_equal ([ "á" , "é" , "'" ], getline ( line ( '.' ) - 2 , line ( '.' ))) 60" Circumflex 61call Put_Dig ( "a>" ) 62call Put_Dig ( ">e" ) 63call Put_Dig ( "b>" ) " not defined 64call assert_equal ([ 'â' , 'ê' , '>' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 65" Tilde 66call Put_Dig ( "o~" ) 67call Put_Dig ( "~u" ) " not defined 68call Put_Dig ( "z~" ) " not defined 69call assert_equal ([ 'õ' , 'u' , '~' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 70" Tilde 71call Put_Dig ( "o?" ) 72call Put_Dig ( "?u" ) 73call Put_Dig ( "z?" ) " not defined 74call assert_equal ([ 'õ' , 'ũ' , '?' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 75" Macron 76call Put_Dig ( "o-" ) 77call Put_Dig ( "-u" ) 78call Put_Dig ( "z-" ) " not defined 79call assert_equal ([ 'ō' , 'ū' , '-' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 80" Breve 81call Put_Dig ( "o(" ) 82call Put_Dig ( "(u" ) 83call Put_Dig ( "z(" ) " not defined 84call assert_equal ([ 'ŏ' , 'ŭ' , '(' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 85" Dot above 86call Put_Dig ( "b." ) 87call Put_Dig ( ".e" ) 88call Put_Dig ( "a." ) " not defined 89call assert_equal ([ 'ḃ' , 'ė' , '.' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 90" Diaeresis 91call Put_Dig ( "a:" ) 92call Put_Dig ( ":u" ) 93call Put_Dig ( "b:" ) " not defined 94call assert_equal ([ 'ä' , 'ü' , ':' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 95" Cedilla 96call Put_Dig ( "'," ) 97call Put_Dig ( ",C" ) 98call Put_Dig ( "b," ) " not defined 99call assert_equal ([ '¸' , 'Ç' , ',' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 100" Underline 101call Put_Dig ( "B_" ) 102call Put_Dig ( "_t" ) 103call Put_Dig ( "a_" ) " not defined 104call assert_equal ([ 'Ḇ' , 'ṯ' , '_' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 105" Stroke 106call Put_Dig ( "j/" ) 107call Put_Dig ( "/l" ) 108call Put_Dig ( "b/" ) " not defined 109call assert_equal ([ '/' , 'ł' , '/' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 110" Double acute 111call Put_Dig ( 'O"' ) 112call Put_Dig ( '"y' ) 113call Put_Dig ( 'b"' ) " not defined 114call assert_equal ([ 'Ő' , 'ÿ' , '"' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 115" Ogonek 116call Put_Dig ( 'u;' ) 117call Put_Dig ( ';E' ) 118call Put_Dig ( 'b;' ) " not defined 119call assert_equal ([ 'ų' , 'Ę' , ';' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 120" Caron 121call Put_Dig ( 'u<' ) 122call Put_Dig ( '<E' ) 123call Put_Dig ( 'b<' ) " not defined 124call assert_equal ([ 'ǔ' , 'Ě' , '<' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 125" Ring above 126call Put_Dig ( 'u0' ) 127call Put_Dig ( '0E' ) " not defined 128call Put_Dig ( 'b0' ) " not defined 129call assert_equal ([ 'ů' , 'E' , '0' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 130" Hook 131call Put_Dig ( 'u2' ) 132call Put_Dig ( '2E' ) 133call Put_Dig ( 'b2' ) " not defined 134call assert_equal ([ 'ủ' , 'Ẻ' , '2' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 135" Horn 136call Put_Dig ( 'u9' ) 137call Put_Dig ( '9E' ) " not defined 138call Put_Dig ( 'b9' ) " not defined 139call assert_equal ([ 'ư' , 'E' , '9' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 140" Cyrillic 141call Put_Dig ( 'u=' ) 142call Put_Dig ( '=b' ) 143call Put_Dig ( '=_' ) 144call assert_equal ([ 'у' , 'б' , '〓' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 145" Greek 146call Put_Dig ( 'u*' ) 147call Put_Dig ( '*b' ) 148call Put_Dig ( '*_' ) 149call assert_equal ([ 'υ' , 'β' , '々' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 150" Greek/Cyrillic special 151call Put_Dig ( 'u%' ) 152call Put_Dig ( '%b' ) " not defined 153call Put_Dig ( '%_' ) " not defined 154call assert_equal ([ 'ύ' , 'b' , '_' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 155" Arabic 156call Put_Dig ( 'u+' ) 157call Put_Dig ( '+b' ) 158call Put_Dig ( '+_' ) " japanese industrial symbol 159call assert_equal ([ '+' , 'ب' , '〄' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 160" Hebrew 161call Put_Dig ( 'Q+' ) 162call Put_Dig ( '+B' ) 163call Put_Dig ( '+X' ) 164call assert_equal ([ 'ק' , 'ב' , 'ח' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 165" Latin 166call Put_Dig ( 'a3' ) 167call Put_Dig ( 'A3' ) 168call Put_Dig ( '3X' ) 169call assert_equal ([ 'ǣ' , 'Ǣ' , 'X' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 170" Bopomofo 171call Put_Dig ( 'a4' ) 172call Put_Dig ( 'A4' ) 173call Put_Dig ( '4X' ) 174call assert_equal ([ 'ㄚ' , '4' , 'X' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 175" Hiragana 176call Put_Dig ( 'a5' ) 177call Put_Dig ( 'A5' ) 178call Put_Dig ( '5X' ) 179call assert_equal ([ 'あ' , 'ぁ' , 'X' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 180" Katakana 181call Put_Dig ( 'a6' ) 182call Put_Dig ( 'A6' ) 183call Put_Dig ( '6X' ) 184call assert_equal ([ 'ァ' , 'ア' , 'X' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 185" Superscripts 186call Put_Dig ( '1S' ) 187call Put_Dig ( '2S' ) 188call Put_Dig ( '3S' ) 189call assert_equal ([ '¹' , '²' , '³' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 190" Subscripts 191call Put_Dig ( '1s' ) 192call Put_Dig ( '2s' ) 193call Put_Dig ( '3s' ) 194call assert_equal ([ '₁' , '₂' , '₃' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 195" Eszet (only lowercase) 196call Put_Dig ( "ss" ) 197call Put_Dig ( "SS" ) " start of string 198call assert_equal ([ "ß" , "" ], getline ( line ( '.' ) - 1 , line ( '.' ))) 199" High bit set 200call Put_Dig ( "a " ) 201call Put_Dig ( " A" ) 202call assert_equal ([ 'á' , 'Á' ], getline ( line ( '.' ) - 1 , line ( '.' ))) 203" Escape is not part of a digraph 204call Put_Dig ( "a\<esc>" ) 205call Put_Dig ( "\<esc>A" ) 206call assert_equal ([ '' , 'A' ], getline ( line ( '.' ) - 1 , line ( '.' ))) 207" define some custom digraphs 208" old: 00 ∞ 209" old: el l 210digraph 00 9216 211digraph el 0252 212call Put_Dig ( "00" ) 213call Put_Dig ( "el" ) 214" Reset digraphs 215digraph 00 8734 216digraph el 108 217call Put_Dig ( "00" ) 218call Put_Dig ( "el" ) 219call assert_equal ([ '␀' , 'ü' , '∞' , 'l' ], getline ( line ( '.' ) - 3 , line ( '.' ))) 220call assert_fails ( 'exe "digraph a\<Esc> 100"' , 'E104:' ) 221call assert_fails ( 'exe "digraph \<Esc>a 100"' , 'E104:' ) 222call assert_fails ( 'digraph xy z' , 'E39:' ) 223call assert_fails ( 'digraph x' , 'E1214:' ) 224bw ! 225endfunc 226 227func Test_digraphs_option () 228" reset whichwrap option, so that testing <esc><bs>A works, 229" without moving up a line 230set digraph ww = 231new 232call Put_Dig_BS ( "0" , "0" ) 233call assert_equal ( "∞" , getline ( '.' )) 234" not a digraph 235call Put_Dig_BS ( "e" , "l" ) 236call assert_equal ( "l" , getline ( '.' )) 237call Put_Dig_BS ( "h" , "t" ) 238call assert_equal ( "þ" , getline ( '.' )) 239" digraph "ab" is the same as "ba" 240call Put_Dig_BS ( "a" , "b" ) 241call Put_Dig_BS ( "b" , "a" ) 242call assert_equal ([ "ば" , "ば" ], getline ( line ( '.' ) - 1 , line ( '.' ))) 243" Euro sign 244call Put_Dig_BS ( "e" , "=" ) 245call Put_Dig_BS ( "=" , "e" ) 246call Put_Dig_BS ( "E" , "u" ) 247call Put_Dig_BS ( "u" , "E" ) 248call assert_equal ([ 'е' ] + repeat ([ "€" ], 3 ), getline ( line ( '.' ) - 3 , line ( '.' ))) 249" Rouble sign 250call Put_Dig_BS ( "R" , "=" ) 251call Put_Dig_BS ( "=" , "R" ) 252call Put_Dig_BS ( "=" , "P" ) 253call Put_Dig_BS ( "P" , "=" ) 254call assert_equal ([ 'Р' ] + repeat ([ "₽" ], 2 ) + [ 'П' ], getline ( line ( '.' ) - 3 , line ( '.' ))) 255" Not a digraph: this is different from <c-k>! 256let _bs = & bs 257set bs = 258call Put_Dig_BS ( "a" , "\<bs>" ) 259call Put_Dig_BS ( "\<bs>" , "a" ) 260call assert_equal ([ '' , 'a' ], getline ( line ( '.' ) - 1 , line ( '.' ))) 261let & bs = _bs 262" Grave 263call Put_Dig_BS ( "a" , "!" ) 264call Put_Dig_BS ( "!" , "e" ) 265call Put_Dig_BS ( "b" , "!" ) " not defined 266call assert_equal ([ "à" , "è" , "!" ], getline ( line ( '.' ) - 2 , line ( '.' ))) 267" Acute accent 268call Put_Dig_BS ( "a" , "'" ) 269call Put_Dig_BS ( "'" , "e" ) 270call Put_Dig_BS ( "b" , "'" ) " not defined 271call assert_equal ([ "á" , "é" , "'" ], getline ( line ( '.' ) - 2 , line ( '.' ))) 272" Cicumflex 273call Put_Dig_BS ( "a" , ">" ) 274call Put_Dig_BS ( ">" , "e" ) 275call Put_Dig_BS ( "b" , ">" ) " not defined 276call assert_equal ([ 'â' , 'ê' , '>' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 277" Tilde 278call Put_Dig_BS ( "o" , "~" ) 279call Put_Dig_BS ( "~" , "u" ) " not defined 280call Put_Dig_BS ( "z" , "~" ) " not defined 281call assert_equal ([ 'õ' , 'u' , '~' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 282" Tilde 283call Put_Dig_BS ( "o" , "?" ) 284call Put_Dig_BS ( "?" , "u" ) 285call Put_Dig_BS ( "z" , "?" ) " not defined 286call assert_equal ([ 'õ' , 'ũ' , '?' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 287" Macron 288call Put_Dig_BS ( "o" , "-" ) 289call Put_Dig_BS ( "-" , "u" ) 290call Put_Dig_BS ( "z" , "-" ) " not defined 291call assert_equal ([ 'ō' , 'ū' , '-' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 292" Breve 293call Put_Dig_BS ( "o" , "(" ) 294call Put_Dig_BS ( "(" , "u" ) 295call Put_Dig_BS ( "z" , "(" ) " not defined 296call assert_equal ([ 'ŏ' , 'ŭ' , '(' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 297" Dot above 298call Put_Dig_BS ( "b" , "." ) 299call Put_Dig_BS ( "." , "e" ) 300call Put_Dig_BS ( "a" , "." ) " not defined 301call assert_equal ([ 'ḃ' , 'ė' , '.' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 302" Diaeresis 303call Put_Dig_BS ( "a" , ":" ) 304call Put_Dig_BS ( ":" , "u" ) 305call Put_Dig_BS ( "b" , ":" ) " not defined 306call assert_equal ([ 'ä' , 'ü' , ':' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 307" Cedilla 308call Put_Dig_BS ( "'" , "," ) 309call Put_Dig_BS ( "," , "C" ) 310call Put_Dig_BS ( "b" , "," ) " not defined 311call assert_equal ([ '¸' , 'Ç' , ',' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 312" Underline 313call Put_Dig_BS ( "B" , "_" ) 314call Put_Dig_BS ( "_" , "t" ) 315call Put_Dig_BS ( "a" , "_" ) " not defined 316call assert_equal ([ 'Ḇ' , 'ṯ' , '_' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 317" Stroke 318call Put_Dig_BS ( "j" , "/" ) 319call Put_Dig_BS ( "/" , "l" ) 320call Put_Dig_BS ( "b" , "/" ) " not defined 321call assert_equal ([ '/' , 'ł' , '/' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 322" Double acute 323call Put_Dig_BS ( 'O' , '"' ) 324call Put_Dig_BS ( '"' , 'y' ) 325call Put_Dig_BS ( 'b' , '"' ) " not defined 326call assert_equal ([ 'Ő' , 'ÿ' , '"' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 327" Ogonek 328call Put_Dig_BS ( 'u' , ';' ) 329call Put_Dig_BS ( ';' , 'E' ) 330call Put_Dig_BS ( 'b' , ';' ) " not defined 331call assert_equal ([ 'ų' , 'Ę' , ';' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 332" Caron 333call Put_Dig_BS ( 'u' , '<' ) 334call Put_Dig_BS ( '<' , 'E' ) 335call Put_Dig_BS ( 'b' , '<' ) " not defined 336call assert_equal ([ 'ǔ' , 'Ě' , '<' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 337" Ring above 338call Put_Dig_BS ( 'u' , '0' ) 339call Put_Dig_BS ( '0' , 'E' ) " not defined 340call Put_Dig_BS ( 'b' , '0' ) " not defined 341call assert_equal ([ 'ů' , 'E' , '0' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 342" Hook 343call Put_Dig_BS ( 'u' , '2' ) 344call Put_Dig_BS ( '2' , 'E' ) 345call Put_Dig_BS ( 'b' , '2' ) " not defined 346call assert_equal ([ 'ủ' , 'Ẻ' , '2' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 347" Horn 348call Put_Dig_BS ( 'u' , '9' ) 349call Put_Dig_BS ( '9' , 'E' ) " not defined 350call Put_Dig_BS ( 'b' , '9' ) " not defined 351call assert_equal ([ 'ư' , 'E' , '9' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 352" Cyrillic 353call Put_Dig_BS ( 'u' , '=' ) 354call Put_Dig_BS ( '=' , 'b' ) 355call Put_Dig_BS ( '=' , '_' ) 356call assert_equal ([ 'у' , 'б' , '〓' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 357" Greek 358call Put_Dig_BS ( 'u' , '*' ) 359call Put_Dig_BS ( '*' , 'b' ) 360call Put_Dig_BS ( '*' , '_' ) 361call assert_equal ([ 'υ' , 'β' , '々' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 362" Greek/Cyrillic special 363call Put_Dig_BS ( 'u' , '%' ) 364call Put_Dig_BS ( '%' , 'b' ) " not defined 365call Put_Dig_BS ( '%' , '_' ) " not defined 366call assert_equal ([ 'ύ' , 'b' , '_' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 367" Arabic 368call Put_Dig_BS ( 'u' , '+' ) 369call Put_Dig_BS ( '+' , 'b' ) 370call Put_Dig_BS ( '+' , '_' ) " japanese industrial symbol 371call assert_equal ([ '+' , 'ب' , '〄' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 372" Hebrew 373call Put_Dig_BS ( 'Q' , '+' ) 374call Put_Dig_BS ( '+' , 'B' ) 375call Put_Dig_BS ( '+' , 'X' ) 376call assert_equal ([ 'ק' , 'ב' , 'ח' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 377" Latin 378call Put_Dig_BS ( 'a' , '3' ) 379call Put_Dig_BS ( 'A' , '3' ) 380call Put_Dig_BS ( '3' , 'X' ) 381call assert_equal ([ 'ǣ' , 'Ǣ' , 'X' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 382" Bopomofo 383call Put_Dig_BS ( 'a' , '4' ) 384call Put_Dig_BS ( 'A' , '4' ) 385call Put_Dig_BS ( '4' , 'X' ) 386call assert_equal ([ 'ㄚ' , '4' , 'X' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 387" Hiragana 388call Put_Dig_BS ( 'a' , '5' ) 389call Put_Dig_BS ( 'A' , '5' ) 390call Put_Dig_BS ( '5' , 'X' ) 391call assert_equal ([ 'あ' , 'ぁ' , 'X' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 392" Katakana 393call Put_Dig_BS ( 'a' , '6' ) 394call Put_Dig_BS ( 'A' , '6' ) 395call Put_Dig_BS ( '6' , 'X' ) 396call assert_equal ([ 'ァ' , 'ア' , 'X' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 397" Superscripts 398call Put_Dig_BS ( '1' , 'S' ) 399call Put_Dig_BS ( '2' , 'S' ) 400call Put_Dig_BS ( '3' , 'S' ) 401call assert_equal ([ '¹' , '²' , '³' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 402" Subscripts 403call Put_Dig_BS ( '1' , 's' ) 404call Put_Dig_BS ( '2' , 's' ) 405call Put_Dig_BS ( '3' , 's' ) 406call assert_equal ([ '₁' , '₂' , '₃' ], getline ( line ( '.' ) - 2 , line ( '.' ))) 407" Eszet (only lowercase) 408call Put_Dig_BS ( "s" , "s" ) 409call Put_Dig_BS ( "S" , "S" ) " start of string 410call assert_equal ([ "ß" , "" ], getline ( line ( '.' ) - 1 , line ( '.' ))) 411" High bit set (different from <c-k>) 412call Put_Dig_BS ( "a" , " " ) 413call Put_Dig_BS ( " " , "A" ) 414call assert_equal ([ ' ' , 'A' ], getline ( line ( '.' ) - 1 , line ( '.' ))) 415" Escape is not part of a digraph (different from <c-k>) 416call Put_Dig_BS ( "a" , "\<esc>" ) 417call Put_Dig_BS ( "\<esc>" , "A" ) 418call assert_equal ([ '' , '' ], getline ( line ( '.' ) - 1 , line ( '.' ))) 419" define some custom digraphs 420" old: 00 ∞ 421" old: el l 422digraph 00 9216 423digraph el 0252 424call Put_Dig_BS ( "0" , "0" ) 425call Put_Dig_BS ( "e" , "l" ) 426" Reset digraphs 427digraph 00 8734 428digraph el 108 429call Put_Dig_BS ( "0" , "0" ) 430call Put_Dig_BS ( "e" , "l" ) 431call assert_equal ([ '␀' , 'ü' , '∞' , 'l' ], getline ( line ( '.' ) - 3 , line ( '.' ))) 432set nodigraph ww & vim 433bw ! 434endfunc 435 436func Test_digraphs_output () 437new 438let out = execute ( ':digraph' ) 439call assert_equal ( 'Eu € 8364' , matchstr ( out , '\C\<Eu\D*8364\>' )) 440call assert_equal ( '=e € 8364' , matchstr ( out , '\C=e\D*8364\>' )) 441call assert_equal ( '=R ₽ 8381' , matchstr ( out , '\C=R\D*8381\>' )) 442call assert_equal ( '=P ₽ 8381' , matchstr ( out , '\C=P\D*8381\>' )) 443call assert_equal ( 'o: ö 246' , matchstr ( out , '\C\<o:\D*246\>' )) 444call assert_equal ( 'v4 ㄪ 12586' , matchstr ( out , '\C\<v4\D*12586\>' )) 445call assert_equal ( "'0 ˚ 730" , matchstr ( out , '\C''0\D*730\>' )) 446call assert_equal ( 'Z% Ж 1046' , matchstr ( out , '\C\<Z%\D*1046\>' )) 447call assert_equal ( 'u- ū 363' , matchstr ( out , '\C\<u-\D*363\>' )) 448call assert_equal ( 'SH ^A 1' , matchstr ( out , '\C\<SH\D*1\>' )) 449call assert_notmatch ( 'Latin supplement' , out ) 450 451let out_bang_without_custom = execute ( ':digraph!' ) 452digraph lt 60 453let out_bang_with_custom = execute ( ':digraph!' ) 454call assert_notmatch ( 'lt' , out_bang_without_custom ) 455call assert_match ( "^\n" 456 \.. "NU ^@ 10 .*\n" 457 \.. "Latin supplement\n" 458 \.. "!I ¡ 161 .*\n" 459 \.. ".*\n" 460 \.. 'Custom\n.*\<lt < 60\>' , out_bang_with_custom ) 461bw ! 462endfunc 463 464func Test_loadkeymap () 465CheckFeature keymap 466new 467set keymap = czech 468set iminsert = 0 469call feedkeys ( "o|\<c-^>|01234567890|\<esc>" , 'tx' ) 470call assert_equal ( "|'é+ěščřžýáíé'" , getline ( '.' )) 471" reset keymap and encoding option 472set keymap = 473bw ! 474endfunc 475 476func Test_digraph_cmndline () 477" Create digraph on commandline 478call feedkeys ( ":\"\<c-k>Eu\<cr>" , 'xt' ) 479call assert_equal ( '"€' , @:) 480 481" Canceling a CTRL-K on the cmdline 482call feedkeys ( ":\"a\<c-k>\<esc>b\<cr>" , 'xt' ) 483call assert_equal ( '"ab' , @:) 484endfunc 485 486func Test_show_digraph () 487new 488call Put_Dig ( "e=" ) 489call assert_equal ( "\n<е> 1077, Hex 0435, Oct 2065, Digr e=" , execute ( 'ascii' )) 490bwipe ! 491endfunc 492 493func Test_show_digraph_cp1251 () 494throw 'skipped: Nvim supports ''utf8'' encoding only' 495new 496set encoding = cp1251 497call Put_Dig ( "='" ) 498call assert_equal ( "\n<\xfa> <|z> <M-z> 250, Hex fa, Oct 372, Digr ='" , execute ( 'ascii' )) 499set encoding = utf-8 500bwipe ! 501endfunc 502 503" Test for error in a keymap file 504func Test_loadkeymap_error () 505CheckFeature keymap 506call assert_fails ( 'loadkeymap' , 'E105:' ) 507call writefile ([ 'loadkeymap' , 'a' ], 'Xkeymap' , 'D' ) 508call assert_fails ( 'source Xkeymap' , 'E791:' ) 509endfunc 510 511" Test for ":loadkeymap" in a block that is not executed: it reads the rest of 512" the script, so that rest, the "endif" with it, is thrown away instead of 513" being read as commands. 514func Test_loadkeymap_skipped () 515CheckFeature keymap 516call writefile ([ 'if 0' , ' loadkeymap' , ' a b' , 'endif' ], 'Xkeymap' , 'D' ) 517call assert_fails ( 'source Xkeymap' , 'E171:' ) 518endfunc 519 520" Test for the characters displayed on the screen when entering a digraph 521func Test_entering_digraph () 522CheckRunVimInTerminal 523let buf = RunVimInTerminal ( '' , { 'rows' : 6 }) 524call term_sendkeys ( buf , "i\<C-K>" ) 525call WaitForAssert ({ ->assert_equal ( '?' , term_getline ( buf , 1 ))}, 1000 ) 526call term_sendkeys ( buf , "1" ) 527call WaitForAssert ({ ->assert_equal ( '1' , term_getline ( buf , 1 ))}, 1000 ) 528call term_sendkeys ( buf , "2" ) 529call WaitForAssert ({ ->assert_equal ( '½' , term_getline ( buf , 1 ))}, 1000 ) 530call StopVimInTerminal ( buf ) 531endfunc 532 533func Test_digraph_set_function () 534new 535call digraph_set ( 'aa' , 'あ' ) 536call Put_Dig ( 'aa' ) 537call assert_equal ( 'あ' , getline ( '$' )) 538call digraph_set ( ' i' , 'い' ) 539call Put_Dig ( ' i' ) 540call assert_equal ( 'い' , getline ( '$' )) 541call digraph_set ( ' ' , 'う' ) 542call Put_Dig ( ' ' ) 543call assert_equal ( 'う' , getline ( '$' )) 544 545eval 'aa' ->digraph_set ( 'え' ) 546call Put_Dig ( 'aa' ) 547call assert_equal ( 'え' , getline ( '$' )) 548 549call assert_fails ( 'call digraph_set("aaa", "あ")' , 'E1214: Digraph must be just two characters: aaa' ) 550call assert_fails ( 'call digraph_set("b", "あ")' , 'E1214: Digraph must be just two characters: b' ) 551call assert_fails ( 'call digraph_set("あ", "あ")' , 'E1214: Digraph must be just two characters: あ' ) 552call assert_fails ( 'call digraph_set("aa", "ああ")' , 'E1215: Digraph must be one character: ああ' ) 553call assert_fails ( 'call digraph_set("aa", "か" .. nr2char(0x3099))' , 'E1215: Digraph must be one character: か' .. nr2char ( 0x3099 )) 554call assert_fails ( 'call digraph_set(v:_null_string, "い")' , 'E1214: Digraph must be just two characters' ) 555call assert_fails ( 'call digraph_set("aa", 0z10)' , 'E976: Using a Blob as a String' ) 556bwipe ! 557endfunc 558 559func Test_digraph_get_function () 560" Built-in digraphs 561call assert_equal ( '∞' , digraph_get ( '00' )) 562 563" User-defined digraphs 564call digraph_set ( 'aa' , 'あ' ) 565call digraph_set ( ' i' , 'い' ) 566call digraph_set ( ' ' , 'う' ) 567call assert_equal ( 'あ' , digraph_get ( 'aa' )) 568call assert_equal ( 'あ' , 'aa' ->digraph_get ()) 569call assert_equal ( 'い' , digraph_get ( ' i' )) 570call assert_equal ( 'う' , digraph_get ( ' ' )) 571call assert_fails ( 'call digraph_get("aaa")' , 'E1214: Digraph must be just two characters: aaa' ) 572call assert_fails ( 'call digraph_get("b")' , 'E1214: Digraph must be just two characters: b' ) 573call assert_fails ( 'call digraph_get(v:_null_string)' , 'E1214: Digraph must be just two characters:' ) 574call assert_fails ( 'call digraph_get(0z10)' , 'E976: Using a Blob as a String' ) 575endfunc 576 577func Test_digraph_get_function_encode () 578throw 'Skipped: Nvim does not support setting encoding=japan' 579CheckFeature iconv 580 581let testcases = { 582 \'00' : '∞' , 583 \'aa' : 'あ' , 584 \} 585for [ key , ch ] in items ( testcases ) 586call digraph_set ( key , ch ) 587set encoding = japan 588call assert_equal ( iconv ( ch , 'utf-8' , 'japan' ), digraph_get ( key )) 589set encoding = utf-8 590endfor 591endfunc 592 593func Test_digraph_setlist_function () 594call digraph_setlist ([[ 'aa' , 'き' ], [ 'bb' , 'く' ]]) 595call assert_equal ( 'き' , digraph_get ( 'aa' )) 596call assert_equal ( 'く' , digraph_get ( 'bb' )) 597 598call assert_fails ( 'call digraph_setlist([[]])' , 'E1216:' ) 599call assert_fails ( 'call digraph_setlist([["aa", "b", "cc"]])' , 'E1216:' ) 600call assert_fails ( 'call digraph_setlist([["あ", "あ"]])' , 'E1214: Digraph must be just two characters: あ' ) 601call assert_fails ( 'call digraph_setlist([v:_null_list])' , 'E1216:' ) 602call assert_fails ( 'call digraph_setlist({})' , 'E1216:' ) 603call assert_fails ( 'call digraph_setlist([{}])' , 'E1216:' ) 604call assert_true ( digraph_setlist ( v: _null_list )) 605endfunc 606 607func Test_digraph_getlist_function () 608" Make sure user-defined digraphs are defined 609call digraph_setlist ([[ 'aa' , 'き' ], [ 'bb' , 'く' ]]) 610 611for pair in digraph_getlist ( 1 ) 612call assert_equal ( pair [ 1 ], digraph_get ( pair [ 0 ])) 613endfor 614 615" We don't know how many digraphs are registered before, so check the number 616" of digraphs returned. 617call assert_equal ( digraph_getlist () ->len (), digraph_getlist ( 0 ) ->len ()) 618call assert_notequal ( digraph_getlist () ->len (), digraph_getlist ( 1 ) ->len ()) 619call assert_equal ( digraph_getlist () ->len (), digraph_getlist ( v: false ) ->len ()) 620call assert_notequal ( digraph_getlist () ->len (), digraph_getlist ( v: true ) ->len ()) 621 622call assert_fails ( 'call digraph_getlist(0z12)' , 'E1212: Bool required for argument 1' ) 623endfunc 624 625func Test_digraph_angle_bracket_patch () 626" Ensure that the deprecated angle brackets 2329/232A ('</','/>') are not used 627call assert_notequal ( '〈' , digraph_get ( '</' )) 628call assert_notequal ( '〉' , digraph_get ( '/>' )) 629" Ensure that the CJK angle brackets 3008/3009 ('</','/>') are used 630call assert_equal ( '〈' , digraph_get ( '</' )) 631call assert_equal ( '〉' , digraph_get ( '/>' )) 632" Ensure that the mathematical angle brackets 27E8/27E9 ('<[',']>') are defined 633call assert_equal ( '⟨' , digraph_get ( '<[' )) 634call assert_equal ( '⟩' , digraph_get ( ']>' )) 635endfunc 636 637" vim: shiftwidth=2 sts=2 expandtab