forked from lambdalisue/vim-fern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.vimspec
57 lines (53 loc) · 1.75 KB
/
hook.vimspec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Describe fern#hook
Describe #emit()
It emits hooks added by #add()
let ns1 = []
let ns2 = []
call fern#hook#add('t', { -> extend(ns1, a:000) })
call fern#hook#add('t', { -> extend(ns2, a:000) })
call fern#hook#emit('t', 'hello', 'world')
Assert Equals(ns1, ['hello', 'world'])
Assert Equals(ns2, ['hello', 'world'])
End
It emits hooks added by #add() and remove 'once' hooks
let ns1 = []
let ns2 = []
call fern#hook#add('t', { -> extend(ns1, a:000) })
call fern#hook#add('t', { -> extend(ns2, a:000) }, {
\ 'once': 1,
\})
call fern#hook#emit('t', 'hello', 'world')
Assert Equals(ns1, ['hello', 'world'])
Assert Equals(ns2, ['hello', 'world'])
call fern#hook#emit('t', 'hello', 'world')
Assert Equals(ns1, ['hello', 'world', 'hello', 'world'])
Assert Equals(ns2, ['hello', 'world'])
End
End
Describe #remove()
It removes a specified hook
let ns1 = []
let ns2 = []
call fern#hook#add('t', { -> extend(ns1, a:000) })
call fern#hook#add('t', { -> extend(ns2, a:000) }, {
\ 'id': 'remove this'
\})
call fern#hook#remove('t', 'remove this')
call fern#hook#emit('t', 'hello', 'world')
Assert Equals(ns1, ['hello', 'world'])
Assert Equals(ns2, [])
End
It removes all hooks if no {id} has specified
let ns1 = []
let ns2 = []
call fern#hook#add('t', { -> extend(ns1, a:000) })
call fern#hook#add('t', { -> extend(ns2, a:000) }, {
\ 'id': 'remove this'
\})
call fern#hook#remove('t')
call fern#hook#emit('t', 'hello', 'world')
Assert Equals(ns1, [])
Assert Equals(ns2, [])
End
End
End