2 # Copyright Simon Lydell 2016.
4 # This file is part of VimFx.
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.
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.
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/>.
20 testUtils = require('./utils')
21 createConfigAPI = require('../lib/api-frame')
25 exports['test exports'] = (assert, $vim) ->
26 vimfx = createConfigAPI($vim)
28 assert.equal(typeof vimfx.listen, 'function', 'listen')
29 assert.equal(typeof vimfx.setHintMatcher, 'function', 'setHintMatcher')
31 exports['test vimfx.listen'] = (assert, $vim, teardown) ->
33 onShutdown = (fn) -> shutdownHandlers.push(fn)
34 vimfx = createConfigAPI($vim, onShutdown)
38 reset() for reset in resets
42 messageManager = new testUtils.MockMessageManager()
43 for name, fn of messageManager when typeof fn == 'function'
45 testUtils.stub(FRAME_SCRIPT_ENVIRONMENT, name, fn.bind(messageManager))
48 vimfx.listen('message', ->)
49 assert.equal(messageManager.sendAsyncMessageCalls, 0)
50 assert.equal(messageManager.addMessageListenerCalls, 1)
51 assert.equal(messageManager.removeMessageListenerCalls, 0)
53 assert.equal(shutdownHandlers.length, 1)
55 assert.equal(messageManager.sendAsyncMessageCalls, 0)
56 assert.equal(messageManager.addMessageListenerCalls, 1)
57 assert.equal(messageManager.removeMessageListenerCalls, 1)
59 exports['test vimfx.setHintMatcher'] = (assert, $vim) ->
61 onShutdown = (fn) -> shutdownHandlers.push(fn)
62 vimfx = createConfigAPI($vim, onShutdown)
64 assert.ok(not $vim.hintMatcher)
67 vimfx.setHintMatcher(hintMatcher)
68 assert.equal($vim.hintMatcher, hintMatcher)
70 assert.equal(shutdownHandlers.length, 1)
72 assert.ok(not $vim.hintMatcher)
74 exports['test vimfx.listen errors'] = (assert, $vim) ->
75 vimfx = createConfigAPI($vim)
77 throws(assert, /message string/i, 'undefined', ->
81 throws(assert, /message string/i, 'false', ->
85 throws(assert, /listener function/i, 'undefined', ->
86 vimfx.listen('message')
89 throws(assert, /listener function/i, 'false', ->
90 vimfx.listen('message', false)
93 exports['test vimfx.setHintMatcher errors'] = (assert, $vim) ->
94 vimfx = createConfigAPI($vim)
96 throws(assert, /function/i, 'undefined', ->
97 vimfx.setHintMatcher()
100 throws(assert, /function/i, 'false', ->
101 vimfx.setHintMatcher(false)