Mercurial > vim
annotate src/testdir/test_listener.vim @ 16774:0cc3f459237b v8.1.1389
patch 8.1.1389: changes are not flushed when end and start overlap
commit https://github.com/vim/vim/commit/7b31a181c84ec6b9050892e80f3132907569f8d8
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 24 21:39:27 2019 +0200
patch 8.1.1389: changes are not flushed when end and start overlap
Problem: Changes are not flushed when end and start overlap. (Paul Jolly)
Solution: When end of a previous changes overlaps with start of a new
change, first flush listeners.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 24 May 2019 21:45:05 +0200 |
parents | 978bcd70883d |
children | 5493e31010e1 |
rev | line source |
---|---|
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " tests for listener_add() and listener_remove() |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
3 func s:StoreList(s, l) |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
4 let s:start = a:s |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
5 let s:text = getline(a:s) |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
6 let s:list = a:l |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
9 func s:AnotherStoreList(l) |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
10 let s:list2 = a:l |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
13 func s:EvilStoreList(l) |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
14 let s:list3 = a:l |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 call assert_fails("call add(a:l, 'myitem')", "E742:") |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 func Test_listening() |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 new |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 call setline(1, ['one', 'two']) |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
21 let s:list = [] |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
22 let id = listener_add({b, s, e, a, l -> s:StoreList(s, l)}) |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 call setline(1, 'one one') |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
24 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
25 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], s:list) |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 |
16652
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
27 " Undo is also a change |
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
28 set undolevels& " start new undo block |
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
29 call append(2, 'two two') |
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
30 undo |
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
31 redraw |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
32 " 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
|
33 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
|
34 1 |
b8fda384605b
patch 8.1.1328: no test for listener with undo operation
Bram Moolenaar <Bram@vim.org>
parents:
16648
diff
changeset
|
35 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
36 " 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
|
37 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
|
38 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
|
39 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
|
40 let s:list = [] |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
41 let s:list2 = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 exe "normal $asome\<Esc>" |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
44 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
|
45 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
|
46 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
47 " removing listener works |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 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
|
49 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
|
50 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
51 let s:list = [] |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
52 let s:list2 = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 call setline(3, 'three') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
55 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
|
56 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
|
57 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
58 " 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
|
59 " together |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 \ {'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
|
67 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
68 " 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 call append(1, 'two two') |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
74 call assert_equal([], 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
|
75 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
|
76 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
|
77 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
78 " 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
|
79 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
|
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 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
89 " a delete at a previous change that was the last one gets merged |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
90 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
|
91 call listener_flush() |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
92 let s:list = [] |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
93 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
|
94 2del |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
95 call assert_equal([], s:list) |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
96 call listener_flush() |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
97 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
|
98 |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
99 " 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
|
100 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
|
101 call listener_flush() |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
102 call setline(2, 'another') |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
103 1del |
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': 0}], s:list) |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
105 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
|
106 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
|
107 call listener_flush() |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
108 call assert_equal([{'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
|
109 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
|
110 |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 " 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
|
112 %del |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
113 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
|
114 call listener_flush() |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
115 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 exe "normal Gofour\<Esc>" |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 redraw |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
118 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
|
119 \ {'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
|
120 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
121 " Remove last listener |
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 call listener_remove(id) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 call setline(1, 'asdfasdf') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
126 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
|
127 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 " 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
|
129 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
|
130 let s:list3 = [] |
16638
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([{'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
|
134 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
135 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
|
136 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 endfunc |
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 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
|
148 new |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
153 " 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
162 " 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 \ {'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
|
174 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
175 " 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
|
176 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
|
177 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
|
178 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
|
179 4del |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
180 call append(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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 \ {'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
|
188 \ {'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
|
189 |
16774
0cc3f459237b
patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents:
16666
diff
changeset
|
190 " 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 1 |
0cc3f459237b
patch 8.1.1389: changes are not flushed when end and start overlap
Bram Moolenaar <Bram@vim.org>
parents:
16666
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 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
|
200 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
201 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
|
202 bwipe! |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
203 endfunc |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
204 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16652
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 endfunc |
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
209 |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 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
|
211 new |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 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
|
213 let bufnr = bufnr('') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 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
|
215 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
|
216 let s:list = [] |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 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
|
218 redraw |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
219 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
|
220 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
|
221 |
16648
a7f06505ad39
patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
222 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
|
223 exe "buf " .. bufnr |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 endfunc |