Mercurial > vim
annotate src/testdir/test_listener.vim @ 16638:4790302965fc v8.1.1321
patch 8.1.1321: no docs or tests for listener functions
commit https://github.com/vim/vim/commit/a334772967de25764ed7b11d768e8b977818d0c6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat May 11 21:14:24 2019 +0200
patch 8.1.1321: no docs or tests for listener functions
Problem: No docs or tests for listener functions.
Solution: Add help and tests for listener_add() and listener_remove().
Invoke the callbacks before redrawing.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 11 May 2019 21:15:06 +0200 |
parents | |
children | a7f06505ad39 |
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 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 func StoreList(l) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 let g:list = a:l |
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 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 func AnotherStoreList(l) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 let g:list2 = a:l |
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 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 func EvilStoreList(l) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 let g:list3 = a:l |
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']) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 let id = listener_add({l -> StoreList(l)}) |
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 one') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 redraw |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], g:list) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 " Two listeners, both get called. |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 let id2 = listener_add({l -> AnotherStoreList(l)}) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 let g:list = [] |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 let g:list2 = [] |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 exe "normal $asome\<Esc>" |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 redraw |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 call assert_equal([{'lnum': 1, 'end': 2, 'col': 8, 'added': 0}], g:list) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 call assert_equal([{'lnum': 1, 'end': 2, 'col': 8, 'added': 0}], g:list2) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 call listener_remove(id2) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 let g:list = [] |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 let g:list2 = [] |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 call setline(3, 'three') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 redraw |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 call assert_equal([{'lnum': 3, 'end': 3, 'col': 1, 'added': 1}], g:list) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 call assert_equal([], g:list2) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 " the "o" command first adds an empty line and then changes it |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 let g:list = [] |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 exe "normal Gofour\<Esc>" |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 redraw |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 call assert_equal([{'lnum': 4, 'end': 4, 'col': 1, 'added': 1}, |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 \ {'lnum': 4, 'end': 5, 'col': 1, 'added': 0}], g:list) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 let g:list = [] |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 call listener_remove(id) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 call setline(1, 'asdfasdf') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 redraw |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 call assert_equal([], g:list) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 " Trying to change the list fails |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 let id = listener_add({l -> EvilStoreList(l)}) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 let g:list3 = [] |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 call setline(1, 'asdfasdf') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 redraw |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], g:list3) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 endfunc |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 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
|
65 new |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 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
|
67 let bufnr = bufnr('') |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 normal ww |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 let id = listener_add({l -> StoreList(l)}, bufnr) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 let g:list = [] |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 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
|
72 redraw |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], g:list) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 exe "buf " .. bufnr |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 bwipe! |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 endfunc |