xref: /vim-8.2.3635/src/testdir/test_global.vim (revision a7c4e747)
1" Test for :global and :vglobal
2
3source check.vim
4
5func Test_yank_put_clipboard()
6  new
7  call setline(1, ['a', 'b', 'c'])
8  set clipboard=unnamed
9  g/^/normal yyp
10  call assert_equal(['a', 'a', 'b', 'b', 'c', 'c'], getline(1, 6))
11  set clipboard=unnamed,unnamedplus
12  call setline(1, ['a', 'b', 'c'])
13  g/^/normal yyp
14  call assert_equal(['a', 'a', 'b', 'b', 'c', 'c'], getline(1, 6))
15  set clipboard&
16  bwipe!
17endfunc
18
19func Test_global_set_clipboard()
20  CheckFeature clipboard_working
21  new
22  set clipboard=unnamedplus
23  let @+='clipboard' | g/^/set cb= | let @" = 'unnamed' | put
24  call assert_equal(['','unnamed'], getline(1, '$'))
25  set clipboard&
26  bwipe!
27endfunc
28
29func Test_nested_global()
30  new
31  call setline(1, ['nothing', 'found', 'found bad', 'bad'])
32  call assert_fails('g/found/3v/bad/s/^/++/', 'E147')
33  g/found/v/bad/s/^/++/
34  call assert_equal(['nothing', '++found', 'found bad', 'bad'], getline(1, 4))
35  bwipe!
36endfunc
37
38func Test_global_error()
39  call assert_fails('g\\a', 'E10:')
40  call assert_fails('g', 'E148:')
41  call assert_fails('g/\(/y', 'E54:')
42endfunc
43
44" Test for printing lines using :g with different search patterns
45func Test_global_print()
46  new
47  call setline(1, ['foo', 'bar', 'foo', 'foo'])
48  let @/ = 'foo'
49  let t = execute("g/")->trim()->split("\n")
50  call assert_equal(['foo', 'foo', 'foo'], t)
51
52  " Test for Vi compatible patterns
53  let @/ = 'bar'
54  let t = execute('g\/')->trim()->split("\n")
55  call assert_equal(['bar'], t)
56
57  normal gg
58  s/foo/foo/
59  let t = execute('g\&')->trim()->split("\n")
60  call assert_equal(['foo', 'foo', 'foo'], t)
61
62  let @/ = 'bar'
63  let t = execute('g?')->trim()->split("\n")
64  call assert_equal(['bar'], t)
65
66  " Test for the 'Pattern found in every line' message
67  let v:statusmsg = ''
68  v/foo\|bar/p
69  call assert_notequal('', v:statusmsg)
70
71  close!
72endfunc
73
74" Test for global command with newline character
75func Test_global_newline()
76  new
77  call setline(1, ['foo'])
78  exe "g/foo/s/f/h/\<NL>s/o$/w/"
79  call assert_equal('how', getline(1))
80  call setline(1, ["foo\<NL>bar"])
81  exe "g/foo/s/foo\\\<NL>bar/xyz/"
82  call assert_equal('xyz', getline(1))
83  close!
84endfunc
85
86" vim: shiftwidth=2 sts=2 expandtab
87