Mercurial > vim
annotate src/testdir/test_listener.vim @ 17984:2ea47dee7ddd v8.1.1988
patch 8.1.1988: :startinsert! does not work the same way as "A"
Commit: https://github.com/vim/vim/commit/8d3b51084a5bdcd2ee9e31bc03cba0d16c43d428
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 5 21:29:01 2019 +0200
patch 8.1.1988: :startinsert! does not work the same way as "A"
Problem: :startinsert! does not work the same way as "A".
Solution: Use the same code to move the cursor. (closes https://github.com/vim/vim/issues/4896)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 05 Sep 2019 21:30:03 +0200 |
parents | 2e53305f2239 |
children | d19caa851682 |
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 |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
3 func s:StoreList(s, l) |
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 |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
5 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
|
6 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
|
7 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
9 func s:AnotherStoreList(l) |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
10 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
|
11 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
13 func s:EvilStoreList(l) |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
14 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
|
15 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
|
16 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 func Test_listening() |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 new |
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', 'two']) |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
21 let s:list = [] |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
22 let id = listener_add({b, s, e, a, l -> s:StoreList(s, l)}) |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 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
|
24 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
25 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
|
26 |
16652
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
27 " 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 " 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
|
34 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
|
35 1 |
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
36 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
37 " 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
|
38 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
|
39 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
|
40 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
|
41 let s:list = [] |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
42 let s:list2 = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 exe "normal $asome\<Esc>" |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
45 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
|
46 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
|
47 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
48 " removing listener works |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 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
|
50 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
|
51 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
52 let s:list = [] |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
53 let s:list2 = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 call setline(3, 'three') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
56 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
|
57 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
|
58 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
59 " 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
|
60 " together |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 \ {'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
|
68 |
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
|
69 " 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
|
70 " merged |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
80 " 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
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 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
|
89 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
|
90 |
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
|
91 " 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
|
92 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
|
93 call listener_flush() |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
94 let s:list = [] |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
95 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
|
96 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
|
97 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
|
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 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
|
100 |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
101 " 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
|
102 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
|
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 setline(2, 'another') |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
105 1del |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 call listener_flush() |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
110 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
|
111 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
|
112 |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 " 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
|
114 %del |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
115 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
|
116 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
117 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 exe "normal Gofour\<Esc>" |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 redraw |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
120 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
|
121 \ {'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
|
122 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
123 " Remove last listener |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
124 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 call listener_remove(id) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 call setline(1, 'asdfasdf') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
128 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
|
129 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 " 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
|
131 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
|
132 let s:list3 = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 call setline(1, 'asdfasdf') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
135 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
|
136 |
17916
2e53305f2239
patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17364
diff
changeset
|
137 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
|
138 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 endfunc |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
148 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
149 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
|
150 new |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
155 " 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
164 " 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 \ {'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
|
176 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
177 " 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
|
178 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
|
179 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
|
180 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
|
181 4del |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 \ {'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
|
190 \ {'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
|
191 |
16774
0cc3f459237b
patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents:
16666
diff
changeset
|
192 " 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 1 |
0cc3f459237b
patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents:
16666
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 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
|
202 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
203 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
|
204 bwipe! |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
205 endfunc |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
206 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 endfunc |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
211 |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 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
|
213 new |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 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
|
215 let bufnr = bufnr('') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 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
|
217 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
|
218 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 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
|
220 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
221 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
|
222 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
|
223 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
224 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
|
225 exe "buf " .. bufnr |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 endfunc |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
228 |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
229 func Test_listener_garbage_collect() |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
230 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
|
231 " NOP |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
232 endfunc |
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 new |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
235 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
|
236 call test_garbagecollect_now() |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
237 " must not crach caused by invalid memory access |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
238 normal ia |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
239 call assert_true(v:true) |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
240 |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
241 call listener_remove(id) |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
242 delfunc MyListener |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
243 bwipe! |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
244 endfunc |
17364
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
245 |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
246 " 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
|
247 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
|
248 new |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
249 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
|
250 |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 endfor |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
255 endfunction |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
256 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
|
257 set autoindent |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
258 set cindent |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
259 |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
260 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
|
261 exe "normal /{}\nl" |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
262 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
|
263 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
|
264 |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
265 bwipe! |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
266 delfunc EchoChanges |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
267 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
|
268 iunmap <CR> |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
269 set nocindent |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
270 endfunc |