Exemplo n.º 1
0
    def test_complete(self):
        """Test autocompletion for user type

        """
        file_name = path.join(path.dirname(__file__), 'test.cpp')
        self.view = sublime.active_window().open_file(file_name)
        while self.view.is_loading():
            time.sleep(0.1)
        # now the file should be ready
        settings = Settings()
        current_folder = path.dirname(self.view.file_name())
        parent_folder = path.dirname(current_folder)
        include_dirs = settings.populate_include_dirs(
            file_current_folder=current_folder,
            file_parent_folder=parent_folder)
        completer = Completer("clang++")
        completer.init(view=self.view,
                       includes=include_dirs,
                       settings=settings)
        self.assertTrue(completer.exists_for_view(self.view.id()))
        self.assertEqual(self.getRow(5), "  a.")
        pos = self.view.text_point(5, 4)
        current_word = self.view.substr(self.view.word(pos))
        self.assertEqual(current_word, ".\n")
        completer.complete(self.view, pos, settings.errors_on_save)
        counter = 0
        while not completer.async_completions_ready:
            time.sleep(0.1)
            counter += 1
            if counter > 20:
                break
        self.assertIsNotNone(completer.completions)
        expected = ['a\tint a', 'a']
        self.assertTrue(expected in completer.completions)
Exemplo n.º 2
0
    def test_init_completer(self):
        """Test that completer is properly initialized

        """
        settings = Settings()
        current_folder = path.dirname(self.view.file_name())
        parent_folder = path.dirname(current_folder)
        include_dirs = settings.populate_include_dirs(
            file_current_folder=current_folder,
            file_parent_folder=parent_folder)
        completer = Completer("clang++")
        completer.init(view=self.view,
                       includes=include_dirs,
                       settings=settings)
        self.assertTrue(completer.exists_for_view(self.view.id()))
Exemplo n.º 3
0
    def test_complete_vector(self):
        """ Test that we can complete vector members. """
        self.setUpView('test_vector.cpp')

        completer = self.setUpCompleter()
        self.assertTrue(completer.exists_for_view(self.view.buffer_id()))

        # Check the current cursor position is completable.
        self.assertEqual(self.getRow(3), "  vec.")
        pos = self.view.text_point(3, 6)
        current_word = self.view.substr(self.view.word(pos))
        self.assertEqual(current_word, ".\n")

        # Load the completions.
        settings = Settings()
        request = CompletionRequest(self.view, pos)
        (_, completions) = completer.complete(request)

        # Verify that we got the expected completions back.
        self.assertIsNotNone(completions)
        if platform.system() == "Windows":
            # disable the windows tests for now until AppVeyor fixes things
            return
        expected = ['begin\titerator begin()', 'begin()']
        self.assertIn(expected, completions)
Exemplo n.º 4
0
    def test_complete_vector(self):
        """ Test that we can complete vector members. """
        self.setUpView('test_vector.cpp')

        completer = self.setUpCompleter()
        self.assertTrue(completer.exists_for_view(self.view.buffer_id()))

        # Check the current cursor position is completable.
        self.assertEqual(self.getRow(3), "  vec.")
        pos = self.view.text_point(3, 6)
        current_word = self.view.substr(self.view.word(pos))
        self.assertEqual(current_word, ".\n")

        # Load the completions.
        settings = Settings()
        completer.complete(self.view, pos, settings.errors_on_save)

        # Wait 2 seconds for them to load.
        counter = 0
        while not completer.async_completions_ready:
            time.sleep(0.1)
            counter += 1
            if counter > 20:
                self.fail("Completions not ready after %d tries" % counter)

        # Verify that we got the expected completions back.
        self.assertIsNotNone(completer.completions)
        if platform.system() == "Windows":
            # disable the windows tests for now until AppVeyor fixes things
            return
        expected = ['begin\titerator begin()', 'begin()']
        self.assertIn(expected, completer.completions)
Exemplo n.º 5
0
    def test_cooperation_with_default_completions(self):
        """
        Test that empty clang completions do not hide default completions.
        """
        self.setUpView("test_errors.cpp")

        completer = self.setUpCompleter()
        self.assertTrue(completer.exists_for_view(self.view.buffer_id()))

        # Undefined foo object has no completions.
        self.assertEqual(self.getRow(1), "  foo.")
        pos = self.view.text_point(1, 6)
        current_word = self.view.substr(self.view.word(pos))
        self.assertEqual(current_word, ".\n")

        # Trigger default completions popup.
        self.view.run_command('auto_complete')
        self.assertTrue(self.view.is_auto_complete_visible())

        # Load the completions.
        settings = Settings()
        completer.complete(self.view, pos, settings.errors_on_save)

        # Wait 2 seconds for them to load.
        counter = 0
        while not completer.async_completions_ready:
            time.sleep(0.1)
            counter += 1
            if counter > 20:
                self.fail("Completions not ready after %d tries" % counter)

        # Verify that we got the expected completions back.
        self.assertEqual([], completer.completions)
        # And that popup with default completions is still open.
        self.assertTrue(self.view.is_auto_complete_visible())
