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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
function! Setup(snip) abort
return snipMate#expandSnip(join(a:snip, "\n"), 1)
endfunction
function! s:to_be_file(expected) abort
return a:expected == getline(1,'$')
endfunction
function! s:to_be_in(item, list) abort
return !empty(filter(copy(a:list), 'v:val is a:item'))
endfunction
call vspec#customize_matcher('to_be_file', function('s:to_be_file'))
call vspec#customize_matcher('to_be_in', function('s:to_be_in'))
describe 'snippet state'
before
enew
let b:snip_state = snipmate#jumping#state()
end
after
bwipeout!
end
describe '.remove()'
it 'removes the state object'
Expect exists('b:snip_state') to_be_true
call b:snip_state.remove()
Expect exists('b:snip_state') to_be_false
end
it 'removes snippet related autocommands'
function! ReadAutocmds()
redir => autocmds
0verbose au snipmate_changes * <buffer>
redir END
return split(autocmds, "\n")
endfunction
aug snipmate_changes
au CursorMoved,CursorMovedI <buffer> echo 'event'
aug END
Expect len(ReadAutocmds()) > 1
call b:snip_state.remove()
Expect len(ReadAutocmds()) == 1
end
end
describe '.find_next_stop()'
it 'increments/decrements the stop_no'
let b:snip_state.stops = { 1 : {}, 2 : {} }
let b:snip_state.stop_no = 1
let b:snip_state.stop_count = 4
call b:snip_state.find_next_stop(0)
Expect b:snip_state.stop_no == 2
call b:snip_state.find_next_stop(1)
Expect b:snip_state.stop_no == 1
end
it 'continues iterating if the next/previous stop does not exist'
let b:snip_state.stops = { 3 : {} }
let b:snip_state.stop_count = 6
let b:snip_state.stop_no = 1
call b:snip_state.find_next_stop(0)
Expect b:snip_state.stop_no == 3
let b:snip_state.stop_no = 5
call b:snip_state.find_next_stop(1)
Expect b:snip_state.stop_no == 3
end
it 'does something at the ends'
"
end
end
describe '.remove_nested()'
it 'removes nested mirrors and only nested mirrors'
let mirror = { 'line' : 0 }
let b:snip_state.stops = { 1 : { 'placeholder' : [[2, mirror]] },
\ 2 : { 'mirrors' : [mirror, {}] } }
call b:snip_state.remove_nested(1)
Expect len(b:snip_state.stops[2].mirrors) == 1
Expect b:snip_state.stops[2].mirrors[0] isnot mirror
end
it 'removes nested stops'
let stop = [2, 'abc']
let b:snip_state.stops = { 1 : { 'placeholder' : [stop] },
\ 2 : { 'placeholder' : stop[1:1] } }
call b:snip_state.remove_nested(1)
Expect len(b:snip_state.stops) == 1
Expect keys(b:snip_state.stops) == ['1']
end
end
describe '.find_update_objects()'
it 'finds mirrors/stops on the same line and after cur_stop'
let b:snip_state.stops = {
\ 1 : { 'line' : 1, 'col' : 5,
\ 'placeholder' : ['x'] },
\ 2 : { 'line' : 1, 'col' : 7,
\ 'mirrors' : [{ 'line' : 1, 'col' : 7 }] }
\ }
let stop = b:snip_state.stops[1]
call b:snip_state.find_update_objects(stop)
for obj in stop.update_objects
Expect obj to_be_in [ b:snip_state.stops[2],
\ b:snip_state.stops[2].mirrors[0] ]
endfor
end
it 'finds mirrors/stops on the same line and after cur_stop mirrors'
let b:snip_state.stops = {
\ 1 : { 'line' : 1, 'col' : 5,
\ 'mirrors' : [{ 'line' : 2, 'col' : 5 }],
\ 'placeholder' : ['x'] },
\ 2 : { 'line' : 2, 'col' : 7,
\ 'mirrors' : [{ 'line' : 2, 'col' : 7 }] }
\ }
let stop = b:snip_state.stops[1]
call b:snip_state.find_update_objects(stop)
for obj in stop.update_objects
Expect obj to_be_in [ b:snip_state.stops[2],
\ b:snip_state.stops[2].mirrors[0] ]
endfor
end
it 'ignores mirrors/stops on other lines'
let b:snip_state.stops = {
\ 1 : { 'line' : 2, 'col' : 5,
\ 'placeholder' : ['x'] },
\ 2 : { 'line' : 1, 'col' : 7,
\ 'mirrors' : [{ 'line' : 1, 'col' : 7 }] },
\ 3 : { 'line' : 3, 'col' : 7,
\ 'mirrors' : [{ 'line' : 3, 'col' : 7 }] }
\ }
let stop = b:snip_state.stops[1]
call b:snip_state.find_update_objects(stop)
Expect empty(stop.update_objects) to_be_true
end
it 'ignores mirrors/stops on the same line but before cur_stop/mirrors'
let b:snip_state.stops = {
\ 1 : { 'line' : 1, 'col' : 5,
\ 'mirrors' : [{ 'line' : 2, 'col' : 5 }],
\ 'placeholder' : ['x'] },
\ 2 : { 'line' : 1, 'col' : 1,
\ 'mirrors' : [{ 'line' : 2, 'col' : 1 }] },
\ 3 : { 'line' : 2, 'col' : 3,
\ 'mirrors' : [{ 'line' : 1, 'col' : 3 }] },
\ }
let stop = b:snip_state.stops[1]
call b:snip_state.find_update_objects(stop)
Expect empty(stop.update_objects) to_be_true
end
end
end
|