Mercurial > vim
annotate src/testdir/test_listener.vim @ 30163:ac28d70ac476
Added tag v9.0.0417 for changeset d12d9d724d275881a42784d35881d150946154d6
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Sep 2022 15:45:04 +0200 |
parents | 711ae604980a |
children | b9a8d1c453e1 |
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! |
20178
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19779
diff
changeset
|
210 |
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19779
diff
changeset
|
211 " Invalid arguments |
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19779
diff
changeset
|
212 call assert_fails('call listener_add([])', 'E921:') |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
213 call assert_fails('call listener_add("s:StoreListArgs", [])', 'E730:') |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
214 call assert_fails('call listener_flush([])', 'E730:') |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
215 endfunc |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
216 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 endfunc |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
221 |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 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
|
223 new |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 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
|
225 let bufnr = bufnr('') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 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
|
227 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
|
228 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 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
|
230 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
231 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
|
232 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
|
233 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
234 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
|
235 exe "buf " .. bufnr |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 endfunc |
17151
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 func Test_listener_garbage_collect() |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
240 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
|
241 " NOP |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
242 endfunc |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
243 |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
244 new |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
245 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
|
246 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
|
247 " 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
|
248 normal ia |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
249 call assert_true(v:true) |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
250 |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
251 call listener_remove(id) |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
252 delfunc MyListener |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
253 bwipe! |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
254 endfunc |
17364
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 " 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
|
257 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
|
258 new |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
259 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
|
260 |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
261 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
|
262 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
|
263 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
|
264 endfor |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
265 endfunction |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
266 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
|
267 set autoindent |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
268 set cindent |
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 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
|
271 exe "normal /{}\nl" |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
272 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
|
273 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
|
274 |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
275 bwipe! |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
276 delfunc EchoChanges |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
277 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
|
278 iunmap <CR> |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
279 set nocindent |
31f31e938961
patch 8.1.1681: insert stray "{" when listener gets buffer line
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
280 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
|
281 |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
282 " 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
|
283 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
|
284 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
|
285 " NOP |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
286 endfunction |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
287 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
|
288 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
|
289 endfunction |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
290 |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
291 new |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
292 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
|
293 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
|
294 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
|
295 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
|
296 undo |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
297 |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
298 bwipe! |
d19caa851682
patch 8.1.2008: error for invalid range when using listener and undo
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 endfunc |
19044
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
303 |
19779
f3162c3ed128
patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
304 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
|
305 new |
f3162c3ed128
patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 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
|
310 endfunc |
f3162c3ed128
patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
311 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
|
312 |
f3162c3ed128
patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
313 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
|
314 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
|
315 undo |
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 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
|
317 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
|
318 " 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
|
319 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
|
320 " 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
|
321 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
|
322 |
f3162c3ed128
patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 bwipe! |
f3162c3ed128
patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
327 endfunc |
f3162c3ed128
patch 8.2.0446: listener with undo of deleting all lines not tested
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
328 |
19044
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 endfunc |
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
333 new |
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
334 " 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 %bwipe! |
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
341 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
|
342 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
|
343 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
|
344 enew! |
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
345 " 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
|
346 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
|
347 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
|
348 |
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
349 " 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 |
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
356 bwipe! |
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
357 delfunc Listener |
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
358 endfunc |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19044
diff
changeset
|
359 |
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19044
diff
changeset
|
360 func Test_col_after_deletion_moved_cur() |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
361 func Listener(bufnr, start, end, added, changes) |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19044
diff
changeset
|
362 call assert_equal([#{lnum: 1, end: 2, added: 0, col: 2}], a:changes) |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
363 endfunc |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
364 new |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
365 call setline(1, ['foo']) |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
366 let lid = listener_add('Listener') |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
367 call feedkeys("lD", 'xt') |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19044
diff
changeset
|
368 call listener_flush() |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
369 bwipe! |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
370 delfunc Listener |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19044
diff
changeset
|
371 endfunc |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
372 |
25782
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
373 func Test_remove_listener_in_callback() |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
374 new |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
375 let s:ID = listener_add('Listener') |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
376 func Listener(...) |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
377 call listener_remove(s:ID) |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
378 let g:listener_called = 'yes' |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
379 endfunc |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
380 call setline(1, ['foo']) |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
381 call feedkeys("lD", 'xt') |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
382 call listener_flush() |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
383 call assert_equal('yes', g:listener_called) |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
384 |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
385 bwipe! |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
386 delfunc Listener |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
387 unlet g:listener_called |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
388 endfunc |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
389 |
30047
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
390 " When multiple listeners are registered, remove one listener and verify the |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
391 " other listener is still called |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
392 func Test_remove_one_listener_in_callback() |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
393 new |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
394 let g:listener1_called = 0 |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
395 let g:listener2_called = 0 |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
396 let s:ID1 = listener_add('Listener1') |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
397 let s:ID2 = listener_add('Listener2') |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
398 func Listener1(...) |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
399 call listener_remove(s:ID1) |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
400 let g:listener1_called += 1 |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
401 endfunc |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
402 func Listener2(...) |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
403 let g:listener2_called += 1 |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
404 endfunc |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
405 call setline(1, ['foo']) |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
406 call feedkeys("~", 'xt') |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
407 call listener_flush() |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
408 call feedkeys("~", 'xt') |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
409 call listener_flush() |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
410 call assert_equal(1, g:listener1_called) |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
411 call assert_equal(2, g:listener2_called) |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
412 |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
413 call listener_remove(s:ID2) |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
414 bwipe! |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
415 delfunc Listener1 |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
416 delfunc Listener2 |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
417 unlet g:listener1_called |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
418 unlet g:listener2_called |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
419 endfunc |
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
420 |
27706
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
421 func Test_no_change_for_empty_undo() |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
422 new |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
423 let text = ['some word here', 'second line'] |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
424 call setline(1, text) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
425 let g:entries = [] |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
426 func Listener(bufnr, start, end, added, changes) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
427 for change in a:changes |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
428 call add(g:entries, [change.lnum, change.end, change.added]) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
429 endfor |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
430 endfunc |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
431 let s:ID = listener_add('Listener') |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
432 let @a = "one line\ntwo line\nthree line" |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
433 set undolevels& " start new undo block |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
434 call feedkeys('fwviw"ap', 'xt') |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
435 call listener_flush(bufnr()) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
436 " first change deletes "word", second change inserts the register |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
437 call assert_equal([[1, 2, 0], [1, 2, 2]], g:entries) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
438 let g:entries = [] |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
439 |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
440 set undolevels& " start new undo block |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
441 undo |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
442 call listener_flush(bufnr()) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
443 call assert_equal([[1, 4, -2]], g:entries) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
444 call assert_equal(text, getline(1, 2)) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
445 |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
446 call listener_remove(s:ID) |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
447 bwipe! |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
448 unlet g:entries |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
449 delfunc Listener |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
450 endfunc |
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
25782
diff
changeset
|
451 |
25782
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
452 |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
453 " vim: shiftwidth=2 sts=2 expandtab |