Exemplo n.º 6
0
    def test_complete(self):
        """ Test autocompletion for user type. """
        self.setUpView('test.cpp')

        completer = self.setUpCompleter()
        self.assertTrue(completer.exists_for_view(self.view.buffer_id()))

        # Check the current cursor position is completable.
        self.assertEqual(self.getRow(5), "  a.")
        pos = self.view.text_point(5, 4)
        current_word = self.view.substr(self.view.word(pos))
        self.assertEqual(current_word, ".\n")

        # Load the completions.
        settings = Settings()
        completer.complete(self.view, pos, settings.errors_on_save)

        # Wait 2 seconds for them to load.
        counter = 0
        while not completer.async_completions_ready:
            time.sleep(0.1)
            counter += 1
            if counter > 20:
                self.fail("Completions not ready after %d tries" % counter)

        # Verify that we got the expected completions back.
        self.assertIsNotNone(completer.completions)
        expected = ['a\tint a', 'a']
        self.assertIn(expected, completer.completions)
Exemplo n.º 7
0
    def test_populate_includes(self):
        """Testing include population
        """
        # open any existing file
        self.tearDown()
        self.setUpView('test_wrong_triggers.cpp')
        # now test the things
        settings = Settings()
        self.assertTrue(settings.is_valid())
        settings.include_file_folder = True
        settings.include_parent_folder = True
        settings.include_dirs = [
            path.realpath("/$project_name/src"),
            path.realpath("/test/test")
        ]
        initial_dirs = list(settings.include_dirs)
        dirs = settings.populate_include_dirs(self.view)

        current_folder = path.dirname(self.view.file_name())
        parent_folder = path.dirname(current_folder)
        self.assertLess(len(initial_dirs), len(dirs))
        self.assertNotEqual(dirs[0], initial_dirs[0])
        self.assertEqual(dirs[1], initial_dirs[1])
        self.assertEqual(dirs[2], current_folder)
        self.assertEqual(dirs[3], parent_folder)
Exemplo n.º 8
0
    def test_populate_flags(self):
        """Testing include population
        """
        # open any existing file
        self.tearDown()
        self.setUpView('test_wrong_triggers.cpp')
        # now test the things
        settings = Settings()
        self.assertTrue(settings.is_valid())
        settings.include_file_folder = True
        settings.include_file_parent_folder = True
        settings.common_flags = [
            "-I" + path.realpath("/$project_name/src"),
            "-I" + path.realpath("/test/test")
        ]
        initial_flags = list(settings.common_flags)
        dirs = settings.populate_common_flags(self.view)

        current_folder = path.dirname(self.view.file_name())
        parent_folder = path.dirname(current_folder)
        self.assertLess(len(initial_flags), len(dirs))
        self.assertFalse(initial_flags[0] in dirs)
        self.assertTrue(initial_flags[1] in dirs)
        self.assertTrue(("-I" + current_folder) in dirs)
        self.assertTrue(("-I" + parent_folder) in dirs)
Exemplo n.º 9
0
    def test_unsaved_views(self):
        """ Test that we gracefully handle unsaved views. """
        # Construct an unsaved scratch view.
        self.view = sublime.active_window().new_file()
        self.view.set_scratch(True)

        # Manually set up a completer.
        settings = Settings()
        clang_binary = settings.clang_binary
        completer = self.Completer(clang_binary)
        completer.init_for_view(view=self.view, settings=settings)

        # Verify that the completer ignores the scratch view.
        self.assertFalse(completer.exists_for_view(self.view.buffer_id()))
Exemplo n.º 10
0
    def setUpCompleter(self):
        """
        Utility method to set up a completer for the current view.

        Returns:
            BaseCompleter: completer for the current view.
        """

        settings = Settings()
        current_folder = path.dirname(self.view.file_name())
        parent_folder = path.dirname(current_folder)
        include_dirs = settings.populate_include_dirs(
            file_current_folder=current_folder,
            file_parent_folder=parent_folder)

        clang_binary = settings.clang_binary
        completer = self.Completer(clang_binary)
        completer.init(
            view=self.view,
            includes=include_dirs,
            settings=settings)

        return completer
Exemplo n.º 11
0
    def setUpCompleter(self):
        """
        Utility method to set up a completer for the current view.

        Returns:
            BaseCompleter: completer for the current view.
        """

        settings = Settings()
        current_folder = path.dirname(self.view.file_name())
        parent_folder = path.dirname(current_folder)
        include_dirs = settings.populate_include_dirs(
            file_current_folder=current_folder,
            file_parent_folder=parent_folder)

        clang_binary = settings.clang_binary
        completer = self.Completer(clang_binary)
        completer.init(
            view=self.view,
            includes=include_dirs,
            settings=settings)

        return completer
