robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Test for multibyte text formatting. 2-- Also test, that 'mps' with multibyte chars works. 3-- And test "ra" on multibyte characters. 4-- Also test byteidx() and byteidxcomp() 5 6local t =require ( 'test.testutil' ) 7local n =require ( 'test.functional.testnvim' )() 8 9local describe , it , before_each =t . describe , t . it , t . before_each 10local feed , insert , eq , eval , clear , feed_command , expect = 11n . feed , n . insert , t . eq , n . eval , n . clear , n . feed_command , n . expect 12 13describe ( 'multibyte text' , function () 14before_each ( clear ) 15 16it ( 'formatting with "set fo=t"' , function () 17insert ( [[ 18{ 19XYZ 20abc XYZ 21}]] ) 22feed_command ( '/^{/+1' ) 23feed_command ( 'set tw=2 fo=t' ) 24feed ( 'gqgqjgqgqo<cr>' ) 25feed ( 'XYZ<cr>' ) 26feed ( 'abc XYZ<esc><esc>' ) 27expect ( [[ 28{ 29XYZ 30abc 31XYZ 32 33XYZ 34abc 35XYZ 36}]] ) 37end ) 38 39it ( 'formatting with "set fo=tm"' , function () 40insert ( [[ 41{ 42X 43Xa 44X a 45XY 46X Y 47}]] ) 48feed_command ( '/^{/+1' ) 49feed_command ( 'set tw=1 fo=tm' ) 50feed ( 'gqgqjgqgqjgqgqjgqgqjgqgqo<cr>' ) 51feed ( 'X<cr>' ) 52feed ( 'Xa<cr>' ) 53feed ( 'X a<cr>' ) 54feed ( 'XY<cr>' ) 55feed ( 'X Y<esc><esc>' ) 56expect ( [[ 57{ 58X 59X 60a 61X 62a 63X 64Y 65X 66Y 67 68X 69X 70a 71X 72a 73X 74Y 75X 76Y 77}]] ) 78end ) 79 80it ( 'formatting with "set fo=tm" (part 2)' , function () 81insert ( [[ 82{ 83X 84Xa 85X a 86XY 87X Y 88aX 89abX 90abcX 91abX c 92abXY 93}]] ) 94feed_command ( '/^{/+1' ) 95feed_command ( 'set tw=2 fo=tm' ) 96feed ( 'gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>' ) 97feed ( 'X<cr>' ) 98feed ( 'Xa<cr>' ) 99feed ( 'X a<cr>' ) 100feed ( 'XY<cr>' ) 101feed ( 'X Y<cr>' ) 102feed ( 'aX<cr>' ) 103feed ( 'abX<cr>' ) 104feed ( 'abcX<cr>' ) 105feed ( 'abX c<cr>' ) 106feed ( 'abXY<esc><esc>' ) 107expect ( [[ 108{ 109X 110X 111a 112X 113a 114X 115Y 116X 117Y 118a 119X 120ab 121X 122abc 123X 124ab 125X 126c 127ab 128X 129Y 130 131X 132X 133a 134X 135a 136X 137Y 138X 139Y 140a 141X 142ab 143X 144abc 145X 146ab 147X 148c 149ab 150X 151Y 152}]] ) 153end ) 154 155it ( 'formatting with "set ai fo=tm"' , function () 156insert ( [[ 157{ 158X 159Xa 160}]] ) 161feed_command ( '/^{/+1' ) 162feed_command ( 'set ai tw=2 fo=tm' ) 163feed ( 'gqgqjgqgqo<cr>' ) 164feed ( 'X<cr>' ) 165feed ( 'Xa<esc>' ) 166expect ( [[ 167{ 168X 169X 170a 171 172X 173X 174a 175}]] ) 176end ) 177 178it ( 'formatting with "set ai fo=tm" (part 2)' , function () 179insert ( [[ 180{ 181X 182Xa 183}]] ) 184feed_command ( '/^{/+1' ) 185feed_command ( 'set noai tw=2 fo=tm' ) 186feed ( 'gqgqjgqgqo<cr>' ) 187feed ( ' X<cr>' ) 188feed ( ' Xa<esc>' ) 189expect ( [[ 190{ 191X 192X 193a 194 195X 196X 197a 198}]] ) 199end ) 200 201it ( 'formatting with "set fo=cqm" and multibyte comments' , function () 202insert ( [[ 203{ 204X 205Xa 206XaY 207XY 208XYZ 209X Y 210X YZ 211XX 212XXa 213XXY 214}]] ) 215feed_command ( '/^{/+1' ) 216feed_command ( 'set tw=2 fo=cqm comments=n:X' ) 217feed ( 'gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>' ) 218feed ( 'X<cr>' ) 219feed ( 'Xa<cr>' ) 220feed ( 'XaY<cr>' ) 221feed ( 'XY<cr>' ) 222feed ( 'XYZ<cr>' ) 223feed ( 'X Y<cr>' ) 224feed ( 'X YZ<cr>' ) 225feed ( 'XX<cr>' ) 226feed ( 'XXa<cr>' ) 227feed ( 'XXY<esc><esc>' ) 228expect ( [[ 229{ 230X 231Xa 232Xa 233XY 234XY 235XY 236XZ 237X Y 238X Y 239X Z 240XX 241XXa 242XXY 243 244X 245Xa 246Xa 247XY 248XY 249XY 250XZ 251X Y 252X Y 253X Z 254XX 255XXa 256XXY 257}]] ) 258end ) 259 260it ( 'formatting in replace mode' , function () 261insert ( [[ 262{ 263 264}]] ) 265feed_command ( '/^{/+1' ) 266feed_command ( 'set tw=2 fo=tm' ) 267feed ( 'RXa<esc>' ) 268expect ( [[ 269{ 270X 271a 272}]] ) 273end ) 274 275it ( "as values of 'mps'" , function () 276insert ( [[ 277{ 278‘ two three ’ four 279}]] ) 280feed_command ( '/^{/+1' ) 281feed_command ( 'set mps+=‘:’' ) 282feed ( 'd%<cr>' ) 283expect ( [[ 284{ 285four 286}]] ) 287end ) 288 289it ( 'can be replaced with r' , function () 290insert ( [[ 291abba 292aab]] ) 293feed ( 'gg0Vjra<cr>' ) 294expect ( [[ 295aaaa 296aaa]] ) 297end ) 298 299it ( "doesn't interfere with 'whichwrap'" , function () 300insert ( [[ 301á 302x]] ) 303feed_command ( 'set whichwrap+=h' ) 304feed_command ( '/^x' ) 305feed ( 'dh' ) 306expect ( [[ 307áx]] ) 308end ) 309 310it ( 'can be queried with byteidx() and byteidxcomp()' , function () 311-- One char of two bytes. 312feed_command ( "let a = '.é.'" ) 313-- Normal e with composing char. 314feed_command ( "let b = '.é.'" ) 315eq ( 0 , eval ( 'byteidx(a, 0)' )) 316eq ( 1 , eval ( 'byteidx(a, 1)' )) 317eq ( 3 , eval ( 'byteidx(a, 2)' )) 318eq ( 4 , eval ( 'byteidx(a, 3)' )) 319eq ( - 1 , eval ( 'byteidx(a, 4)' )) 320eq ( 0 , eval ( 'byteidx(b, 0)' )) 321eq ( 1 , eval ( 'byteidx(b, 1)' )) 322eq ( 4 , eval ( 'byteidx(b, 2)' )) 323eq ( 5 , eval ( 'byteidx(b, 3)' )) 324eq ( - 1 , eval ( 'byteidx(b, 4)' )) 325eq ( 0 , eval ( 'byteidxcomp(a, 0)' )) 326eq ( 1 , eval ( 'byteidxcomp(a, 1)' )) 327eq ( 3 , eval ( 'byteidxcomp(a, 2)' )) 328eq ( 4 , eval ( 'byteidxcomp(a, 3)' )) 329eq ( - 1 , eval ( 'byteidxcomp(a, 4)' )) 330eq ( 0 , eval ( 'byteidxcomp(b, 0)' )) 331eq ( 1 , eval ( 'byteidxcomp(b, 1)' )) 332eq ( 2 , eval ( 'byteidxcomp(b, 2)' )) 333eq ( 4 , eval ( 'byteidxcomp(b, 3)' )) 334eq ( 5 , eval ( 'byteidxcomp(b, 4)' )) 335eq ( - 1 , eval ( 'byteidxcomp(b, 5)' )) 336end ) 337 338it ( 'correctly interact with the \zs pattern' , function () 339eq ( 'a1a2a3a' , eval ( [[substitute('123', '\zs', 'a', 'g')]] )) 340end ) 341end )