annotate src/testdir/test_listener.vim @ 16652:b8fda384605b v8.1.1328

patch 8.1.1328: no test for listener with undo operation commit https://github.com/vim/vim/commit/bc4fd43160739efb93c39589dcc9ffd5d5a951d0 Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 12 14:36:27 2019 +0200 patch 8.1.1328: no test for listener with undo operation Problem: No test for listener with undo operation. Solution: Add a test.
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 May 2019 14:45:04 +0200
parents a7f06505ad39
children 04c2614af21c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " tests for listener_add() and listener_remove()
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
3 func s:StoreList(l)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
4 let s:list = a:l
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 endfunc
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
7 func s:AnotherStoreList(l)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
8 let s:list2 = a:l
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 endfunc
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
11 func s:EvilStoreList(l)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
12 let s:list3 = a:l
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 call assert_fails("call add(a:l, 'myitem')", "E742:")
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 endfunc
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 func Test_listening()
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 new
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 call setline(1, ['one', 'two'])
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
19 let id = listener_add({l -> s:StoreList(l)})
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 call setline(1, 'one one')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
22 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], s:list)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
16652
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
24 " Undo is also a change
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
25 set undolevels& " start new undo block
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
26 call append(2, 'two two')
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
27 undo
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
28 redraw
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
29 call assert_equal([{'lnum': 3, 'end': 3, 'col': 1, 'added': 1},
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
30 \ {'lnum': 3, 'end': 4, 'col': 1, 'added': -1}, ], s:list)
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
31 1
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
32
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 " Two listeners, both get called.
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
34 let id2 = listener_add({l -> s:AnotherStoreList(l)})
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
35 let s:list = []
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
36 let s:list2 = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 exe "normal $asome\<Esc>"
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
39 call assert_equal([{'lnum': 1, 'end': 2, 'col': 8, 'added': 0}], s:list)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
40 call assert_equal([{'lnum': 1, 'end': 2, 'col': 8, 'added': 0}], s:list2)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 call listener_remove(id2)
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
43 let s:list = []
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
44 let s:list2 = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 call setline(3, 'three')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
47 call assert_equal([{'lnum': 3, 'end': 3, 'col': 1, 'added': 1}], s:list)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
48 call assert_equal([], s:list2)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 " the "o" command first adds an empty line and then changes it
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
51 let s:list = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 exe "normal Gofour\<Esc>"
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 redraw
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 call assert_equal([{'lnum': 4, 'end': 4, 'col': 1, 'added': 1},
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
55 \ {'lnum': 4, 'end': 5, 'col': 1, 'added': 0}], s:list)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
57 " Remove last listener
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
58 let s:list = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 call listener_remove(id)
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 call setline(1, 'asdfasdf')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
62 call assert_equal([], s:list)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 " Trying to change the list fails
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
65 let id = listener_add({l -> s:EvilStoreList(l)})
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
66 let s:list3 = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 call setline(1, 'asdfasdf')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
69 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], s:list3)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
71 call listener_remove(id)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 bwipe!
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 endfunc
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
75 func s:StoreBufList(buf, l)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
76 let s:bufnr = a:buf
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
77 let s:list = a:l
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
78 endfunc
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
79
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 func Test_listening_other_buf()
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 new
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 call setline(1, ['one', 'two'])
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 let bufnr = bufnr('')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 normal ww
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
85 let id = listener_add(function('s:StoreBufList', [bufnr]), bufnr)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
86 let s:list = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 call setbufline(bufnr, 1, 'hello')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
89 call assert_equal(bufnr, s:bufnr)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
90 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], s:list)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
92 call listener_remove(id)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 exe "buf " .. bufnr
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 bwipe!
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 endfunc