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