Bram Moolenaar | 3fcfa35 | 2017-03-29 19:20:41 +0200 | [diff] [blame] | 1 | |
| 2 | func 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! |
| 11 | endfunc |
Bram Moolenaar | f84b122 | 2017-06-10 14:29:52 +0200 | [diff] [blame] | 12 | |
| 13 | func 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! |
| 20 | endfunc |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 21 | |
| 22 | func Test_global_error() |
| 23 | call assert_fails('g\\a', 'E10:') |
| 24 | call assert_fails('g', 'E148:') |
| 25 | call assert_fails('g/\(/y', 'E476:') |
| 26 | endfunc |
| 27 | |
Bram Moolenaar | ea3db91 | 2020-02-02 15:32:13 +0100 | [diff] [blame] | 28 | " Test for printing lines using :g with different search patterns |
| 29 | func 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! |
| 56 | endfunc |
| 57 | |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 58 | " Test for global command with newline character |
| 59 | func 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! |
| 68 | endfunc |
| 69 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 70 | " vim: shiftwidth=2 sts=2 expandtab |