annotate src/testdir/test_listener.vim @ 19779:f3162c3ed128 v8.2.0446

patch 8.2.0446: listener with undo of deleting all lines not tested Commit: https://github.com/vim/vim/commit/a07e31af545b91925362854a48c42fee16dd8c28 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 25 21:13:46 2020 +0100 patch 8.2.0446: listener with undo of deleting all lines not tested Problem: Listener with undo of deleting all lines not tested. Solution: Add a test.
author Bram Moolenaar <Bram@vim.org>
date Wed, 25 Mar 2020 21:15:04 +0100
parents 36ec10251b2b
children 2fb397573541
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
18434
5da355d15b88 patch 8.1.2211: listener callback "added" argument is not the total
Bram Moolenaar <Bram@vim.org>
parents: 18025
diff changeset
3 func s:StoreList(s, e, a, l)
16666
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
4 let s:start = a:s
18434
5da355d15b88 patch 8.1.2211: listener callback "added" argument is not the total
Bram Moolenaar <Bram@vim.org>
parents: 18025
diff changeset
5 let s:end = a:e
5da355d15b88 patch 8.1.2211: listener callback "added" argument is not the total
Bram Moolenaar <Bram@vim.org>
parents: 18025
diff changeset
6 let s:added = a:a
16666
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
7 let s:text = getline(a:s)
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
8 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
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:AnotherStoreList(l)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
12 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
13 endfunc
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
15 func s:EvilStoreList(l)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
16 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
17 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
18 endfunc
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 func Test_listening()
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 new
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 call setline(1, ['one', 'two'])
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
23 let s:list = []
18434
5da355d15b88 patch 8.1.2211: listener callback "added" argument is not the total
Bram Moolenaar <Bram@vim.org>
parents: 18025
diff changeset
24 let id = listener_add({b, s, e, a, l -> s:StoreList(s, e, a, l)})
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 call setline(1, 'one one')
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
26 call listener_flush()
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
27 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
28
16652
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
29 " 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
30 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
31 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
32 undo
16972
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
33 call assert_equal([{'lnum': 3, 'end': 3, 'col': 1, 'added': 1}], s:list)
16652
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
34 redraw
16972
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
35 " the two changes are not merged
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
36 call assert_equal([{'lnum': 3, 'end': 4, 'col': 1, 'added': -1}], s:list)
16652
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
37 1
b8fda384605b patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents: 16648
diff changeset
38
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
39 " Two listeners, both get called. Also check column.
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
40 call setline(1, ['one one', 'two'])
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
41 call listener_flush()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
42 let id2 = listener_add({b, s, e, a, l -> s:AnotherStoreList(l)})
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 exe "normal $asome\<Esc>"
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': 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
48 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
49
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
50 " removing listener works
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 call listener_remove(id2)
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
52 call setline(1, ['one one', 'two'])
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
53 call listener_flush()
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
54 let s:list = []
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
55 let s:list2 = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 call setline(3, 'three')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
58 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
59 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
60
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
61 " a change above a previous change without a line number change is reported
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
62 " together
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
63 call setline(1, ['one one', 'two'])
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17364
diff changeset
64 call listener_flush(bufnr())
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
65 call append(2, 'two two')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
66 call setline(1, 'something')
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17364
diff changeset
67 call bufnr()->listener_flush()
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
68 call assert_equal([{'lnum': 3, 'end': 3, 'col': 1, 'added': 1},
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
69 \ {'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], s:list)
18434
5da355d15b88 patch 8.1.2211: listener callback "added" argument is not the total
Bram Moolenaar <Bram@vim.org>
parents: 18025
diff changeset
70 call assert_equal(1, s:start)
5da355d15b88 patch 8.1.2211: listener callback "added" argument is not the total
Bram Moolenaar <Bram@vim.org>
parents: 18025
diff changeset
71 call assert_equal(3, s:end)
5da355d15b88 patch 8.1.2211: listener callback "added" argument is not the total
Bram Moolenaar <Bram@vim.org>
parents: 18025
diff changeset
72 call assert_equal(1, s:added)
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
73
16972
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
74 " an insert just above a previous change that was the last one does not get
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
75 " merged
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
76 call setline(1, ['one one', 'two'])
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
77 call listener_flush()
16666
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
78 let s:list = []
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
79 call setline(2, 'something')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
80 call append(1, 'two two')
16972
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
81 call assert_equal([{'lnum': 2, 'end': 3, 'col': 1, 'added': 0}], s:list)
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
82 call listener_flush()
16972
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
83 call assert_equal([{'lnum': 2, 'end': 2, 'col': 1, 'added': 1}], s:list)
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
84
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
85 " an insert above a previous change causes a flush
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
86 call setline(1, ['one one', 'two'])
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
87 call listener_flush()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
88 call setline(2, 'something')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
89 call append(0, 'two two')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
90 call assert_equal([{'lnum': 2, 'end': 3, 'col': 1, 'added': 0}], s:list)
16666
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
91 call assert_equal('something', s:text)
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
92 call listener_flush()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
93 call assert_equal([{'lnum': 1, 'end': 1, 'col': 1, 'added': 1}], s:list)
16666
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
94 call assert_equal('two two', s:text)
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
95
16972
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
96 " a delete at a previous change that was the last one does not get merged
16666
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
97 call setline(1, ['one one', 'two'])
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
98 call listener_flush()
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
99 let s:list = []
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
100 call setline(2, 'something')
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
101 2del
16972
5493e31010e1 patch 8.1.1486: a listener change is merged even when it adds a line
Bram Moolenaar <Bram@vim.org>
parents: 16774
diff changeset
102 call assert_equal([{'lnum': 2, 'end': 3, 'col': 1, 'added': 0}], s:list)
16666
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
103 call listener_flush()
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
104 call assert_equal([{'lnum': 2, 'end': 3, 'col': 1, 'added': -1}], s:list)
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
105
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
106 " a delete above a previous change causes a flush
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
107 call setline(1, ['one one', 'two'])
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
108 call listener_flush()
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
109 call setline(2, 'another')
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
110 1del
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
111 call assert_equal([{'lnum': 2, 'end': 3, 'col': 1, 'added': 0}], s:list)
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
112 call assert_equal(2, s:start)
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
113 call assert_equal('another', s:text)
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
114 call listener_flush()
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
115 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': -1}], s:list)
978bcd70883d patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents: 16660
diff changeset
116 call assert_equal('another', s:text)
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
117
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 " the "o" command first adds an empty line and then changes it
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
119 %del
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
120 call setline(1, ['one one', 'two'])
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
121 call listener_flush()
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
122 let s:list = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 exe "normal Gofour\<Esc>"
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 redraw
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
125 call assert_equal([{'lnum': 3, 'end': 3, 'col': 1, 'added': 1},
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
126 \ {'lnum': 3, 'end': 4, '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
127
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
128 " Remove last listener
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
129 let s:list = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 call listener_remove(id)
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 call setline(1, 'asdfasdf')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
133 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
134
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 " Trying to change the list fails
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
136 let id = listener_add({b, s, e, a, l -> s:EvilStoreList(l)})
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
137 let s:list3 = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 call setline(1, 'asdfasdf')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
140 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
141
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17364
diff changeset
142 eval id->listener_remove()
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 bwipe!
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 endfunc
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
146 func s:StoreListArgs(buf, start, end, added, list)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
147 let s:buf = a:buf
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
148 let s:start = a:start
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
149 let s:end = a:end
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
150 let s:added = a:added
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
151 let s:list = a:list
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
152 endfunc
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
153
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
154 func Test_listener_args()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
155 new
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
156 call setline(1, ['one', 'two'])
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
157 let s:list = []
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
158 let id = listener_add('s:StoreListArgs')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
159
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
160 " just one change
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
161 call setline(1, 'one one')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
162 call listener_flush()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
163 call assert_equal(bufnr(''), s:buf)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
164 call assert_equal(1, s:start)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
165 call assert_equal(2, s:end)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
166 call assert_equal(0, s:added)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
167 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], s:list)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
168
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
169 " two disconnected changes
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
170 call setline(1, ['one', 'two', 'three', 'four'])
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
171 call listener_flush()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
172 call setline(1, 'one one')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
173 call setline(3, 'three three')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
174 call listener_flush()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
175 call assert_equal(bufnr(''), s:buf)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
176 call assert_equal(1, s:start)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
177 call assert_equal(4, s:end)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
178 call assert_equal(0, s:added)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
179 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0},
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
180 \ {'lnum': 3, 'end': 4, 'col': 1, 'added': 0}], s:list)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
181
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
182 " add and remove lines
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
183 call setline(1, ['one', 'two', 'three', 'four', 'five', 'six'])
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
184 call listener_flush()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
185 call append(2, 'two two')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
186 4del
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
187 call append(5, 'five five')
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
188 call listener_flush()
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
189 call assert_equal(bufnr(''), s:buf)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
190 call assert_equal(3, s:start)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
191 call assert_equal(6, s:end)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
192 call assert_equal(1, s:added)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
193 call assert_equal([{'lnum': 3, 'end': 3, 'col': 1, 'added': 1},
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
194 \ {'lnum': 4, 'end': 5, 'col': 1, 'added': -1},
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
195 \ {'lnum': 6, 'end': 6, 'col': 1, 'added': 1}], s:list)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
196
16774
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
197 " split a line then insert one, should get two disconnected change lists
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
198 call setline(1, 'split here')
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
199 call listener_flush()
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
200 let s:list = []
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
201 exe "normal 1ggwi\<CR>\<Esc>"
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
202 1
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
203 normal o
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
204 call assert_equal([{'lnum': 1, 'end': 2, 'col': 7, 'added': 1}], s:list)
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
205 call listener_flush()
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
206 call assert_equal([{'lnum': 2, 'end': 2, 'col': 1, 'added': 1}], s:list)
0cc3f459237b patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents: 16666
diff changeset
207
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
208 call listener_remove(id)
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
209 bwipe!
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
210 endfunc
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
211
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
212 func s:StoreBufList(buf, start, end, added, list)
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
213 let s:bufnr = a:buf
16660
04c2614af21c patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents: 16652
diff changeset
214 let s:list = a:list
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
215 endfunc
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
216
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 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
218 new
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 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
220 let bufnr = bufnr('')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 normal ww
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17364
diff changeset
222 let id = bufnr->listener_add(function('s:StoreBufList'))
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
223 let s:list = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 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
225 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
226 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
227 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
228
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
229 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
230 exe "buf " .. bufnr
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 bwipe!
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 endfunc
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
233
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
234 func Test_listener_garbage_collect()
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
235 func MyListener(x, bufnr, start, end, added, changes)
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
236 " NOP
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
237 endfunc
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
238
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
239 new
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
240 let id = listener_add(function('MyListener', [{}]), bufnr(''))
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
241 call test_garbagecollect_now()
18025
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
242 " must not crash caused by invalid memory access
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
243 normal ia
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
244 call assert_true(v:true)
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
245
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
246 call listener_remove(id)
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
247 delfunc MyListener
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
248 bwipe!
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 16972
diff changeset
249 endfunc
17364
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
250
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
251 " This verifies the fix for issue #4455
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
252 func Test_listener_caches_buffer_line()
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
253 new
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
254 inoremap <silent> <CR> <CR><Esc>O
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
255
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
256 function EchoChanges(bufnr, start, end, added, changes)
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
257 for l:change in a:changes
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
258 let text = getbufline(a:bufnr, l:change.lnum, l:change.end-1+l:change.added)
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
259 endfor
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
260 endfunction
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
261 let lid = listener_add("EchoChanges")
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
262 set autoindent
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
263 set cindent
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
264
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
265 call setline(1, ["{", "\tif true {}", "}"])
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
266 exe "normal /{}\nl"
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
267 call feedkeys("i\r\e", 'xt')
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
268 call assert_equal(["{", "\tif true {", "", "\t}", "}"], getline(1, 5))
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
269
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
270 bwipe!
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
271 delfunc EchoChanges
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
272 call listener_remove(lid)
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
273 iunmap <CR>
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
274 set nocindent
31f31e938961 patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
275 endfunc
18025
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
276
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
277 " Verify the fix for issue #4908
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
278 func Test_listener_undo_line_number()
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
279 function DoIt()
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
280 " NOP
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
281 endfunction
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
282 function EchoChanges(bufnr, start, end, added, changes)
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
283 call DoIt()
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
284 endfunction
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
285
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
286 new
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
287 let lid = listener_add("EchoChanges")
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
288 call setline(1, ['a', 'b', 'c'])
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
289 set undolevels& " start new undo block
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
290 call feedkeys("ggcG\<Esc>", 'xt')
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
291 undo
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
292
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
293 bwipe!
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
294 delfunc DoIt
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
295 delfunc EchoChanges
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
296 call listener_remove(lid)
d19caa851682 patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
297 endfunc
19044
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
298
19779
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
299 func Test_listener_undo_delete_all()
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
300 new
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
301 call setline(1, [1, 2, 3, 4])
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
302 let s:changes = []
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
303 func s:ExtendList(bufnr, start, end, added, changes)
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
304 call extend(s:changes, a:changes)
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
305 endfunc
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
306 let id = listener_add('s:ExtendList')
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
307
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
308 set undolevels& " start new undo block
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
309 normal! ggdG
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
310 undo
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
311 call listener_flush()
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
312 call assert_equal(2, s:changes->len())
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
313 " delete removes four lines, empty line remains
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
314 call assert_equal({'lnum': 1, 'end': 5, 'col': 1, 'added': -4}, s:changes[0])
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
315 " undo replaces empty line and adds 3 lines
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
316 call assert_equal({'lnum': 1, 'end': 2, 'col': 1, 'added': 3}, s:changes[1])
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
317
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
318 call listener_remove(id)
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
319 delfunc s:ExtendList
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
320 unlet s:changes
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
321 bwipe!
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
322 endfunc
f3162c3ed128 patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents: 19534
diff changeset
323
19044
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
324 func Test_listener_cleared_newbuf()
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
325 func Listener(bufnr, start, end, added, changes)
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
326 let g:gotCalled += 1
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
327 endfunc
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
328 new
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
329 " check that listening works
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
330 let g:gotCalled = 0
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
331 let lid = listener_add("Listener")
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
332 call feedkeys("axxx\<Esc>", 'xt')
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
333 call listener_flush(bufnr())
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
334 call assert_equal(1, g:gotCalled)
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
335 %bwipe!
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
336 let bufnr = bufnr()
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
337 let b:testing = 123
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
338 let lid = listener_add("Listener")
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
339 enew!
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
340 " check buffer is reused
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
341 call assert_equal(bufnr, bufnr())
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
342 call assert_false(exists('b:testing'))
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
343
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
344 " check that listening stops when reusing the buffer
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
345 let g:gotCalled = 0
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
346 call feedkeys("axxx\<Esc>", 'xt')
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
347 call listener_flush(bufnr())
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
348 call assert_equal(0, g:gotCalled)
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
349 unlet g:gotCalled
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
350
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
351 bwipe!
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
352 delfunc Listener
af795b6a2624 patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents: 18434
diff changeset
353 endfunc
19534
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
354
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
355 func Test_col_after_deletion_moved_cur()
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
356 func Listener(bufnr, start, end, added, changes)
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
357 call assert_equal([#{lnum: 1, end: 2, added: 0, col: 2}], a:changes)
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
358 endfunc
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
359 new
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
360 call setline(1, ['foo'])
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
361 let lid = listener_add('Listener')
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
362 call feedkeys("lD", 'xt')
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
363 call listener_flush()
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
364 bwipe!
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
365 delfunc Listener
36ec10251b2b patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents: 19044
diff changeset
366 endfunc