-
Notifications
You must be signed in to change notification settings - Fork 268
/
test_plugin_mappings.py
66 lines (52 loc) · 2.45 KB
/
test_plugin_mappings.py
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
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
sys.path.append(u'../ftplugin')
import unittest
import orgmode.settings
from orgmode.exceptions import PluginError
from orgmode._vim import ORGMODE
from orgmode.keybinding import MODE_ALL, Plug
import vim
from orgmode.py3compat.encode_compatibility import *
ORG_PLUGINS = ['ShowHide', '|', 'Navigator', 'EditStructure', '|', 'Hyperlinks', '|', 'Todo', 'TagsProperties', 'Date', 'Agenda', 'Misc', '|', 'Export']
class MappingTestCase(unittest.TestCase):
u"""Tests all plugins for overlapping mappings."""
def test_non_overlapping_plug_mappings(self):
def find_overlapping_mappings(kb, all_keybindings):
found_overlapping_mapping = False
for tkb in all_keybindings:
if kb.mode == tkb.mode or MODE_ALL in (kb.mode, tkb.mode):
if isinstance(kb._action, Plug) and isinstance(tkb._action, Plug):
akb = kb.action
atkb = tkb.action
if (akb.startswith(atkb) or atkb.startswith(akb)) and akb != atkb:
print(u'\nERROR: Found overlapping mapping: %s (%s), %s (%s)' % (kb.key, akb, tkb.key, atkb))
found_overlapping_mapping = True
if all_keybindings:
res = find_overlapping_mappings(all_keybindings[0], all_keybindings[1:])
if not found_overlapping_mapping:
return res
return found_overlapping_mapping
if self.keybindings:
self.assertFalse(find_overlapping_mappings(self.keybindings[0], self.keybindings[1:]))
def setUp(self):
self.keybindings = []
vim.EVALRESULTS = {
u'exists("g:org_debug")': 0,
u'exists("b:org_debug")': 0,
u'exists("*repeat#set()")': 0,
u'b:changedtick': 0,
u_encode(u'exists("b:org_plugins")'): 0,
u_encode(u'exists("g:org_plugins")'): 1,
u_encode(u'g:org_plugins'): ORG_PLUGINS,
}
for plugin in filter(lambda p: p != '|', ORG_PLUGINS):
try:
ORGMODE.register_plugin(plugin)
except PluginError:
pass
if plugin in ORGMODE._plugins:
self.keybindings.extend(ORGMODE._plugins[plugin].keybindings)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(MappingTestCase)