annotate src/testdir/test_substitute.vim @ 12285:4963348ed734 v8.0.1022

patch 8.0.1022: test 80 is old style commit https://github.com/vim/vim/commit/1a333bc44a5d7e51575b1c3cd864fb37fd5b5f2b Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 30 20:21:58 2017 +0200 patch 8.0.1022: test 80 is old style Problem: Test 80 is old style. Solution: Turn it into a new style test. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Wed, 30 Aug 2017 20:30:04 +0200
parents ab9f7bbe4439
children aa658b33f25a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10072
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for multi-line regexps with ":s".
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 function! Test_multiline_subst()
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 enew!
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 call append(0, ["1 aa",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 \ "bb",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 \ "cc",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 \ "2 dd",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 \ "ee",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 \ "3 ef",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 \ "gh",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 \ "4 ij",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 \ "5 a8",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 \ "8b c9",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 \ "9d",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 \ "6 e7",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 \ "77f",
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 \ "xxxxx"])
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 1
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 " test if replacing a line break works with a back reference
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 /^1/,/^2/s/\n\(.\)/ \1/
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 " test if inserting a line break works with a back reference
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 /^3/,/^4/s/\(.\)$/\r\1/
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 " test if replacing a line break with another line break works
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 /^5/,/^6/s/\(\_d\{3}\)/x\1x/
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 call assert_equal('1 aa bb cc 2 dd ee', getline(1))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 call assert_equal('3 e', getline(2))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 call assert_equal('f', getline(3))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call assert_equal('g', getline(4))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call assert_equal('h', getline(5))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 call assert_equal('4 i', getline(6))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call assert_equal('j', getline(7))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 call assert_equal('5 ax8', getline(8))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 call assert_equal('8xb cx9', getline(9))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 call assert_equal('9xd', getline(10))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 call assert_equal('6 ex7', getline(11))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 call assert_equal('7x7f', getline(12))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 call assert_equal('xxxxx', getline(13))
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 enew!
c104f09ae2f4 commit https://github.com/vim/vim/commit/cd055da370114f66c960be9c8b1eb0f33a9e0a85
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 endfunction
10893
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
42
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
43 function! Test_substitute_variants()
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
44 " Validate that all the 2-/3-letter variants which embed the flags into the
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
45 " command name actually work.
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
46 enew!
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
47 let ln = 'Testing string'
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
48 let variants = [
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
49 \ { 'cmd': ':s/Test/test/c', 'exp': 'testing string', 'prompt': 'y' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
50 \ { 'cmd': ':s/foo/bar/ce', 'exp': ln },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
51 \ { 'cmd': ':s/t/r/cg', 'exp': 'Tesring srring', 'prompt': 'a' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
52 \ { 'cmd': ':s/t/r/ci', 'exp': 'resting string', 'prompt': 'y' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
53 \ { 'cmd': ':s/t/r/cI', 'exp': 'Tesring string', 'prompt': 'y' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
54 \ { 'cmd': ':s/t/r/cn', 'exp': ln },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
55 \ { 'cmd': ':s/t/r/cp', 'exp': 'Tesring string', 'prompt': 'y' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
56 \ { 'cmd': ':s/t/r/cl', 'exp': 'Tesring string', 'prompt': 'y' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
57 \ { 'cmd': ':s/t/r/gc', 'exp': 'Tesring srring', 'prompt': 'a' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
58 \ { 'cmd': ':s/foo/bar/ge', 'exp': ln },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
59 \ { 'cmd': ':s/t/r/g', 'exp': 'Tesring srring' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
60 \ { 'cmd': ':s/t/r/gi', 'exp': 'resring srring' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
61 \ { 'cmd': ':s/t/r/gI', 'exp': 'Tesring srring' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
62 \ { 'cmd': ':s/t/r/gn', 'exp': ln },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
63 \ { 'cmd': ':s/t/r/gp', 'exp': 'Tesring srring' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
64 \ { 'cmd': ':s/t/r/gl', 'exp': 'Tesring srring' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
65 \ { 'cmd': ':s//r/gr', 'exp': 'Testr strr' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
66 \ { 'cmd': ':s/t/r/ic', 'exp': 'resting string', 'prompt': 'y' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
67 \ { 'cmd': ':s/foo/bar/ie', 'exp': ln },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
68 \ { 'cmd': ':s/t/r/i', 'exp': 'resting string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
69 \ { 'cmd': ':s/t/r/iI', 'exp': 'Tesring string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
70 \ { 'cmd': ':s/t/r/in', 'exp': ln },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
71 \ { 'cmd': ':s/t/r/ip', 'exp': 'resting string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
72 \ { 'cmd': ':s//r/ir', 'exp': 'Testr string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
73 \ { 'cmd': ':s/t/r/Ic', 'exp': 'Tesring string', 'prompt': 'y' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
74 \ { 'cmd': ':s/foo/bar/Ie', 'exp': ln },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
75 \ { 'cmd': ':s/t/r/Ig', 'exp': 'Tesring srring' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
76 \ { 'cmd': ':s/t/r/Ii', 'exp': 'resting string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
77 \ { 'cmd': ':s/t/r/I', 'exp': 'Tesring string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
78 \ { 'cmd': ':s/t/r/Ip', 'exp': 'Tesring string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
79 \ { 'cmd': ':s/t/r/Il', 'exp': 'Tesring string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
80 \ { 'cmd': ':s//r/Ir', 'exp': 'Testr string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
81 \ { 'cmd': ':s//r/rc', 'exp': 'Testr string', 'prompt': 'y' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
82 \ { 'cmd': ':s//r/rg', 'exp': 'Testr strr' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
83 \ { 'cmd': ':s//r/ri', 'exp': 'Testr string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
84 \ { 'cmd': ':s//r/rI', 'exp': 'Testr string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
85 \ { 'cmd': ':s//r/rn', 'exp': 'Testing string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
86 \ { 'cmd': ':s//r/rp', 'exp': 'Testr string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
87 \ { 'cmd': ':s//r/rl', 'exp': 'Testr string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
88 \ { 'cmd': ':s//r/r', 'exp': 'Testr string' },
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
89 \]
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
90
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
91 for var in variants
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
92 for run in [1, 2]
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
93 let cmd = var.cmd
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
94 if run == 2 && cmd =~ "/.*/.*/."
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
95 " Change :s/from/to/{flags} to :s{flags}
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
96 let cmd = substitute(cmd, '/.*/', '', '')
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
97 endif
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
98 call setline(1, [ln])
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
99 let msg = printf('using "%s"', cmd)
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
100 let @/='ing'
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
101 let v:errmsg = ''
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
102 call feedkeys(cmd . "\<CR>" . get(var, 'prompt', ''), 'ntx')
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
103 " No error should exist (matters for testing e flag)
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
104 call assert_equal('', v:errmsg, msg)
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
105 call assert_equal(var.exp, getline('.'), msg)
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
106 endfor
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
107 endfor
fbed07965b6a patch 8.0.0336: flags of :substitute not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 10072
diff changeset
108 endfunction
10970
ab9f7bbe4439 patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents: 10893
diff changeset
109
ab9f7bbe4439 patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents: 10893
diff changeset
110 func Test_substitute_repeat()
ab9f7bbe4439 patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents: 10893
diff changeset
111 " This caused an invalid memory access.
ab9f7bbe4439 patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents: 10893
diff changeset
112 split Xfile
ab9f7bbe4439 patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents: 10893
diff changeset
113 s/^/x
ab9f7bbe4439 patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents: 10893
diff changeset
114 call feedkeys("Qsc\<CR>y", 'tx')
ab9f7bbe4439 patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents: 10893
diff changeset
115 bwipe!
ab9f7bbe4439 patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents: 10893
diff changeset
116 endfunc
12285
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
117
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
118 " Test for *sub-replace-special* and *sub-replace-expression* on substitute().
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
119 func Test_sub_replace_1()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
120 " Run the tests with 'magic' on
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
121 set magic
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
122 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
123 call assert_equal('AA', substitute('A', 'A', '&&', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
124 call assert_equal('&', substitute('B', 'B', '\&', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
125 call assert_equal('C123456789987654321', substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
126 call assert_equal('d', substitute('D', 'D', 'd', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
127 call assert_equal('~', substitute('E', 'E', '~', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
128 call assert_equal('~', substitute('F', 'F', '\~', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
129 call assert_equal('Gg', substitute('G', 'G', '\ugg', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
130 call assert_equal('Hh', substitute('H', 'H', '\Uh\Eh', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
131 call assert_equal('iI', substitute('I', 'I', '\lII', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
132 call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
133 call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
134 call assert_equal("l\<C-V>\<C-M>l",
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
135 \ substitute('lLl', 'L', "\<C-V>\<C-M>", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
136 call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
137 call assert_equal("n\<C-V>\<C-M>n",
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
138 \ substitute('nNn', 'N', "\\\<C-V>\<C-M>", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
139 call assert_equal("o\no", substitute('oOo', 'O', '\n', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
140 call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
141 call assert_equal("q\tq", substitute('qQq', 'Q', '\t', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
142 call assert_equal('r\r', substitute('rRr', 'R', '\\', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
143 call assert_equal('scs', substitute('sSs', 'S', '\c', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
144 call assert_equal("u\nu", substitute('uUu', 'U', "\n", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
145 call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
146 call assert_equal("w\\w", substitute('wWw', 'W', "\\", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
147 call assert_equal("x\<C-M>x", substitute('xXx', 'X', "\r", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
148 call assert_equal("YyyY", substitute('Y', 'Y', '\L\uyYy\l\EY', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
149 call assert_equal("zZZz", substitute('Z', 'Z', '\U\lZzZ\u\Ez', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
150 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
151
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
152 func Test_sub_replace_2()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
153 " Run the tests with 'magic' off
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
154 set nomagic
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
155 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
156 call assert_equal('AA', substitute('A', 'A', '&&', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
157 call assert_equal('&', substitute('B', 'B', '\&', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
158 call assert_equal('C123456789987654321', substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
159 call assert_equal('d', substitute('D', 'D', 'd', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
160 call assert_equal('~', substitute('E', 'E', '~', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
161 call assert_equal('~', substitute('F', 'F', '\~', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
162 call assert_equal('Gg', substitute('G', 'G', '\ugg', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
163 call assert_equal('Hh', substitute('H', 'H', '\Uh\Eh', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
164 call assert_equal('iI', substitute('I', 'I', '\lII', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
165 call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
166 call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
167 call assert_equal("l\<C-V>\<C-M>l",
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
168 \ substitute('lLl', 'L', "\<C-V>\<C-M>", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
169 call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
170 call assert_equal("n\<C-V>\<C-M>n",
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
171 \ substitute('nNn', 'N', "\\\<C-V>\<C-M>", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
172 call assert_equal("o\no", substitute('oOo', 'O', '\n', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
173 call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
174 call assert_equal("q\tq", substitute('qQq', 'Q', '\t', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
175 call assert_equal('r\r', substitute('rRr', 'R', '\\', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
176 call assert_equal('scs', substitute('sSs', 'S', '\c', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
177 call assert_equal("t\<C-M>t", substitute('tTt', 'T', "\r", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
178 call assert_equal("u\nu", substitute('uUu', 'U', "\n", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
179 call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
180 call assert_equal('w\w', substitute('wWw', 'W', "\\", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
181 call assert_equal('XxxX', substitute('X', 'X', '\L\uxXx\l\EX', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
182 call assert_equal('yYYy', substitute('Y', 'Y', '\U\lYyY\u\Ey', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
183 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
184
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
185 func Test_sub_replace_3()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
186 set magic&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
187 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
188 call assert_equal('a\a', substitute('aAa', 'A', '\="\\"', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
189 call assert_equal('b\\b', substitute('bBb', 'B', '\="\\\\"', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
190 call assert_equal("c\rc", substitute('cCc', 'C', "\\=\"\r\"", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
191 call assert_equal("d\\\rd", substitute('dDd', 'D', "\\=\"\\\\\r\"", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
192 call assert_equal("e\\\\\re", substitute('eEe', 'E', "\\=\"\\\\\\\\\r\"", ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
193 call assert_equal('f\rf', substitute('fFf', 'F', '\="\\r"', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
194 call assert_equal('j\nj', substitute('jJj', 'J', '\="\\n"', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
195 call assert_equal("k\<C-M>k", substitute('kKk', 'K', '\="\r"', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
196 call assert_equal("l\nl", substitute('lLl', 'L', '\="\n"', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
197 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
198
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
199 " Test for submatch() on substitute().
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
200 func Test_sub_replace_4()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
201 set magic&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
202 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
203 call assert_equal('a\a', substitute('aAa', 'A',
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
204 \ '\=substitute(submatch(0), ".", "\\", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
205 call assert_equal('b\b', substitute('bBb', 'B',
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
206 \ '\=substitute(submatch(0), ".", "\\\\", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
207 call assert_equal("c\<C-V>\<C-M>c", substitute('cCc', 'C', '\=substitute(submatch(0), ".", "\<C-V>\<C-M>", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
208 call assert_equal("d\<C-V>\<C-M>d", substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\\<C-V>\<C-M>", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
209 call assert_equal("e\\\<C-V>\<C-M>e", substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-M>", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
210 call assert_equal("f\<C-M>f", substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
211 call assert_equal("j\nj", substitute('jJj', 'J', '\=substitute(submatch(0), ".", "\\n", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
212 call assert_equal("k\rk", substitute('kKk', 'K', '\=substitute(submatch(0), ".", "\r", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
213 call assert_equal("l\nl", substitute('lLl', 'L', '\=substitute(submatch(0), ".", "\n", "")', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
214 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
215
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
216 func Test_sub_replace_5()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
217 set magic&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
218 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
219 call assert_equal('A123456789987654321', substitute('A123456789',
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
220 \ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
221 \ '\=submatch(0) . submatch(9) . submatch(8) . ' .
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
222 \ 'submatch(7) . submatch(6) . submatch(5) . ' .
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
223 \ 'submatch(4) . submatch(3) . submatch(2) . submatch(1)',
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
224 \ ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
225 call assert_equal("[['A123456789'], ['9'], ['8'], ['7'], ['6'], " .
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
226 \ "['5'], ['4'], ['3'], ['2'], ['1']]",
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
227 \ substitute('A123456789',
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
228 \ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
229 \ '\=string([submatch(0, 1), submatch(9, 1), ' .
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
230 \ 'submatch(8, 1), submatch(7, 1), submatch(6, 1), ' .
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
231 \ 'submatch(5, 1), submatch(4, 1), submatch(3, 1), ' .
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
232 \ 'submatch(2, 1), submatch(1, 1)])',
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
233 \ ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
234 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
235
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
236 func Test_sub_replace_6()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
237 set magic&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
238 set cpo+=/
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
239 call assert_equal('a', substitute('A', 'A', 'a', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
240 call assert_equal('%', substitute('B', 'B', '%', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
241 set cpo-=/
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
242 call assert_equal('c', substitute('C', 'C', 'c', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
243 call assert_equal('%', substitute('D', 'D', '%', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
244 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
245
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
246 func Test_sub_replace_7()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
247 set magic&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
248 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
249 call assert_equal('AA', substitute('AA', 'A.', '\=submatch(0)', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
250 call assert_equal("B\nB", substitute("B\nB", 'B.', '\=submatch(0)', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
251 call assert_equal("['B\n']B", substitute("B\nB", 'B.', '\=string(submatch(0, 1))', ''))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
252 call assert_equal('-abab', substitute('-bb', '\zeb', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
253 call assert_equal('c-cbcbc', substitute('-bb', '\ze', 'c', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
254 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
255
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
256 " Test for *:s%* on :substitute.
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
257 func Test_sub_replace_8()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
258 new
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
259 set magic&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
260 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
261 $put =',,X'
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
262 s/\(^\|,\)\ze\(,\|X\)/\1N/g
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
263 call assert_equal('N,,NX', getline("$"))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
264 $put =',,Y'
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
265 let cmd = ':s/\(^\|,\)\ze\(,\|Y\)/\1N/gc'
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
266 call feedkeys(cmd . "\<CR>a", "xt")
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
267 call assert_equal('N,,NY', getline("$"))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
268 :$put =',,Z'
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
269 let cmd = ':s/\(^\|,\)\ze\(,\|Z\)/\1N/gc'
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
270 call feedkeys(cmd . "\<CR>yy", "xt")
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
271 call assert_equal('N,,NZ', getline("$"))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
272 enew! | close
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
273 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
274
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
275 func Test_sub_replace_9()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
276 new
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
277 set magic&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
278 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
279 $put ='xxx'
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
280 call feedkeys(":s/x/X/gc\<CR>yyq", "xt")
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
281 call assert_equal('XXx', getline("$"))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
282 enew! | close
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
283 endfunc
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
284
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
285 func Test_sub_replace_10()
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
286 set magic&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
287 set cpo&
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
288 call assert_equal('a1a2a3a', substitute('123', '\zs', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
289 call assert_equal('aaa', substitute('123', '\zs.', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
290 call assert_equal('1a2a3a', substitute('123', '.\zs', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
291 call assert_equal('a1a2a3a', substitute('123', '\ze', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
292 call assert_equal('a1a2a3', substitute('123', '\ze.', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
293 call assert_equal('aaa', substitute('123', '.\ze', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
294 call assert_equal('aa2a3a', substitute('123', '1\|\ze', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
295 call assert_equal('1aaa', substitute('123', '1\zs\|[23]', 'a', 'g'))
4963348ed734 patch 8.0.1022: test 80 is old style
Christian Brabandt <cb@256bit.org>
parents: 10970
diff changeset
296 endfunc