Exemplo n.º 12
0
    def setUpCompleter(self):
        """
        Utility method to set up a completer for the current view.

        Returns:
            BaseCompleter: completer for the current view.
        """

        settings = Settings()

        clang_binary = settings.clang_binary
        completer = self.Completer(clang_binary)
        completer.init_for_view(view=self.view, settings=settings)

        return completer
Exemplo n.º 13
0
    def test_init(self):
        """Test that settings are correctly initialized

        """
        settings = Settings()
        self.assertIsNotNone(settings.subl_settings)
        # test other settings
        self.assertIsNotNone(settings.verbose)
        self.assertIsNotNone(settings.include_file_folder)
        self.assertIsNotNone(settings.include_file_parent_folder)
        self.assertIsNotNone(settings.triggers)
        self.assertIsNotNone(settings.common_flags)
        self.assertIsNotNone(settings.clang_binary)
        self.assertIsNotNone(settings.search_clang_complete_file)
        self.assertIsNotNone(settings.errors_on_save)
Exemplo n.º 14
0
    def test_no_completions_with_error_markers(self):
        """ Test that empty completions still produce error marks. """
        self.setUpView("test_errors.cpp")

        completer = self.setUpCompleter()
        self.assertTrue(completer.exists_for_view(self.view.buffer_id()))

        # Undefined foo object has no completions.
        self.assertEqual(self.getRow(1), "  foo.")
        pos = self.view.text_point(1, 6)
        current_word = self.view.substr(self.view.word(pos))
        self.assertEqual(current_word, ".\n")

        # Load the completions.
        settings = Settings()
        completer.complete(self.view, pos, settings.errors_on_save)

        # Wait 2 seconds for them to load.
        counter = 0
        while not completer.async_completions_ready:
            time.sleep(0.1)
            counter += 1
            if counter > 20:
                self.fail("Completions not ready after %d tries" % counter)

        # Verify that we got the expected completions back.
        self.assertEqual([], completer.completions)

        # Verify that error regions were added.
        error_vis = completer.error_vis
        self.assertIsNotNone(error_vis)
        regions_dict = error_vis.err_regions[self.view.buffer_id()]
        self.assertIsNotNone(regions_dict)
        # Verify the number of rows with error regions.
        self.assertTrue(len(regions_dict.keys()) > 0)
        # Verify the region row.
        expected_row = 2
        self.assertIn(expected_row, regions_dict)
        # Verify that correct amount of regions were created.
        expected_regions_count = 1
        self.assertEqual(expected_regions_count,
                         len(regions_dict[expected_row]))
        # Verify the column, row and region extent.
        error_region = regions_dict[expected_row][0]
        self.assertEqual('3', error_region['col'])
        self.assertEqual('2', error_region['row'])
        self.assertEqual(43, error_region['region'].a)
        self.assertEqual(46, error_region['region'].b)
Exemplo n.º 15
0
 def test_populate_includes(self):
     """Testing include population
     """
     settings = Settings()
     self.assertTrue(settings.is_valid())
     settings.include_file_folder = True
     settings.include_parent_folder = True
     settings.include_dirs = [
         path.realpath("/$project_name/src"),
         path.realpath("/test/test")
     ]
     initial_dirs = list(settings.include_dirs)
     dirs = settings.populate_include_dirs(path.realpath(__file__),
                                           path.abspath(path.curdir))
     self.assertLess(len(initial_dirs), len(dirs))
     self.assertNotEqual(dirs[0], initial_dirs[0])
     self.assertEqual(dirs[1], initial_dirs[1])
     self.assertEqual(dirs[2], path.realpath(__file__))
     self.assertEqual(dirs[3], path.abspath(path.dirname(path.curdir)))
Exemplo n.º 16
0
    def test_complete(self):
        """ Test autocompletion for user type. """
        self.setUpView('test.cpp')

        completer = self.setUpCompleter()
        self.assertTrue(completer.exists_for_view(self.view.buffer_id()))

        # Check the current cursor position is completable.
        self.assertEqual(self.getRow(5), "  a.")
        pos = self.view.text_point(5, 4)
        current_word = self.view.substr(self.view.word(pos))
        self.assertEqual(current_word, ".\n")

        # Load the completions.
        settings = Settings()
        request = CompletionRequest(self.view, pos)
        (_, completions) = completer.complete(request)

        # Verify that we got the expected completions back.
        self.assertIsNotNone(completions)
        expected = ['a\tint a', 'a']
        self.assertIn(expected, completions)
Exemplo n.º 17
0
    def test_valid(self):
        """Test validity

        """
        settings = Settings()
        self.assertTrue(settings.is_valid())