annotate src/testdir/test_filter_cmd.vim @ 9980:b222552cf0c4 v7.4.2263

commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 26 22:29:11 2016 +0200 patch 7.4.2263 Problem: :filter does not work for many commands. Can only get matching messages. Solution: Make :filter work for :command, :map, :list, :number and :print. Make ":filter!" show non-matching lines.
author Christian Brabandt <cb@256bit.org>
date Fri, 26 Aug 2016 22:30:07 +0200
parents e975914c17e9
children 4b152b5f414f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9941
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test the :filter command modifier
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 func Test_filter()
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 edit Xdoesnotmatch
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 edit Xwillmatch
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 call assert_equal('"Xwillmatch"', substitute(execute('filter willma ls'), '[^"]*\(".*"\)[^"]*', '\1', ''))
9980
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
7 bwipe Xdoesnotmatch
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
8 bwipe Xwillmatch
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
9
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
10 new
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
11 call setline(1, ['foo1', 'foo2', 'foo3', 'foo4', 'foo5'])
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
12 call assert_equal("\nfoo2\nfoo4", execute('filter /foo[24]/ 1,$print'))
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
13 call assert_equal("\n 2 foo2\n 4 foo4", execute('filter /foo[24]/ 1,$number'))
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
14 call assert_equal("\nfoo2$\nfoo4$", execute('filter /foo[24]/ 1,$list'))
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
15
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
16 call assert_equal("\nfoo1$\nfoo3$\nfoo5$", execute('filter! /foo[24]/ 1,$list'))
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
17 bwipe!
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
18
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
19 command XTryThis echo 'this'
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
20 command XTryThat echo 'that'
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
21 command XDoThat echo 'that'
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
22 let lines = split(execute('filter XTry command'), "\n")
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
23 call assert_equal(3, len(lines))
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
24 call assert_match("XTryThat", lines[1])
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
25 call assert_match("XTryThis", lines[2])
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
26 delcommand XTryThis
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
27 delcommand XTryThat
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
28 delcommand XDoThat
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
29
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
30 map f1 the first key
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
31 map f2 the second key
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
32 map f3 not a key
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
33 let lines = split(execute('filter the map f'), "\n")
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
34 call assert_equal(2, len(lines))
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
35 call assert_match("f2", lines[0])
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
36 call assert_match("f1", lines[1])
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
37 unmap f1
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
38 unmap f2
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
39 unmap f3
9941
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 endfunc
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 func Test_filter_fails()
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 call assert_fails('filter', 'E471:')
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 call assert_fails('filter pat', 'E476:')
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call assert_fails('filter /pat', 'E476:')
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call assert_fails('filter /pat/', 'E476:')
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 call assert_fails('filter /pat/ asdf', 'E492:')
9980
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
48
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
49 call assert_fails('filter!', 'E471:')
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
50 call assert_fails('filter! pat', 'E476:')
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
51 call assert_fails('filter! /pat', 'E476:')
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
52 call assert_fails('filter! /pat/', 'E476:')
b222552cf0c4 commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents: 9941
diff changeset
53 call assert_fails('filter! /pat/ asdf', 'E492:')
9941
e975914c17e9 commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 endfunc