robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1-- Test for scenarios involving 'spell' 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5local Screen =require ( 'test.functional.ui.screen' ) 6 7local describe , it , before_each , pending =t . describe , t . it , t . before_each , t . pending 8local clear =n . clear 9local exec =n . exec 10local feed =n . feed 11local insert =n . insert 12local api =n . api 13local is_os =t . is_os 14 15describe ( "'spell'" , function () 16local screen 17 18before_each ( function () 19clear () 20screen =Screen . new ( 80 , 8 ) 21screen : add_extra_attr_ids { 22[ 100 ] ={ special =Screen . colors . Red , undercurl =true } , 23[ 101 ] ={ special =Screen . colors . Blue , undercurl =true } , 24[ 102 ] ={ foreground =Screen . colors . Blue , special =Screen . colors . Red , undercurl =true } , 25[ 103 ] ={ foreground =tonumber ( '0x6a0dad' ) } , 26[ 104 ] ={ foreground =Screen . colors . Red , underline =true } , 27[ 105 ] ={ foreground =Screen . colors . Blue , underline =true } , 28} 29end ) 30 31it ( 'joins long lines #7937' , function () 32if is_os ( 'openbsd' ) then 33pending ( 'FIXME #12104' , function () end ) 34return 35end 36exec ( 'set spell' ) 37insert ( [[ 38Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 39tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 40quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 41consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 42cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 43non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 44]] ) 45feed ( 'ggJJJJJJ0' ) 46screen : expect ( [[ 47{100:^Lorem} {100:ipsum} dolor sit {100:amet}, {100:consectetur} {100:adipiscing} {100:elit}, {100:sed} do {100:eiusmod} {100:tempor} {100:i}| 48{100:ncididunt} {100:ut} {100:labore} et {100:dolore} {100:magna} {100:aliqua}. {100:Ut} {100:enim} ad minim {100:veniam}, {100:quis} {100:nostru}| 49{100:d} {100:exercitation} {100:ullamco} {100:laboris} {100:nisi} {100:ut} {100:aliquip} ex ea {100:commodo} {100:consequat}. {100:Duis} {100:aut}| 50{100:e} {100:irure} dolor in {100:reprehenderit} in {100:voluptate} {100:velit} {100:esse} {100:cillum} {100:dolore} {100:eu} {100:fugiat} {100:n}| 51{100:ulla} {100:pariatur}. {100:Excepteur} {100:sint} {100:occaecat} {100:cupidatat} non {100:proident}, {100:sunt} in culpa {100:qui}| 52{100:officia} {100:deserunt} {100:mollit} {100:anim} id est {100:laborum}. | 53{1:~ }| 54| 55]] ) 56end ) 57 58-- oldtest: Test_spell_screendump() 59it ( 'has correct highlight at start of line' , function () 60exec ( [=[ 61call setline(1, [ 62\"This is some text without any spell errors. Everything", 63\"should just be black, nothing wrong here.", 64\"", 65\"This line has a sepll error. and missing caps.", 66\"And and this is the the duplication.", 67\"with missing caps here.", 68\]) 69set spell spelllang=en_nz 70]=] ) 71screen : expect ( [[ 72^This is some text without any spell errors. Everything | 73should just be black, nothing wrong here. | 74| 75This line has a {100:sepll} error. {101:and} missing caps. | 76{100:And and} this is {100:the the} duplication. | 77{101:with} missing caps here. | 78{1:~ }| 79| 80]] ) 81end ) 82 83-- oldtest: Test_spell_screendump_spellcap() 84it ( 'SpellCap highlight at start of line' , function () 85exec ( [=[ 86call setline(1, [ 87\" This line has a sepll error. and missing caps and trailing spaces. ", 88\"another missing cap here.", 89\"", 90\"and here.", 91\" ", 92\"and here." 93\]) 94set spell spelllang=en 95]=] ) 96screen : expect ( [[ 97^ This line has a {100:sepll} error. {101:and} missing caps and trailing spaces. | 98{101:another} missing cap here. | 99| 100{101:and} here. | 101| 102{101:and} here. | 103{1:~ }| 104| 105]] ) 106-- After adding word missing Cap in next line is updated 107feed ( '3GANot<Esc>' ) 108screen : expect ( [[ 109This line has a {100:sepll} error. {101:and} missing caps and trailing spaces. | 110{101:another} missing cap here. | 111No^t | 112and here. | 113| 114{101:and} here. | 115{1:~ }| 116| 117]] ) 118-- Deleting a full stop removes missing Cap in next line 119feed ( '5Gdd<C-L>k$x' ) 120screen : expect ( [[ 121This line has a {100:sepll} error. {101:and} missing caps and trailing spaces. | 122{101:another} missing cap here. | 123Not | 124and her^e | 125and here. | 126{1:~ }|*2 127| 128]] ) 129-- Undo also updates the next line (go to command line to remove message) 130feed ( 'u:<Esc>' ) 131screen : expect ( [[ 132This line has a {100:sepll} error. {101:and} missing caps and trailing spaces. | 133{101:another} missing cap here. | 134Not | 135and here^. | 136{101:and} here. | 137{1:~ }|*2 138| 139]] ) 140-- Folding an empty line does not remove Cap in next line 141feed ( 'uzfk:<Esc>' ) 142screen : expect ( [[ 143This line has a {100:sepll} error. {101:and} missing caps and trailing spaces. | 144{101:another} missing cap here. | 145Not | 146{13:^+-- 2 lines: and here.·························································}| 147{101:and} here. | 148{1:~ }|*2 149| 150]] ) 151-- Folding the end of a sentence does not remove Cap in next line 152-- and editing a line does not remove Cap in current line 153feed ( 'Jzfkk$x' ) 154screen : expect ( [[ 155This line has a {100:sepll} error. {101:and} missing caps and trailing spaces. | 156{101:another} missing cap her^e | 157{13:+-- 2 lines: Not·······························································}| 158{101:and} here. | 159{1:~ }|*3 160| 161]] ) 162-- Cap is correctly applied in the first row of a window 163feed ( '<C-E><C-L>' ) 164screen : expect ( [[ 165{101:another} missing cap her^e | 166{13:+-- 2 lines: Not·······························································}| 167{101:and} here. | 168{1:~ }|*4 169| 170]] ) 171-- Adding an empty line does not remove Cap in "mod_bot" area 172feed ( 'zbO<Esc>' ) 173screen : expect ( [[ 174This line has a {100:sepll} error. {101:and} missing caps and trailing spaces. | 175^ | 176{101:another} missing cap here | 177{13:+-- 2 lines: Not·······························································}| 178{101:and} here. | 179{1:~ }|*2 180| 181]] ) 182-- Multiple empty lines does not remove Cap in the line after 183feed ( 'O<Esc><C-L>' ) 184screen : expect ( [[ 185This line has a {100:sepll} error. {101:and} missing caps and trailing spaces. | 186^ | 187| 188{101:another} missing cap here | 189{13:+-- 2 lines: Not·······························································}| 190{101:and} here. | 191{1:~ }| 192| 193]] ) 194end ) 195 196-- oldtest: Test_spell_compatible() 197it ( [[redraws properly when using "C" and "$" is in 'cpo']] , function () 198exec ( [=[ 199call setline(1, [ 200\ "test "->repeat(20), 201\ "", 202\ "end", 203\ ]) 204set spell cpo+=$ 205]=] ) 206feed ( '51|C' ) 207screen : expect ( [[ 208{101:test} test test test test test test test test test ^test test test test test test | 209test test test test$ | 210| 211{101:end} | 212{1:~ }|*3 213{5:-- INSERT --} | 214]] ) 215feed ( 'x' ) 216screen : expect ( [[ 217{101:test} test test test test test test test test test x^est test test test test test | 218test test test test$ | 219| 220{101:end} | 221{1:~ }|*3 222{5:-- INSERT --} | 223]] ) 224end ) 225 226it ( 'extmarks, "noplainbuffer" and syntax #20385 #23398' , function () 227exec ( 'set filetype=c' ) 228exec ( 'syntax on' ) 229exec ( 'set spell' ) 230insert ( [[ 231#include <stdbool.h> 232bool func(void); 233// I am a speling mistakke]] ) 234feed ( 'ge' ) 235screen : expect ( [[ 236{103:#include }{26:<stdbool.h>} | 237{6:bool} func({6:void}); | 238{18:// I am a }{102:spelin^g}{18: }{102:mistakke} | 239{1:~ }|*4 240| 241]] ) 242feed ( ']s' ) 243screen : expect ( [[ 244{103:#include }{26:<stdbool.h>} | 245{6:bool} func({6:void}); | 246{18:// I am a }{102:speling}{18: }{102:^mistakke} | 247{1:~ }|*4 248| 249]] ) 250feed ( ']s' ) 251screen : expect ( [[ 252{103:#include }{26:<stdbool.h>} | 253{6:bool} func({6:void}); | 254{18:// I am a }{102:^speling}{18: }{102:mistakke} | 255{1:~ }|*4 256{19:search hit BOTTOM, continuing at TOP} | 257]] ) 258exec ( 'echo ""' ) 259local ns =api . nvim_create_namespace ( 'spell' ) 260-- extmark with spell=true enables spell 261local id =api . nvim_buf_set_extmark ( 0 , ns , 1 , 4 , { end_row =1 , end_col =10 , spell =true } ) 262screen : expect ( [[ 263{103:#include }{26:<stdbool.h>} | 264{6:bool} {100:func}({6:void}); | 265{18:// I am a }{102:^speling}{18: }{102:mistakke} | 266{1:~ }|*4 267| 268]] ) 269feed ( '[s' ) 270screen : expect ( [[ 271{103:#include }{26:<stdbool.h>} | 272{6:bool} {100:^func}({6:void}); | 273{18:// I am a }{102:speling}{18: }{102:mistakke} | 274{1:~ }|*4 275| 276]] ) 277api . nvim_buf_del_extmark ( 0 , ns , id ) 278-- extmark with spell=false disables spell 279id =api . nvim_buf_set_extmark ( 0 , ns , 2 , 18 , { end_row =2 , end_col =26 , spell =false } ) 280screen : expect ( [[ 281{103:#include }{26:<stdbool.h>} | 282{6:bool} ^func({6:void}); | 283{18:// I am a }{102:speling}{18: mistakke} | 284{1:~ }|*4 285| 286]] ) 287feed ( '[s' ) 288screen : expect ( [[ 289{103:#include }{26:<stdbool.h>} | 290{6:bool} func({6:void}); | 291{18:// I am a }{102:^speling}{18: mistakke} | 292{1:~ }|*4 293{19:search hit TOP, continuing at BOTTOM} | 294]] ) 295exec ( 'echo ""' ) 296api . nvim_buf_del_extmark ( 0 , ns , id ) 297screen : expect ( [[ 298{103:#include }{26:<stdbool.h>} | 299{6:bool} func({6:void}); | 300{18:// I am a }{102:^speling}{18: }{102:mistakke} | 301{1:~ }|*4 302| 303]] ) 304feed ( ']s' ) 305screen : expect ( [[ 306{103:#include }{26:<stdbool.h>} | 307{6:bool} func({6:void}); | 308{18:// I am a }{102:speling}{18: }{102:^mistakke} | 309{1:~ }|*4 310| 311]] ) 312-- "noplainbuffer" shouldn't change spellchecking behavior with syntax enabled 313exec ( 'set spelloptions+=noplainbuffer' ) 314screen : expect_unchanged () 315feed ( '[s' ) 316screen : expect ( [[ 317{103:#include }{26:<stdbool.h>} | 318{6:bool} func({6:void}); | 319{18:// I am a }{102:^speling}{18: }{102:mistakke} | 320{1:~ }|*4 321| 322]] ) 323-- no spellchecking with "noplainbuffer" and syntax disabled 324exec ( 'syntax off' ) 325screen : expect ( [[ 326#include <stdbool.h> | 327bool func(void); | 328// I am a ^speling mistakke | 329{1:~ }|*4 330| 331]] ) 332feed ( ']s' ) 333screen : expect ( [[ 334#include <stdbool.h> | 335bool func(void); | 336// I am a ^speling mistakke | 337{1:~ }|*4 338{19:search hit BOTTOM, continuing at TOP} | 339]] ) 340exec ( 'echo ""' ) 341-- everything is spellchecked without "noplainbuffer" with syntax disabled 342exec ( 'set spelloptions&' ) 343screen : expect ( [[ 344#include <{100:stdbool}.h> | 345{100:bool} {100:func}(void); | 346// I am a {100:^speling} {100:mistakke} | 347{1:~ }|*4 348| 349]] ) 350feed ( '[s' ) 351screen : expect ( [[ 352#include <{100:stdbool}.h> | 353{100:bool} {100:^func}(void); | 354// I am a {100:speling} {100:mistakke} | 355{1:~ }|*4 356| 357]] ) 358end ) 359 360it ( 'and syntax does not clear extmark highlighting at the start of a word' , function () 361screen : try_resize ( 43 , 3 ) 362exec ( [[ 363set spell 364syntax match Constant "^.*$" 365call setline(1, "This is some text without any spell errors.") 366]] ) 367local ns =api . nvim_create_namespace ( 'spell' ) 368api . nvim_buf_set_extmark ( 0 , ns , 0 , 0 , { hl_group ='WarningMsg' , end_col =43 } ) 369screen : expect ( [[ 370{19:^This is some text without any spell errors.}| 371{1:~ }| 372| 373]] ) 374end ) 375 376it ( 'overrides syntax when Visual selection is active' , function () 377screen : try_resize ( 43 , 3 ) 378exec ( [[ 379hi! Comment guibg=NONE guifg=Blue gui=NONE guisp=NONE 380hi! SpellBad guibg=NONE guifg=Red gui=NONE guisp=NONE 381hi! Visual guibg=NONE guifg=NONE gui=underline guisp=NONE 382syn match Comment "//.*" 383call setline(1, '// Here is a misspeld word.') 384set spell 385]] ) 386screen : expect ( [[ 387{18:^// Here is a }{19:misspeld}{18: word.} | 388{1:~ }| 389| 390]] ) 391feed ( 'V' ) 392screen : expect ( [[ 393{105:^// Here is a }{104:misspeld}{105: word.} | 394{1:~ }| 395{5:-- VISUAL LINE --} | 396]] ) 397end ) 398 399it ( "global value works properly for 'spelloptions'" , function () 400screen : try_resize ( 43 , 3 ) 401exec ( 'set spell' ) 402-- :setglobal applies to future buffers but not current buffer 403exec ( 'setglobal spelloptions=camel' ) 404insert ( 'Here is TheCamelWord being spellchecked' ) 405screen : expect ( [[ 406Here is {100:TheCamelWord} being spellchecke^d | 407{1:~ }| 408| 409]] ) 410exec ( 'enew' ) 411insert ( 'There is TheCamelWord being spellchecked' ) 412screen : expect ( [[ 413There is TheCamelWord being spellchecke^d | 414{1:~ }| 415| 416]] ) 417-- :setlocal applies to current buffer but not future buffers 418exec ( 'setlocal spelloptions=' ) 419screen : expect ( [[ 420There is {100:TheCamelWord} being spellchecke^d | 421{1:~ }| 422| 423]] ) 424exec ( 'enew' ) 425insert ( 'What is TheCamelWord being spellchecked' ) 426screen : expect ( [[ 427What is TheCamelWord being spellchecke^d | 428{1:~ }| 429| 430]] ) 431-- :set applies to both current buffer and future buffers 432exec ( 'set spelloptions=' ) 433screen : expect ( [[ 434What is {100:TheCamelWord} being spellchecke^d | 435{1:~ }| 436| 437]] ) 438exec ( 'enew' ) 439insert ( 'Where is TheCamelWord being spellchecked' ) 440screen : expect ( [[ 441Where is {100:TheCamelWord} being spellchecke^d | 442{1:~ }| 443| 444]] ) 445end ) 446 447local function test_spell_false_nav ( ephemeral ) 448screen : try_resize ( 50 , 8 ) 449insert ( 'Splel\nSplle\nSepll\nSpele\nSpeel' ) 450feed ( 'gg0' ) 451exec ( 'set shortmess+=s spell spelloptions=noplainbuffer' ) 452 453n . exec_lua ( function () 454local ns =vim . api . nvim_create_namespace ( 'spell' ) 455if ephemeral then 456local decors ={} --- @type [integer,integer,vim.api.keyset.set_extmark][] 457local function on_do () 458for _ , decor in ipairs ( decors ) do 459vim . api . nvim_buf_set_extmark ( 4600 , 461ns , 462decor [ 1 ], 463decor [ 2 ], 464vim . tbl_deep_extend ( 'error' , decor [ 3 ], { ephemeral =true } ) 465) 466end 467end 468vim . api . nvim_set_decoration_provider ( ns , { 469on_win =on_do , 470_on_spell_nav =on_do , 471} ) 472function _G . Update ( new_decors ) 473decors =new_decors 474vim . cmd ( 'redraw!' ) 475end 476else 477--- @param decors [integer,integer,vim.api.keyset.set_extmark][] 478function _G . Update ( decors ) 479vim . api . nvim_buf_clear_namespace ( 0 , ns , 0 , - 1 ) 480for _ , decor in ipairs ( decors ) do 481vim . api . nvim_buf_set_extmark ( 0 , ns , decor [ 1 ], decor [ 2 ], decor [ 3 ]) 482end 483vim . cmd ( 'redraw!' ) 484end 485end 486end ) 487 488n . exec_lua ( function () 489_G . Update ( { 490{ 0 , 0 , { end_row =5 , spell =true , priority =0 } } , 491{ 2 , 0 , { end_row =3 , spell =false , priority =1 } } , 492} ) 493end ) 494screen : expect ( [[ 495{100:^Splel} | 496{100:Splle} | 497Sepll | 498{100:Spele} | 499{100:Speel} | 500{1:~ }|*2 501| 502]] ) 503 504t . eq ( { 1 , 0 } , api . nvim_win_get_cursor ( 0 )) 505feed ( ']s' ) 506t . eq ( { 2 , 0 } , api . nvim_win_get_cursor ( 0 )) 507feed ( ']s' ) 508t . eq ( { 4 , 0 } , api . nvim_win_get_cursor ( 0 )) 509feed ( ']s' ) 510t . eq ( { 5 , 0 } , api . nvim_win_get_cursor ( 0 )) 511feed ( ']s' ) 512t . eq ( { 1 , 0 } , api . nvim_win_get_cursor ( 0 )) 513feed ( '[s' ) 514t . eq ( { 5 , 0 } , api . nvim_win_get_cursor ( 0 )) 515feed ( '[s' ) 516t . eq ( { 4 , 0 } , api . nvim_win_get_cursor ( 0 )) 517feed ( '[s' ) 518t . eq ( { 2 , 0 } , api . nvim_win_get_cursor ( 0 )) 519feed ( '[s' ) 520t . eq ( { 1 , 0 } , api . nvim_win_get_cursor ( 0 )) 521 522n . exec_lua ( function () 523_G . Update ( { 524{ 0 , 0 , { end_row =5 , spell =true , priority =0 } } , 525{ 3 , 0 , { end_row =5 , spell =false , priority =1 } } , 526{ 3 , 0 , { end_row =4 , spell =true , priority =2 } } , 527} ) 528end ) 529screen : expect ( [[ 530{100:^Splel} | 531{100:Splle} | 532{100:Sepll} | 533{100:Spele} | 534Speel | 535{1:~ }|*2 536| 537]] ) 538 539t . eq ( { 1 , 0 } , api . nvim_win_get_cursor ( 0 )) 540feed ( ']s' ) 541t . eq ( { 2 , 0 } , api . nvim_win_get_cursor ( 0 )) 542feed ( ']s' ) 543t . eq ( { 3 , 0 } , api . nvim_win_get_cursor ( 0 )) 544feed ( ']s' ) 545t . eq ( { 4 , 0 } , api . nvim_win_get_cursor ( 0 )) 546feed ( ']s' ) 547t . eq ( { 1 , 0 } , api . nvim_win_get_cursor ( 0 )) 548feed ( '[s' ) 549t . eq ( { 4 , 0 } , api . nvim_win_get_cursor ( 0 )) 550feed ( '[s' ) 551t . eq ( { 3 , 0 } , api . nvim_win_get_cursor ( 0 )) 552feed ( '[s' ) 553t . eq ( { 2 , 0 } , api . nvim_win_get_cursor ( 0 )) 554feed ( '[s' ) 555t . eq ( { 1 , 0 } , api . nvim_win_get_cursor ( 0 )) 556end 557 558describe ( 'spell=false decoration on line with spelling mistake #39441' , function () 559it ( 'using ephemeral decorations' , function () 560test_spell_false_nav ( true ) 561end ) 562 563it ( 'using non-ephemeral extmarks' , function () 564test_spell_false_nav ( false ) 565end ) 566end ) 567end )