Exemplo n.º 1
0
def ClangdCompleter_ShouldEnableClangdCompleter_UseClangd_test():
    user_options = DefaultOptions()
    user_options['use_clangd'] = 'Always'

    # Clangd turned on, assumes the clangd binary was found with a supported
    # version.
    with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
               return_value=['clangd', 'arg1', 'arg2']) as find_clangd_binary:
        eq_(clangd_completer.ShouldEnableClangdCompleter(user_options), True)

    # Clangd turned on but no supported binary.
    with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
               return_value=None) as find_clangd_binary:
        eq_(clangd_completer.ShouldEnableClangdCompleter(user_options), False)
        find_clangd_binary.assert_called()
Exemplo n.º 2
0
def ClangdCompleter_ShouldEnableClangdCompleter_test():
    user_options = DefaultOptions()

    # Clangd not in third_party (or an old version).
    with patch('ycmd.completers.cpp.clangd_completer.GetThirdPartyClangd',
               return_value=None):
        # Default.
        clangd_completer.CLANGD_COMMAND = clangd_completer.NOT_CACHED
        assert_that(clangd_completer.ShouldEnableClangdCompleter(user_options),
                    equal_to(False))

        # Found supported binary.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=['clangd']):
            assert_that(
                clangd_completer.ShouldEnableClangdCompleter(user_options),
                equal_to(True))
        # No supported binary found.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=None):
            assert_that(
                clangd_completer.ShouldEnableClangdCompleter(user_options),
                equal_to(False))

        # Clangd is disabled.
        user_options['use_clangd'] = 0
        assert_that(clangd_completer.ShouldEnableClangdCompleter(user_options),
                    equal_to(False))

    user_options = DefaultOptions()

    # Clangd in third_party with a supported version.
    with patch('ycmd.completers.cpp.clangd_completer.GetThirdPartyClangd',
               return_value='third_party_clangd'):
        # Default.
        clangd_completer.CLANGD_COMMAND = clangd_completer.NOT_CACHED
        assert_that(clangd_completer.ShouldEnableClangdCompleter(user_options),
                    equal_to(True))

        # Enabled.
        user_options['use_clangd'] = 1
        # Found supported binary.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=['clangd']):
            assert_that(
                clangd_completer.ShouldEnableClangdCompleter(user_options),
                equal_to(True))
        # No supported binary found.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=None):
            assert_that(
                clangd_completer.ShouldEnableClangdCompleter(user_options),
                equal_to(False))

        # Disabled.
        user_options['use_clangd'] = 0
        assert_that(clangd_completer.ShouldEnableClangdCompleter(user_options),
                    equal_to(False))
Exemplo n.º 3
0
def ClangdCompleter_ShouldEnableClangdCompleter_NoUseClangd_test():
    user_options = DefaultOptions()

    # Clangd not in third_party (or an old version).
    with patch('ycmd.completers.cpp.clangd_completer.Get3rdPartyClangd',
               return_value=None):
        # Default.
        eq_(clangd_completer.ShouldEnableClangdCompleter(user_options), False)

        # Enabled.
        user_options['use_clangd'] = 'Always'
        # Found supported binary.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=True):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                True)
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=None):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                False)

    # Clangd in third_party with a supported version.
    with patch('ycmd.completers.cpp.clangd_completer.Get3rdPartyClangd',
               return_value=True):
        # Disabled.
        user_options['use_clangd'] = 'Never'
        eq_(clangd_completer.ShouldEnableClangdCompleter(user_options), False)

        # Auto.
        user_options['use_clangd'] = 'Auto'
        # Found supported binary.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=True):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                True)
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=None):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                False)
Exemplo n.º 4
0
def ClangdCompleter_ShouldEnableClangdCompleter_test():
    user_options = DefaultOptions()

    # Clangd not in third_party (or an old version).
    with patch('ycmd.completers.cpp.clangd_completer.GetThirdPartyClangd',
               return_value=None):
        # Default.
        eq_(clangd_completer.ShouldEnableClangdCompleter(user_options), False)

        # Only Clangd in the third-party folder is allowed.
        user_options['use_clangd'] = 'Auto'
        # Found supported binary.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=['clangd']):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                False)
        # No supported binary found.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=None):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                False)

        # Clangd is always enabled.
        user_options['use_clangd'] = 'Always'
        # Found supported binary.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=['clangd']):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                True)
        # No supported binary found.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=None):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                False)

        # Clangd is always disabled.
        user_options['use_clangd'] = 'Never'
        eq_(clangd_completer.ShouldEnableClangdCompleter(user_options), False)

    user_options = DefaultOptions()

    # Clangd in third_party with a supported version.
    with patch('ycmd.completers.cpp.clangd_completer.GetThirdPartyClangd',
               return_value='third_party_clangd'):
        # Default.
        eq_(clangd_completer.ShouldEnableClangdCompleter(user_options), True)

        # Enabled.
        user_options['use_clangd'] = 'Always'
        # Found supported binary.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=True):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                True)
        # No supported binary found.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=None):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                False)

        # Only Clangd in the third-party folder is allowed.
        user_options['use_clangd'] = 'Auto'
        # Found supported binary.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=['clangd']):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                True)
        # No supported binary found.
        with patch('ycmd.completers.cpp.clangd_completer.GetClangdCommand',
                   return_value=None):
            eq_(clangd_completer.ShouldEnableClangdCompleter(user_options),
                False)

        # Disabled.
        user_options['use_clangd'] = 'Never'
        eq_(clangd_completer.ShouldEnableClangdCompleter(user_options), False)