summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0891
blob: d897b585c35f8d63319a4d13d105cbcd9f20d49d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0891
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0891
Problem:    Substitute command inssuficiently tested.
Solution:   Add more test coverage. (Dominique Pelle)
Files:	    src/testdir/test_substitute.vim


*** ../vim-8.1.0890/src/testdir/test_substitute.vim	2019-02-10 21:55:23.109307873 +0100
--- src/testdir/test_substitute.vim	2019-02-10 22:48:01.208799319 +0100
***************
*** 141,146 ****
--- 141,230 ----
    bwipe!
  endfunc
  
+ " Test %s/\n// which is implemented as a special case to use a
+ " more efficient join rather than doing a regular substitution.
+ func Test_substitute_join()
+   new
+ 
+   call setline(1, ["foo\tbar", "bar\<C-H>foo"])
+   let a = execute('%s/\n//')
+   call assert_equal("", a)
+   call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
+   call assert_equal('\n', histget("search", -1))
+ 
+   call setline(1, ["foo\tbar", "bar\<C-H>foo"])
+   let a = execute('%s/\n//g')
+   call assert_equal("", a)
+   call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
+   call assert_equal('\n', histget("search", -1))
+ 
+   call setline(1, ["foo\tbar", "bar\<C-H>foo"])
+   let a = execute('%s/\n//p')
+   call assert_equal("\nfoo     barbar^Hfoo", a)
+   call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
+   call assert_equal('\n', histget("search", -1))
+ 
+   call setline(1, ["foo\tbar", "bar\<C-H>foo"])
+   let a = execute('%s/\n//l')
+   call assert_equal("\nfoo^Ibarbar^Hfoo$", a)
+   call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
+   call assert_equal('\n', histget("search", -1))
+ 
+   call setline(1, ["foo\tbar", "bar\<C-H>foo"])
+   let a = execute('%s/\n//#')
+   call assert_equal("\n  1 foo     barbar^Hfoo", a)
+   call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
+   call assert_equal('\n', histget("search", -1))
+ 
+   bwipe!
+ endfunc
+ 
+ func Test_substitute_count()
+   new
+   call setline(1, ['foo foo', 'foo foo', 'foo foo', 'foo foo', 'foo foo'])
+   2
+ 
+   s/foo/bar/3
+   call assert_equal(['foo foo', 'bar foo', 'bar foo', 'bar foo', 'foo foo'],
+   \                 getline(1, '$'))
+ 
+   call assert_fails('s/foo/bar/0', 'E939:')
+ 
+   bwipe!
+ endfunc
+ 
+ " Test substitute 'n' flag (report number of matches, do not substitute).
+ func Test_substitute_flag_n()
+   new
+   let lines = ['foo foo', 'foo foo', 'foo foo', 'foo foo', 'foo foo']
+   call setline(1, lines)
+ 
+   call assert_equal("\n3 matches on 3 lines", execute('2,4s/foo/bar/n'))
+   call assert_equal("\n6 matches on 3 lines", execute('2,4s/foo/bar/gn'))
+ 
+   " c flag (confirm) should be ignored when using n flag.
+   call assert_equal("\n3 matches on 3 lines", execute('2,4s/foo/bar/nc'))
+ 
+   " No substitution should have been done.
+   call assert_equal(lines, getline(1, '$'))
+ 
+   bwipe!
+ endfunc
+ 
+ func Test_substitute_errors()
+   new
+   call setline(1, 'foobar')
+ 
+   call assert_fails('s/FOO/bar/', 'E486:')
+   call assert_fails('s/foo/bar/@', 'E488:')
+   call assert_fails('s/\(/bar/', 'E476:')
+ 
+   setl nomodifiable
+   call assert_fails('s/foo/bar/', 'E21:')
+ 
+   bwipe!
+ endfunc
+ 
  " Test for *sub-replace-special* and *sub-replace-expression* on substitute().
  func Test_sub_replace_1()
    " Run the tests with 'magic' on
*** ../vim-8.1.0890/src/version.c	2019-02-10 22:43:30.158824050 +0100
--- src/version.c	2019-02-10 22:49:31.960124516 +0100
***************
*** 785,786 ****
--- 785,788 ----
  {   /* Add new patch number below this line */
+ /**/
+     891,
  /**/

-- 
INSPECTOR END OF FILM: Move along.  There's nothing to see!  Keep moving!
   [Suddenly he notices the cameras.]
INSPECTOR END OF FILM: (to Camera) All right, put that away sonny.
   [He walks over to it and puts his hand over the lens.]
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///