annotate src/testdir/test_listener.vim @ 16648:a7f06505ad39 v8.1.1326

patch 8.1.1326: no test for listener with partial commit https://github.com/vim/vim/commit/8aad88d8de256e58f04054eb7230c9613e26502f Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 12 13:53:50 2019 +0200 patch 8.1.1326: no test for listener with partial Problem: No test for listener with partial. Solution: Add a test. Add example to help.
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 May 2019 14:00:07 +0200
parents 4790302965fc
children b8fda384605b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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'])
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
19 let id = listener_add({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
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
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
22 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
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.
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
25 let id2 = listener_add({l -> s:AnotherStoreList(l)})
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
26 let s:list = []
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
27 let s:list2 = []
16638
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
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
30 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
31 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
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)
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
34 let s:list = []
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
35 let s:list2 = []
16638
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
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
38 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
39 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
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
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
42 let s:list = []
16638
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},
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
46 \ {'lnum': 4, 'end': 5, '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
47
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
48 " Remove last listener
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
49 let s:list = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 call listener_remove(id)
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 call setline(1, 'asdfasdf')
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([], s:list)
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 " Trying to change the list fails
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
56 let id = listener_add({l -> s:EvilStoreList(l)})
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
57 let s:list3 = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 call setline(1, 'asdfasdf')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
60 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
61
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
62 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
63 bwipe!
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 endfunc
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
66 func s:StoreBufList(buf, l)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
67 let s:bufnr = a:buf
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
68 let s:list = a:l
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
69 endfunc
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
70
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 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
72 new
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 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
74 let bufnr = bufnr('')
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 normal ww
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
76 let id = listener_add(function('s:StoreBufList', [bufnr]), bufnr)
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
77 let s:list = []
16638
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 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
79 redraw
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
80 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
81 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
82
16648
a7f06505ad39 patch 8.1.1326: no test for listener with partial
Bram Moolenaar <Bram@vim.org>
parents: 16638
diff changeset
83 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
84 exe "buf " .. bufnr
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 bwipe!
4790302965fc patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 endfunc