diff options
author | Itamar <itamar8910@gmail.com> | 2021-05-22 12:28:52 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-22 15:52:11 +0200 |
commit | 6738a966ec315a31fe146c4dde3618c6e14ec8d9 (patch) | |
tree | d5a29342588641bf9d1e3ea069b1bfb077fc945d /Userland/DevTools | |
parent | b9021f8631b84d53ac83d4b59f8c0ef8e724eeb8 (diff) | |
download | serenity-6738a966ec315a31fe146c4dde3618c6e14ec8d9.zip |
CppLanguageServer: Add test case for auto-completing include paths
Diffstat (limited to 'Userland/DevTools')
3 files changed, 35 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp index 70112f04d1..6557a5f932 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp @@ -41,6 +41,7 @@ static void test_complete_local_args(); static void test_complete_local_vars(); static void test_complete_type(); static void test_find_variable_definition(); +static void test_complete_includes(); int run_tests() { @@ -48,6 +49,7 @@ int run_tests() test_complete_local_vars(); test_complete_type(); test_find_variable_definition(); + test_complete_includes(); return s_some_test_failed ? 1 : 0; } @@ -120,3 +122,28 @@ void test_find_variable_definition() PASS; FAIL("wrong declaration location"); } +void test_complete_includes() +{ + I_TEST(Complete Type) + FileDB filedb; + filedb.set_project_root(TESTS_ROOT_DIR); + add_file(filedb, "complete_includes.cpp"); + add_file(filedb, "sample_header.h"); + CppComprehensionEngine autocomplete(filedb); + + auto suggestions = autocomplete.get_suggestions("complete_includes.cpp", { 0, 23 }); + if (suggestions.size() != 1) + FAIL(project include - bad size); + + if (suggestions[0].completion != "sample_header.h") + FAIL("project include - wrong results"); + + suggestions = autocomplete.get_suggestions("complete_includes.cpp", { 1, 19 }); + if (suggestions.size() != 1) + FAIL(global include - bad size); + + if (suggestions[0].completion != "cdefs.h") + FAIL("global include - wrong results"); + + PASS; +} diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/complete_includes.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/complete_includes.cpp new file mode 100644 index 0000000000..3eb239f29f --- /dev/null +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/complete_includes.cpp @@ -0,0 +1,5 @@ +#include "sample_heade +#include <sys/cdef + +void foo() {} + diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/sample_header.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/sample_header.h new file mode 100644 index 0000000000..ab2154484e --- /dev/null +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/sample_header.h @@ -0,0 +1,3 @@ +#pragma once + +int bar(); |