Mercurial > vim
annotate src/testdir/test_listener.vim @ 16660:04c2614af21c v8.1.1332
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
commit https://github.com/vim/vim/commit/fe1ade0a78a70a4c7ddaebb6964497f037f4997a
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 14 21:20:36 2019 +0200
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Problem: Cannot flush change listeners without also redrawing. The line
numbers in the list of changes may become invalid.
Solution: Add listener_flush(). Invoke listeners before adding a change
that makes line numbers invalid.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 14 May 2019 21:30:06 +0200 |
parents | b8fda384605b |
children | 978bcd70883d |
rev | line source |
---|---|
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " tests for listener_add() and listener_remove() |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
3 func s:StoreList(l) |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
4 let s:list = a:l |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
7 func s:AnotherStoreList(l) |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
8 let s:list2 = a:l |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
11 func s:EvilStoreList(l) |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
12 let s:list3 = a:l |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 call assert_fails("call add(a:l, 'myitem')", "E742:") |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 func Test_listening() |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 new |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 call setline(1, ['one', 'two']) |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
19 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
|
20 let id = listener_add({b, s, e, a, l -> s:StoreList(l)}) |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 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
|
22 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
23 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
|
24 |
16652
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
25 " 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
|
26 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
|
27 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
|
28 undo |
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
29 redraw |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
30 " the two changes get merged |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
31 call assert_equal([{'lnum': 3, 'end': 4, 'col': 1, 'added': 0}], 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 1 |
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
33 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
34 " 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
|
35 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
|
36 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
|
37 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
|
38 let s:list = [] |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
39 let s:list2 = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 exe "normal $asome\<Esc>" |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
42 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
|
43 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
|
44 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
45 " removing listener works |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 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
|
47 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
|
48 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
49 let s:list = [] |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
50 let s:list2 = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 call setline(3, 'three') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
53 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
|
54 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
|
55 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
56 " 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
|
57 " together |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 call setline(1, 'something') |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
62 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
|
63 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
|
64 \ {'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
|
65 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
66 " an insert just above a previous change that was the last one gets merged |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 call append(1, 'two two') |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
71 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
|
72 call assert_equal([{'lnum': 2, 'end': 3, '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
|
73 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
74 " 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 call assert_equal([{'lnum': 2, 'end': 3, '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
|
80 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
|
81 call assert_equal([{'lnum': 1, 'end': 1, '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
|
82 |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 " 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
|
84 %del |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
85 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
|
86 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
87 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 exe "normal Gofour\<Esc>" |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 redraw |
16660
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': 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
|
91 \ {'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
|
92 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
93 " Remove last listener |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
94 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 call listener_remove(id) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 call setline(1, 'asdfasdf') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
98 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
|
99 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 " 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
|
101 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
|
102 let s:list3 = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 call setline(1, 'asdfasdf') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
105 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
|
106 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
107 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
|
108 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 endfunc |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
118 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
119 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
|
120 new |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
125 " 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
134 " 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 \ {'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
|
146 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
147 " 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
|
148 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
|
149 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
|
150 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
|
151 4del |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 \ {'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
|
160 \ {'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
|
161 |
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_remove(id) |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
163 bwipe! |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
164 endfunc |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
165 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 endfunc |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
170 |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 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
|
172 new |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 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
|
174 let bufnr = bufnr('') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 normal ww |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
176 let id = listener_add(function('s:StoreBufList'), bufnr) |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
177 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 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
|
179 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
180 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
|
181 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
|
182 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
183 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
|
184 exe "buf " .. bufnr |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 endfunc |