]> git.gir.st - VimFx.git/blob - extension/test/utils.coffee
Rework programmatic customization of VimFx
[VimFx.git] / extension / test / utils.coffee
1 ###
2 # Copyright Simon Lydell 2015, 2016.
3 #
4 # This file is part of VimFx.
5 #
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
18 ###
19
20 # This file provides some handy helpers for testing.
21
22 Vim = require('../lib/vim')
23
24 stub = (obj, method, fn) ->
25 originalFn = obj[method]
26 obj[method] = fn
27 return -> obj[method] = originalFn
28
29 throws = (assert, regex, badValue, fn) ->
30 assert.throws(fn)
31 try fn() catch error
32 assert.ok(error.message.startsWith('VimFx:'), 'start with VimFx')
33 assert.ok(error.message.endsWith(": #{badValue}"), 'show bad value')
34 assert.ok(regex.test(error.message), 'regex match')
35
36 class MockMessageManager
37 constructor: ->
38 @sendAsyncMessageCalls = 0
39 @addMessageListenerCalls = 0
40 @removeMessageListenerCalls = 0
41
42 sendAsyncMessage: -> @sendAsyncMessageCalls++
43 addMessageListener: -> @addMessageListenerCalls++
44 removeMessageListener: -> @removeMessageListenerCalls++
45
46 class MockVim extends Vim
47 constructor: (@_messageManager = null) ->
48
49 module.exports = {
50 stub
51 throws
52 MockMessageManager
53 MockVim
54 }
Imprint / Impressum