|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | + |
| 4 | +import sys |
| 5 | +sys.path.append(u'../ftplugin') |
| 6 | + |
| 7 | +import unittest |
| 8 | +import orgmode.settings |
| 9 | +from orgmode.exceptions import PluginError |
| 10 | +from orgmode._vim import ORGMODE |
| 11 | +from orgmode.keybinding import MODE_ALL, Plug |
| 12 | + |
| 13 | +import vim |
| 14 | + |
| 15 | +ORG_PLUGINS = ['ShowHide', '|', 'Navigator', 'EditStructure', '|', 'Hyperlinks', '|', 'Todo', 'TagsProperties', 'Date', 'Agenda', 'Misc', '|', 'Export'] |
| 16 | + |
| 17 | + |
| 18 | +class MappingTestCase(unittest.TestCase): |
| 19 | + u"""Tests all plugins for overlapping mappings.""" |
| 20 | + def test_non_overlapping_plug_mappings(self): |
| 21 | + def find_overlapping_mappings(kb, all_keybindings): |
| 22 | + for tkb in all_keybindings: |
| 23 | + if kb.mode == tkb.mode or MODE_ALL in (kb.mode, tkb.mode): |
| 24 | + if isinstance(kb._action, Plug) and isinstance(tkb._action, Plug): |
| 25 | + akb = kb.action |
| 26 | + atkb = tkb.action |
| 27 | + if (akb.startswith(atkb) or atkb.startswith(akb)) and akb != atkb: |
| 28 | + print u'ERROR: Found overlapping mapping: %s (%s), %s (%s)' % (kb.key, akb, tkb.key, atkb) |
| 29 | + return True |
| 30 | + |
| 31 | + if all_keybindings: |
| 32 | + return find_overlapping_mappings(all_keybindings[0], all_keybindings[1:]) |
| 33 | + return False |
| 34 | + |
| 35 | + if self.keybindings: |
| 36 | + self.assertFalse(find_overlapping_mappings(self.keybindings[0], self.keybindings[1:])) |
| 37 | + |
| 38 | + def setUp(self): |
| 39 | + self.keybindings = [] |
| 40 | + |
| 41 | + vim.EVALRESULTS = { |
| 42 | + u'exists("g:org_debug")': 0, |
| 43 | + u'exists("b:org_debug")': 0, |
| 44 | + u'exists("*repeat#set()")': 0, |
| 45 | + u'b:changedtick': 0, |
| 46 | + u'exists("b:org_plugins")'.encode(u'utf-8'): 0, |
| 47 | + u'exists("g:org_plugins")'.encode(u'utf-8'): 1, |
| 48 | + u'g:org_plugins'.encode(u'utf-8'): ORG_PLUGINS, |
| 49 | + } |
| 50 | + for plugin in filter(lambda p: p != '|', ORG_PLUGINS): |
| 51 | + try: |
| 52 | + ORGMODE.register_plugin(plugin) |
| 53 | + except PluginError: |
| 54 | + pass |
| 55 | + if plugin in ORGMODE._plugins: |
| 56 | + self.keybindings.extend(ORGMODE._plugins[plugin].keybindings) |
| 57 | + |
| 58 | + |
| 59 | +def suite(): |
| 60 | + return unittest.TestLoader().loadTestsFromTestCase(MappingTestCase) |
| 61 | + |
| 62 | +# vi: noexpandtab |
0 commit comments