robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
7e65c44cfb
master
1" Test for :global and :vglobal 2 3source check.vim 4source term_util.vim 5 6func Test_yank_put_clipboard () 7new 8call setline ( 1 , [ 'a' , 'b' , 'c' ]) 9set clipboard = unnamed 10g /^ /normal yyp 11call assert_equal ([ 'a' , 'a' , 'b' , 'b' , 'c' , 'c' ], getline ( 1 , 6 )) 12set clipboard = unnamed,unnamedplus 13call setline ( 1 , [ 'a' , 'b' , 'c' ]) 14g /^ /normal yyp 15call assert_equal ([ 'a' , 'a' , 'b' , 'b' , 'c' , 'c' ], getline ( 1 , 6 )) 16set clipboard & 17bwipe ! 18endfunc 19 20func Test_global_set_clipboard () 21CheckFeature clipboard_working 22new 23set clipboard = unnamedplus 24let @+= 'clipboard' |g /^ /set cb = |let @"= 'unnamed' |put 25call assert_equal ([ '' , 'unnamed' ], getline ( 1 , '$' )) 26set clipboard & 27bwipe ! 28endfunc 29 30func Test_nested_global () 31new 32call setline ( 1 , [ 'nothing' , 'found' , 'found bad' , 'bad' ]) 33call assert_fails ( 'g/found/3v/bad/s/^/++/' , 'E147' ) 34g /found /v /bad/s/^/++/ 35call assert_equal ([ 'nothing' , '++found' , 'found bad' , 'bad' ], getline ( 1 , 4 )) 36bwipe ! 37endfunc 38 39func Test_global_error () 40call assert_fails ( 'g\\a' , 'E10:' ) 41call assert_fails ( 'g' , 'E148:' ) 42call assert_fails ( 'g/\(/y' , 'E54:' ) 43endfunc 44 45" Test for printing lines using :g with different search patterns 46func Test_global_print () 47new 48call setline ( 1 , [ 'foo' , 'bar' , 'foo' , 'foo' ]) 49let @/= 'foo' 50let t = execute ( "g/" ) ->trim () ->split ( "\n" ) 51call assert_equal ([ 'foo' , 'foo' , 'foo' ], t ) 52 53" Test for Vi compatible patterns 54let @/= 'bar' 55let t = execute ( 'g\/' ) ->trim () ->split ( "\n" ) 56call assert_equal ([ 'bar' ], t ) 57 58normal gg 59s /foo/foo/ 60let t = execute ( 'g\&' ) ->trim () ->split ( "\n" ) 61call assert_equal ([ 'foo' , 'foo' , 'foo' ], t ) 62 63let @/= 'bar' 64let t = execute ( 'g?' ) ->trim () ->split ( "\n" ) 65call assert_equal ([ 'bar' ], t ) 66 67" Test for the 'Pattern found in every line' message 68let v: statusmsg = '' 69v /foo\|bar/p 70call assert_notequal ( '' , v: statusmsg ) 71 72bw ! 73endfunc 74 75func Test_global_empty_pattern () 76" populate history 77silent g /hello / 78 79redir @a 80g // 81redir END 82 83call assert_match ( 'Pattern not found: hello' , @a) 84" ^~~~~ this was previously empty 85endfunc 86 87" Test for global command with newline character 88func Test_global_newline () 89new 90call setline ( 1 , [ 'foo' ]) 91exe "g/foo/s/f/h/\<NL>s/o$/w/" 92call assert_equal ( 'how' , getline ( 1 )) 93call setline ( 1 , [ "foo\<NL>bar" ]) 94exe "g/foo/s/foo\\\<NL>bar/xyz/" 95call assert_equal ( 'xyz' , getline ( 1 )) 96bw ! 97endfunc 98 99" Test :g with ? as delimiter. 100func Test_global_question_delimiter () 101new 102call setline ( 1 , [ 'aaaaa' , 'b?bbb' , 'ccccc' , 'ddd?d' , 'eeeee' ]) 103g ?\? ?delete 104call assert_equal ([ 'aaaaa' , 'ccccc' , 'eeeee' ], getline ( 1 , '$' )) 105bwipe ! 106endfunc 107 108func Test_global_wrong_delimiter () 109call assert_fails ( 'g x^bxd' , 'E146:' ) 110endfunc 111 112" Test for interrupting :global using Ctrl-C 113func Test_interrupt_global () 114CheckRunVimInTerminal 115 116let lines =<< trim END 117cnoremap ; <Cmd>sleep 10<CR> 118call setline(1, repeat(['foo'], 5)) 119END 120call writefile ( lines , 'Xtest_interrupt_global' ) 121let buf = RunVimInTerminal ( '-S Xtest_interrupt_global' , { 'rows' : 6 }) 122 123call term_sendkeys ( buf , ":g/foo/norm :\<C-V>;\<CR>" ) 124" Wait for :sleep to start 125call TermWait ( buf , 100 ) 126call term_sendkeys ( buf , "\<C-C>" ) 127call WaitForAssert ({ ->assert_match ( 'Interrupted' , term_getline ( buf , 6 ))}, 1000 ) 128 129" Also test in Ex mode 130call term_sendkeys ( buf , "gQg/foo/norm :\<C-V>;\<CR>" ) 131" Wait for :sleep to start 132call TermWait ( buf , 100 ) 133call term_sendkeys ( buf , "\<C-C>" ) 134call WaitForAssert ({ ->assert_match ( 'Interrupted' , term_getline ( buf , 5 ))}, 1000 ) 135 136call StopVimInTerminal ( buf ) 137call delete ( 'Xtest_interrupt_global' ) 138endfunc 139 140" vim: shiftwidth=2 sts=2 expandtab