blob: 7804ca470e2dc3e055f2dd73e042a19965e5993c [file] [log] [blame]
Bram Moolenaar3fcfa352017-03-29 19:20:41 +02001
2func Test_yank_put_clipboard()
3 new
4 call setline(1, ['a', 'b', 'c'])
5 set clipboard=unnamed
6 g/^/normal yyp
7 call assert_equal(['a', 'a', 'b', 'b', 'c', 'c'], getline(1, 6))
8
9 set clipboard&
10 bwipe!
11endfunc
Bram Moolenaarf84b1222017-06-10 14:29:52 +020012
13func Test_nested_global()
14 new
15 call setline(1, ['nothing', 'found', 'found bad', 'bad'])
16 call assert_fails('g/found/3v/bad/s/^/++/', 'E147')
17 g/found/v/bad/s/^/++/
18 call assert_equal(['nothing', '++found', 'found bad', 'bad'], getline(1, 4))
19 bwipe!
20endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010021
22func Test_global_error()
23 call assert_fails('g\\a', 'E10:')
24 call assert_fails('g', 'E148:')
25 call assert_fails('g/\(/y', 'E476:')
26endfunc
27
Bram Moolenaarea3db912020-02-02 15:32:13 +010028" Test for printing lines using :g with different search patterns
29func Test_global_print()
30 new
31 call setline(1, ['foo', 'bar', 'foo', 'foo'])
32 let @/ = 'foo'
33 let t = execute("g/")->trim()->split("\n")
34 call assert_equal(['foo', 'foo', 'foo'], t)
35
36 " Test for Vi compatible patterns
37 let @/ = 'bar'
38 let t = execute('g\/')->trim()->split("\n")
39 call assert_equal(['bar'], t)
40
41 normal gg
42 s/foo/foo/
43 let t = execute('g\&')->trim()->split("\n")
44 call assert_equal(['foo', 'foo', 'foo'], t)
45
46 let @/ = 'bar'
47 let t = execute('g?')->trim()->split("\n")
48 call assert_equal(['bar'], t)
49
50 " Test for the 'Pattern found in every line' message
51 let v:statusmsg = ''
52 v/foo\|bar/p
53 call assert_notequal('', v:statusmsg)
54
55 close!
56endfunc
57
Bram Moolenaar818fc9a2020-02-21 17:54:45 +010058" Test for global command with newline character
59func Test_global_newline()
60 new
61 call setline(1, ['foo'])
62 exe "g/foo/s/f/h/\<NL>s/o$/w/"
63 call assert_equal('how', getline(1))
64 call setline(1, ["foo\<NL>bar"])
65 exe "g/foo/s/foo\\\<NL>bar/xyz/"
66 call assert_equal('xyz', getline(1))
67 close!
68endfunc
69
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010070" vim: shiftwidth=2 sts=2 expandtab