Skip to content

Commit 9d60a2f

Browse files
committed
- add test cases for overlapping mappings
1 parent 703f9e8 commit 9d60a2f

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ docs: documentation
6262
# generate a test coverage report for all python files
6363
coverage:
6464
@echo ">>> Coverage depends on the package python-nose and python-coverage, make sure they are installed!"
65-
cd tests && nosetests --with-coverage --cover-html .
65+
cd tests && nosetests2 --with-coverage --cover-html .
6666

6767
# run a static code checker
6868
lint:

doc/orgguide.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,7 @@ LINKS *orgguide-links*
13581358
CHANGELOG *orgguide-changelog*
13591359

13601360
0.5.0-0
1361+
- add test cases for overlapping mappings
13611362
- add three dots after folded text, like in orgmode
13621363
- improve highlighting of org-mode properties (closes issue #130)
13631364
- implement global visibility as it works in Emacs org-mode (closes issue #119)

tests/run_tests.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import test_plugin_show_hide
1818
import test_plugin_tags_properties
1919
import test_plugin_todo
20+
import test_plugin_mappings
2021

2122
import unittest
2223

@@ -42,6 +43,7 @@
4243
tests.addTests(test_plugin_show_hide.suite())
4344
tests.addTests(test_plugin_tags_properties.suite())
4445
tests.addTests(test_plugin_todo.suite())
46+
tests.addTests(test_plugin_mappings.suite())
4547

4648
runner = unittest.TextTestRunner()
4749
runner.run(tests)

tests/test_plugin_mappings.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)