diff --git a/rplugin/test/templates/example.py b/rplugin/test/templates/example.py new file mode 100644 index 0000000..f271883 --- /dev/null +++ b/rplugin/test/templates/example.py @@ -0,0 +1,7 @@ +class SomeClass(object): + + def __init__(self): + pass + + def method(self): + pass diff --git a/rplugin/test/templates/expected_tags b/rplugin/test/templates/expected_tags new file mode 100644 index 0000000..d086ef2 --- /dev/null +++ b/rplugin/test/templates/expected_tags @@ -0,0 +1,6 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_PROGRAM_AUTHOR Universal Ctags Team // +!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/ +!_TAG_PROGRAM_URL https://ctags.io/ /official site/ +!_TAG_PROGRAM_VERSION 0.0.0 /4f741b9/ diff --git a/rplugin/test/test_neotags.py b/rplugin/test/test_neotags.py index 9c3c78d..486aa89 100644 --- a/rplugin/test/test_neotags.py +++ b/rplugin/test/test_neotags.py @@ -1,14 +1,20 @@ -import unittest from unittest.mock import Mock from unittest.mock import MagicMock +from pyfakefs import fake_filesystem_unittest import neovim +import os from python3.neotags import NeotagsPlugin -class TestNeotagsPlugin(unittest.TestCase): +class TestNeotagsPlugin(fake_filesystem_unittest.TestCase): def setUp(self): + self.templates_dirname = os.path.join( + os.path.dirname(__file__), + 'templates' + ) + self.setUpPyfakefs() self.plugin = NeotagsPlugin(Mock(neovim.api.nvim)) def test_default_options(self): @@ -59,3 +65,62 @@ class TestNeotagsPlugin(unittest.TestCase): self.plugin.error('some message') self.plugin.nvim.err_write.assert_not_called() + + def test_get_tags_file_in_same_folder(self): + filename = '/var/data/some_file.py' + expected_tags_filename = '/var/data/tags' + + self.fs.CreateFile(filename) + self.fs.CreateFile(expected_tags_filename) + + self.assertEqual( + expected_tags_filename, + self.plugin.get_tags_file(filename) + ) + + def test_get_tags_file_in_parent_folder(self): + filename = '/var/data/some_file.py' + expected_tags_filename = '/var/tags' + + self.fs.CreateFile(filename) + self.fs.CreateFile(expected_tags_filename) + + self.assertEqual( + expected_tags_filename, + self.plugin.get_tags_file(filename) + ) + + def test_get_tags_file_in_root_folder(self): + filename = '/var/data/some_file.py' + expected_tags_filename = '/tags' + + self.fs.CreateFile(filename) + self.fs.CreateFile(expected_tags_filename) + + self.assertEqual( + expected_tags_filename, + self.plugin.get_tags_file(filename) + ) + + def test_strips_existing_tags(self): + filename = '/var/data/example.py' + tags_file = '/var/data/tags' + expected_tags_file = os.path.join( + self.templates_dirname, + 'expected_tags' + ) + + self.copyRealFile( + os.path.join(self.templates_dirname, 'example.py'), + os.path.join(os.path.dirname(filename), os.path.basename(filename)) + ) + self.copyRealFile( + os.path.join(self.templates_dirname, 'tags'), + os.path.join( + os.path.dirname(tags_file), os.path.basename(tags_file) + ) + ) + + self.plugin.strip_existing_tags(tags_file, os.path.basename(filename)) + with open(tags_file) as f, open(expected_tags_file) as e: + self.assertEqual(e.read(), f.read())