robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each =t . describe , t . it , t . before_each 5local clear =n . clear 6local command =n . command 7local dedent =t . dedent 8local eval =n . eval 9local eq =t . eq 10local feed =n . feed 11local api =n . api 12local exec_capture =n . exec_capture 13 14describe ( 'TabNewEntered' , function () 15describe ( 'au TabNewEntered' , function () 16describe ( 'with * as <afile>' , function () 17it ( 'matches when entering any new tab' , function () 18clear () 19command ( 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")' ) 20eq ( 'tabnewentered:2:2' , api . nvim_exec ( 'tabnew' , true )) 21eq ( 'tabnewentered:3:3' , api . nvim_exec ( 'tabnew test.x2' , true )) 22end ) 23end ) 24describe ( 'with FILE as <afile>' , function () 25it ( 'matches when opening a new tab for FILE' , function () 26clear () 27command ( 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"' ) 28eq ( 'tabnewentered:match' , api . nvim_exec ( 'tabnew Xtest-tabnewentered' , true )) 29end ) 30end ) 31describe ( 'with CTRL-W T' , function () 32it ( 'works when opening a new tab with CTRL-W T' , function () 33clear () 34command ( 'au! TabNewEntered * echom "entered"' ) 35command ( 'tabnew test.x2' ) 36command ( 'split' ) 37eq ( 'entered' , api . nvim_exec ( 'execute "normal \\<C-W>T"' , true )) 38end ) 39end ) 40describe ( 'with tab split #4334' , function () 41it ( 'works when create a tab by using tab split command' , function () 42clear () 43command ( 'au! TabNewEntered * let b:entered = "entered"' ) 44command ( 'tab split' ) 45eq ( 'entered' , api . nvim_exec ( 'echo b:entered' , true )) 46end ) 47end ) 48end ) 49end ) 50 51describe ( 'TabEnter' , function () 52before_each ( clear ) 53it ( 'has correct previous tab when entering any new tab' , function () 54command ( 'augroup TEMP' ) 55command ( 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')' ) 56command ( 'augroup END' ) 57eq ( 'tabenter:2:1' , api . nvim_exec ( 'tabnew' , true )) 58eq ( 'tabenter:3:2' , api . nvim_exec ( 'tabnew test.x2' , true )) 59command ( 'augroup! TEMP' ) 60end ) 61it ( 'has correct previous tab when entering any preexisting tab' , function () 62command ( 'tabnew' ) 63command ( 'tabnew' ) 64command ( 'augroup TEMP' ) 65command ( 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')' ) 66command ( 'augroup END' ) 67eq ( 'tabenter:1:3' , api . nvim_exec ( 'tabnext' , true )) 68eq ( 'tabenter:2:1' , api . nvim_exec ( 'tabnext' , true )) 69command ( 'augroup! TEMP' ) 70end ) 71end ) 72 73describe ( 'tabpage/previous' , function () 74before_each ( clear ) 75local function switches_to_previous_after_new_tab_creation_at_end ( characters ) 76return function () 77-- Add three tabs for a total of four 78command ( 'tabnew' ) 79command ( 'tabnew' ) 80command ( 'tabnew' ) 81 82-- The previous tab is now the third. 83eq ( 3 , eval ( "tabpagenr('#')" )) 84 85-- Switch to the previous (third) tab 86feed ( characters ) 87 88eq ( 89dedent ( [=[ 90Tab page 1 91[No Name] 92Tab page 2 93[No Name] 94Tab page 3 95> [No Name] 96Tab page 4 97# [No Name]]=] ), 98exec_capture ( 'tabs' ) 99) 100 101-- The previous tab is now the fourth. 102eq ( 4 , eval ( "tabpagenr('#')" )) 103end 104end 105it ( 106'switches to previous via g<Tab> after new tab creation at end' , 107switches_to_previous_after_new_tab_creation_at_end ( 'g<Tab>' ) 108) 109it ( 110'switches to previous via <C-W>g<Tab>. after new tab creation at end' , 111switches_to_previous_after_new_tab_creation_at_end ( '<C-W>g<Tab>' ) 112) 113it ( 114'switches to previous via <C-Tab>. after new tab creation at end' , 115switches_to_previous_after_new_tab_creation_at_end ( '<C-Tab>' ) 116) 117it ( 118'switches to previous via :tabn #<CR>. after new tab creation at end' , 119switches_to_previous_after_new_tab_creation_at_end ( ':tabn #<CR>' ) 120) 121 122local function switches_to_previous_after_new_tab_creation_in_middle ( characters ) 123return function () 124-- Add three tabs for a total of four 125command ( 'tabnew' ) 126command ( 'tabnew' ) 127command ( 'tabnew' ) 128-- Switch to the second tab 129command ( 'tabnext 2' ) 130-- Add a new tab after the second tab 131command ( 'tabnew' ) 132 133-- The previous tab is now the second. 134eq ( 2 , eval ( "tabpagenr('#')" )) 135 136-- Switch to the previous (second) tab 137feed ( characters ) 138eq ( 139dedent ( [=[ 140Tab page 1 141[No Name] 142Tab page 2 143> [No Name] 144Tab page 3 145# [No Name] 146Tab page 4 147[No Name] 148Tab page 5 149[No Name]]=] ), 150exec_capture ( 'tabs' ) 151) 152 153-- The previous tab is now the third. 154eq ( 3 , eval ( "tabpagenr('#')" )) 155end 156end 157it ( 158'switches to previous via g<Tab> after new tab creation in middle' , 159switches_to_previous_after_new_tab_creation_in_middle ( 'g<Tab>' ) 160) 161it ( 162'switches to previous via <C-W>g<Tab> after new tab creation in middle' , 163switches_to_previous_after_new_tab_creation_in_middle ( '<C-W>g<Tab>' ) 164) 165it ( 166'switches to previous via <C-Tab> after new tab creation in middle' , 167switches_to_previous_after_new_tab_creation_in_middle ( '<C-Tab>' ) 168) 169it ( 170'switches to previous via :tabn #<CR> after new tab creation in middle' , 171switches_to_previous_after_new_tab_creation_in_middle ( ':tabn #<CR>' ) 172) 173 174local function switches_to_previous_after_switching_to_next_tab ( characters ) 175return function () 176-- Add three tabs for a total of four 177command ( 'tabnew' ) 178command ( 'tabnew' ) 179command ( 'tabnew' ) 180-- Switch to the next (first) tab 181command ( 'tabnext' ) 182 183-- The previous tab is now the fourth. 184eq ( 4 , eval ( "tabpagenr('#')" )) 185 186-- Switch to the previous (fourth) tab 187feed ( characters ) 188 189eq ( 190dedent ( [=[ 191Tab page 1 192# [No Name] 193Tab page 2 194[No Name] 195Tab page 3 196[No Name] 197Tab page 4 198> [No Name]]=] ), 199exec_capture ( 'tabs' ) 200) 201 202-- The previous tab is now the first. 203eq ( 1 , eval ( "tabpagenr('#')" )) 204end 205end 206it ( 207'switches to previous via g<Tab> after switching to next tab' , 208switches_to_previous_after_switching_to_next_tab ( 'g<Tab>' ) 209) 210it ( 211'switches to previous via <C-W>g<Tab> after switching to next tab' , 212switches_to_previous_after_switching_to_next_tab ( '<C-W>g<Tab>' ) 213) 214it ( 215'switches to previous via <C-Tab> after switching to next tab' , 216switches_to_previous_after_switching_to_next_tab ( '<C-Tab>' ) 217) 218it ( 219'switches to previous via :tabn #<CR> after switching to next tab' , 220switches_to_previous_after_switching_to_next_tab ( ':tabn #<CR>' ) 221) 222 223local function switches_to_previous_after_switching_to_last_tab ( characters ) 224return function () 225-- Add three tabs for a total of four 226command ( 'tabnew' ) 227command ( 'tabnew' ) 228command ( 'tabnew' ) 229-- Switch to the next (first) tab 230command ( 'tabnext' ) 231-- Switch to the last (fourth) tab. 232command ( 'tablast' ) 233 234-- The previous tab is now the second. 235eq ( 1 , eval ( "tabpagenr('#')" )) 236 237-- Switch to the previous (second) tab 238feed ( characters ) 239 240eq ( 241dedent ( [=[ 242Tab page 1 243> [No Name] 244Tab page 2 245[No Name] 246Tab page 3 247[No Name] 248Tab page 4 249# [No Name]]=] ), 250exec_capture ( 'tabs' ) 251) 252 253-- The previous tab is now the fourth. 254eq ( 4 , eval ( "tabpagenr('#')" )) 255end 256end 257it ( 258'switches to previous after switching to last tab' , 259switches_to_previous_after_switching_to_last_tab ( 'g<Tab>' ) 260) 261it ( 262'switches to previous after switching to last tab' , 263switches_to_previous_after_switching_to_last_tab ( '<C-W>g<Tab>' ) 264) 265it ( 266'switches to previous after switching to last tab' , 267switches_to_previous_after_switching_to_last_tab ( '<C-Tab>' ) 268) 269it ( 270'switches to previous after switching to last tab' , 271switches_to_previous_after_switching_to_last_tab ( ':tabn #<CR>' ) 272) 273 274local function switches_to_previous_after_switching_to_previous_tab ( characters ) 275return function () 276-- Add three tabs for a total of four 277command ( 'tabnew' ) 278command ( 'tabnew' ) 279command ( 'tabnew' ) 280-- Switch to the previous (third) tab 281command ( 'tabprevious' ) 282 283-- The previous tab is now the fourth. 284eq ( 4 , eval ( "tabpagenr('#')" )) 285 286-- Switch to the previous (fourth) tab 287feed ( characters ) 288 289eq ( 290dedent ( [=[ 291Tab page 1 292[No Name] 293Tab page 2 294[No Name] 295Tab page 3 296# [No Name] 297Tab page 4 298> [No Name]]=] ), 299exec_capture ( 'tabs' ) 300) 301 302-- The previous tab is now the third. 303eq ( 3 , eval ( "tabpagenr('#')" )) 304end 305end 306it ( 307'switches to previous via g<Tab> after switching to previous tab' , 308switches_to_previous_after_switching_to_previous_tab ( 'g<Tab>' ) 309) 310it ( 311'switches to previous via <C-W>g<Tab> after switching to previous tab' , 312switches_to_previous_after_switching_to_previous_tab ( '<C-W>g<Tab>' ) 313) 314it ( 315'switches to previous via <C-Tab> after switching to previous tab' , 316switches_to_previous_after_switching_to_previous_tab ( '<C-Tab>' ) 317) 318it ( 319'switches to previous via :tabn #<CR> after switching to previous tab' , 320switches_to_previous_after_switching_to_previous_tab ( ':tabn #<CR>' ) 321) 322 323local function switches_to_previous_after_switching_to_first_tab ( characters ) 324return function () 325-- Add three tabs for a total of four 326command ( 'tabnew' ) 327command ( 'tabnew' ) 328command ( 'tabnew' ) 329-- Switch to the previous (third) tab 330command ( 'tabprevious' ) 331-- Switch to the first tab 332command ( 'tabfirst' ) 333 334-- The previous tab is now the third. 335eq ( 3 , eval ( "tabpagenr('#')" )) 336 337-- Switch to the previous (third) tab 338feed ( characters ) 339 340eq ( 341dedent ( [=[ 342Tab page 1 343# [No Name] 344Tab page 2 345[No Name] 346Tab page 3 347> [No Name] 348Tab page 4 349[No Name]]=] ), 350exec_capture ( 'tabs' ) 351) 352 353-- The previous tab is now the first. 354eq ( 1 , eval ( "tabpagenr('#')" )) 355end 356end 357it ( 358'switches to previous via g<Tab> after switching to first tab' , 359switches_to_previous_after_switching_to_first_tab ( 'g<Tab>' ) 360) 361it ( 362'switches to previous via <C-W>g<Tab> after switching to first tab' , 363switches_to_previous_after_switching_to_first_tab ( '<C-W>g<Tab>' ) 364) 365it ( 366'switches to previous via <C-Tab> after switching to first tab' , 367switches_to_previous_after_switching_to_first_tab ( '<C-Tab>' ) 368) 369it ( 370'switches to previous via :tabn #<CR> after switching to first tab' , 371switches_to_previous_after_switching_to_first_tab ( ':tabn #<CR>' ) 372) 373 374local function switches_to_previous_after_numbered_tab_switch ( characters ) 375return function () 376-- Add three tabs for a total of four 377command ( 'tabnew' ) 378command ( 'tabnew' ) 379command ( 'tabnew' ) 380-- Switch to the second tab 381command ( 'tabnext 2' ) 382 383-- The previous tab is now the fourth. 384eq ( 4 , eval ( "tabpagenr('#')" )) 385 386-- Switch to the previous (fourth) tab 387feed ( characters ) 388 389eq ( 390dedent ( [=[ 391Tab page 1 392[No Name] 393Tab page 2 394# [No Name] 395Tab page 3 396[No Name] 397Tab page 4 398> [No Name]]=] ), 399exec_capture ( 'tabs' ) 400) 401 402-- The previous tab is now the second. 403eq ( 2 , eval ( "tabpagenr('#')" )) 404end 405end 406it ( 407'switches to previous via g<Tab> after numbered tab switch' , 408switches_to_previous_after_numbered_tab_switch ( 'g<Tab>' ) 409) 410it ( 411'switches to previous via <C-W>g<Tab> after numbered tab switch' , 412switches_to_previous_after_numbered_tab_switch ( '<C-W>g<Tab>' ) 413) 414it ( 415'switches to previous via <C-Tab> after numbered tab switch' , 416switches_to_previous_after_numbered_tab_switch ( '<C-Tab>' ) 417) 418it ( 419'switches to previous via :tabn #<CR> after numbered tab switch' , 420switches_to_previous_after_numbered_tab_switch ( ':tabn #<CR>' ) 421) 422 423local function switches_to_previous_after_switching_to_previous ( characters1 , characters2 ) 424return function () 425-- Add three tabs for a total of four 426command ( 'tabnew' ) 427command ( 'tabnew' ) 428command ( 'tabnew' ) 429-- Switch to the second tab 430command ( 'tabnext 2' ) 431-- Switch to the previous (fourth) tab 432feed ( characters1 ) 433 434-- The previous tab is now the second. 435eq ( 2 , eval ( "tabpagenr('#')" )) 436 437-- Switch to the previous (second) tab 438feed ( characters2 ) 439 440eq ( 441dedent ( [=[ 442Tab page 1 443[No Name] 444Tab page 2 445> [No Name] 446Tab page 3 447[No Name] 448Tab page 4 449# [No Name]]=] ), 450exec_capture ( 'tabs' ) 451) 452 453-- The previous tab is now the fourth. 454eq ( 4 , eval ( "tabpagenr('#')" )) 455end 456end 457it ( 458'switches to previous via g<Tab> after switching to previous via g<Tab>' , 459switches_to_previous_after_switching_to_previous ( 'g<Tab>' , 'g<Tab>' ) 460) 461it ( 462'switches to previous via <C-W>g<Tab> after switching to previous via g<Tab>' , 463switches_to_previous_after_switching_to_previous ( 'g<Tab>' , '<C-W>g<Tab>' ) 464) 465it ( 466'switches to previous via <C-Tab> after switching to previous via g<Tab>' , 467switches_to_previous_after_switching_to_previous ( 'g<Tab>' , '<C-Tab>' ) 468) 469it ( 470'switches to previous via :tabn #<CR> after switching to previous via g<Tab>' , 471switches_to_previous_after_switching_to_previous ( 'g<Tab>' , ':tabn #<CR>' ) 472) 473it ( 474'switches to previous via g<Tab> after switching to previous via <C-W>g<Tab>' , 475switches_to_previous_after_switching_to_previous ( '<C-W>g<Tab>' , 'g<Tab>' ) 476) 477it ( 478'switches to previous via <C-W>g<Tab> after switching to previous via <C-W>g<Tab>' , 479switches_to_previous_after_switching_to_previous ( '<C-W>g<Tab>' , '<C-W>g<Tab>' ) 480) 481it ( 482'switches to previous via <C-Tab> after switching to previous via <C-W>g<Tab>' , 483switches_to_previous_after_switching_to_previous ( '<C-W>g<Tab>' , '<C-Tab>' ) 484) 485it ( 486'switches to previous via :tabn #<CR> after switching to previous via <C-W>g<Tab>' , 487switches_to_previous_after_switching_to_previous ( '<C-W>g<Tab>' , ':tabn #<CR>' ) 488) 489it ( 490'switches to previous via g<Tab> after switching to previous via <C-Tab>' , 491switches_to_previous_after_switching_to_previous ( '<C-Tab>' , 'g<Tab>' ) 492) 493it ( 494'switches to previous via <C-W>g<Tab> after switching to previous via <C-Tab>' , 495switches_to_previous_after_switching_to_previous ( '<C-Tab>' , '<C-W>g<Tab>' ) 496) 497it ( 498'switches to previous via <C-Tab> after switching to previous via <C-Tab>' , 499switches_to_previous_after_switching_to_previous ( '<C-Tab>' , '<C-Tab>' ) 500) 501it ( 502'switches to previous via :tabn #<CR> after switching to previous via <C-Tab>' , 503switches_to_previous_after_switching_to_previous ( '<C-Tab>' , ':tabn #<CR>' ) 504) 505it ( 506'switches to previous via g<Tab> after switching to previous via :tabn #<CR>' , 507switches_to_previous_after_switching_to_previous ( ':tabn #<CR>' , 'g<Tab>' ) 508) 509it ( 510'switches to previous via <C-W>g<Tab> after switching to previous via :tabn #<CR>' , 511switches_to_previous_after_switching_to_previous ( ':tabn #<CR>' , '<C-W>g<Tab>' ) 512) 513it ( 514'switches to previous via <C-Tab> after switching to previous via <C-Tab>' , 515switches_to_previous_after_switching_to_previous ( ':tabn #<CR>' , '<C-Tab>' ) 516) 517it ( 518'switches to previous via :tabn #<CR> after switching to previous via :tabn #<CR>' , 519switches_to_previous_after_switching_to_previous ( ':tabn #<CR>' , ':tabn #<CR>' ) 520) 521 522local function does_not_switch_to_previous_after_closing_current_tab ( characters ) 523return function () 524-- Add three tabs for a total of four 525command ( 'tabnew' ) 526command ( 'tabnew' ) 527command ( 'tabnew' ) 528-- Close the current (fourth tab) 529command ( 'wincmd c' ) 530 531-- The previous tab is now the "zeroth" -- there isn't one. 532eq ( 0 , eval ( "tabpagenr('#')" )) 533 534-- At this point, switching to the "previous" (i.e. fourth) tab would mean 535-- switching to either a dangling or a null pointer. 536feed ( characters ) 537 538eq ( 539dedent ( [=[ 540Tab page 1 541[No Name] 542Tab page 2 543[No Name] 544Tab page 3 545> [No Name]]=] ), 546exec_capture ( 'tabs' ) 547) 548 549-- The previous tab is now the "zero". 550eq ( 0 , eval ( "tabpagenr('#')" )) 551end 552end 553it ( 554'does not switch to previous via g<Tab> after closing current tab' , 555does_not_switch_to_previous_after_closing_current_tab ( 'g<Tab>' ) 556) 557it ( 558'does not switch to previous via <C-W>g<Tab> after closing current tab' , 559does_not_switch_to_previous_after_closing_current_tab ( '<C-W>g<Tab>' ) 560) 561it ( 562'does not switch to previous via <C-Tab> after closing current tab' , 563does_not_switch_to_previous_after_closing_current_tab ( '<C-Tab>' ) 564) 565it ( 566'does not switch to previous via :tabn #<CR> after closing current tab' , 567does_not_switch_to_previous_after_closing_current_tab ( ':tabn #<CR>' ) 568) 569 570local function does_not_switch_to_previous_after_entering_operator_pending ( characters ) 571return function () 572-- Add three tabs for a total of four 573command ( 'tabnew' ) 574command ( 'tabnew' ) 575command ( 'tabnew' ) 576 577-- The previous tab is now the third. 578eq ( 3 , eval ( "tabpagenr('#')" )) 579 580-- Enter operator pending mode. 581feed ( 'd' ) 582eq ( 'no' , eval ( 'mode(1)' )) 583 584-- At this point switching to the previous tab should have no effect 585-- other than leaving operator pending mode. 586feed ( characters ) 587 588-- Attempting to switch tabs returns us to normal mode. 589eq ( 'n' , eval ( 'mode()' )) 590 591-- The current tab is still the fourth. 592eq ( 4 , eval ( 'tabpagenr()' )) 593 594-- The previous tab is still the third. 595eq ( 3 , eval ( "tabpagenr('#')" )) 596end 597end 598it ( 599'does not switch to previous via g<Tab> after entering operator pending' , 600does_not_switch_to_previous_after_entering_operator_pending ( 'g<Tab>' ) 601) 602-- NOTE: When in operator pending mode, attempting to switch to previous has 603-- the following effect: 604-- - Ctrl-W exits operator pending mode 605-- - g<Tab> switches to the previous tab 606-- In other words, the effect of "<C-W>g<Tab>" is to switch to the 607-- previous tab even from operator pending mode, but only thanks to the 608-- fact that the suffix after "<C-W>" in "<C-W>g<Tab>" just happens to 609-- be the same as the normal mode command to switch to the previous tab. 610-- it('does not switch to previous via <C-W>g<Tab> after entering operator pending', 611-- does_not_switch_to_previous_after_entering_operator_pending('<C-W>g<Tab>')) 612it ( 613'does not switch to previous via <C-Tab> after entering operator pending' , 614does_not_switch_to_previous_after_entering_operator_pending ( '<C-Tab>' ) 615) 616-- NOTE: When in operator pending mode, pressing : leaves operator pending 617-- mode and enters command mode, so :tabn #<CR> does in fact switch 618-- tabs. 619-- it('does not switch to previous via :tabn #<CR> after entering operator pending', 620-- does_not_switch_to_previous_after_entering_operator_pending(':tabn #<CR>')) 621 622local function cmdwin_allows_tab_switch ( characters ) 623return function () 624-- Add three tabs for a total of four 625command ( 'tabnew' ) 626command ( 'tabnew' ) 627command ( 'tabnew' ) 628 629-- The previous tab is now the third. 630eq ( 3 , eval ( "tabpagenr('#')" )) 631 632-- Edit : command line in command-line window 633feed ( 'q:' ) 634 635local cmdline_win_id =eval ( 'win_getid()' ) 636 637-- Switching to the previous tab now works. 638feed ( characters ) 639 640-- Focus moved out of the cmdwin to the previous (third) tab. 641t . neq ( cmdline_win_id , eval ( 'win_getid()' )) 642eq ( 3 , eval ( 'tabpagenr()' )) 643end 644end 645 646it ( 'cmdwin allows tab switch via g<Tab>' , cmdwin_allows_tab_switch ( 'g<Tab>' )) 647it ( 'cmdwin allows tab switch via <C-W>g<Tab>' , cmdwin_allows_tab_switch ( '<C-W>g<Tab>' )) 648it ( 'cmdwin allows tab switch via <C-Tab>' , cmdwin_allows_tab_switch ( '<C-Tab>' )) 649it ( 'cmdwin allows tab switch via :tabn #<CR>' , cmdwin_allows_tab_switch ( ':tabn #<CR>' )) 650 651it ( ':tabs indicates correct prevtab curwin' , function () 652-- Add three tabs for a total of four 653command ( 'tabnew' ) 654command ( 'tabnew' ) 655command ( 'split' ) 656command ( 'vsplit' ) 657feed ( '<C-w>p' ) 658command ( 'tabnew' ) 659 660-- The previous tab is now the three. 661eq ( 3 , eval ( "tabpagenr('#')" )) 662 663eq ( 664dedent ( [=[ 665Tab page 1 666[No Name] 667Tab page 2 668[No Name] 669Tab page 3 670[No Name] 671# [No Name] 672[No Name] 673Tab page 4 674> [No Name]]=] ), 675exec_capture ( 'tabs' ) 676) 677end ) 678end )