diff --git a/rplugin/python3/__init__.py b/rplugin/python3/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rplugin/python3/neotags.py b/rplugin/python3/neotags.py index b2b7f5e..73b6dcf 100644 --- a/rplugin/python3/neotags.py +++ b/rplugin/python3/neotags.py @@ -12,6 +12,7 @@ class NeotagsPlugin(object): def __init__(self, nvim): self.nvim = nvim # Perhaps debugging settings? + # Like autotags, configure regex compared to filename to ignore, e.g. fugitive buffers, git commits, etc. self.options = { 'tags_filename': 'tags', 'ctags_cmd': 'ctags', diff --git a/rplugin/test/__init__.py b/rplugin/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rplugin/test/test_neotags.py b/rplugin/test/test_neotags.py new file mode 100644 index 0000000..9c3c78d --- /dev/null +++ b/rplugin/test/test_neotags.py @@ -0,0 +1,61 @@ +import unittest +from unittest.mock import Mock +from unittest.mock import MagicMock +import neovim + +from python3.neotags import NeotagsPlugin + + +class TestNeotagsPlugin(unittest.TestCase): + + def setUp(self): + self.plugin = NeotagsPlugin(Mock(neovim.api.nvim)) + + def test_default_options(self): + self.assertEqual('ctags', self.plugin.options['ctags_cmd']) + self.assertEqual('tags', self.plugin.options['tags_filename']) + self.assertEqual(False, self.plugin.options['logging']) + + def test_default_options(self): + self.plugin.nvim.configure_mock(vars={}) + self.plugin.nvim.vars['neotags_tags_filename'] = 'new_tags' + self.plugin.nvim.vars['neotags_ctags_cmd'] = 'new_ctags' + self.plugin.nvim.vars['neotags_logging'] = True + + self.plugin.update_settings() + + self.assertEqual('new_tags', self.plugin.options['tags_filename']) + self.assertEqual('new_ctags', self.plugin.options['ctags_cmd']) + self.assertEqual(True, self.plugin.options['logging']) + + def test_debug_logs_to_nvim_when_logging_is_active(self): + self.plugin.options['logging'] = True + self.plugin.nvim.out_write = MagicMock() + + self.plugin.debug('some message') + self.plugin.nvim.out_write.assert_called_once_with( + "neotags > some message\n" + ) + + def test_debug_does_not_log_to_nvim_when_logging_is_inactive(self): + self.plugin.options['logging'] = False + self.plugin.nvim.out_write = MagicMock() + + self.plugin.debug('some message') + self.plugin.nvim.out_write.assert_not_called() + + def test_error_logs_to_nvim_when_logging_is_active(self): + self.plugin.options['logging'] = True + self.plugin.nvim.err_write = MagicMock() + + self.plugin.error('some message') + self.plugin.nvim.err_write.assert_called_once_with( + "neotags > some message\n" + ) + + def test_error_does_not_log_to_nvim_when_logging_is_inactive(self): + self.plugin.options['logging'] = False + self.plugin.nvim.err_write = MagicMock() + + self.plugin.error('some message') + self.plugin.nvim.err_write.assert_not_called()