summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-07-03 12:30:57 +0300
committerAndreas Kling <kling@serenityos.org>2021-07-04 17:50:33 +0200
commit2af5bb908347fe6b831af5091b296161dc11780c (patch)
treefb1fafcd20d2983b72f0ee910b170cdf6a6d3cfb
parentf26f764c7dfb46e9dd0e893fafc0f8b5b374877c (diff)
downloadserenity-2af5bb908347fe6b831af5091b296161dc11780c.zip
CppLanguageServer: Add test for "get_parameters_hint"
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp32
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/parameters_hint1.cpp8
2 files changed, 40 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp
index 6557a5f932..3b69ee417c 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp
@@ -42,6 +42,7 @@ static void test_complete_local_vars();
static void test_complete_type();
static void test_find_variable_definition();
static void test_complete_includes();
+static void test_parameters_hint();
int run_tests()
{
@@ -50,6 +51,7 @@ int run_tests()
test_complete_type();
test_find_variable_definition();
test_complete_includes();
+ test_parameters_hint();
return s_some_test_failed ? 1 : 0;
}
@@ -122,6 +124,7 @@ void test_find_variable_definition()
PASS;
FAIL("wrong declaration location");
}
+
void test_complete_includes()
{
I_TEST(Complete Type)
@@ -147,3 +150,32 @@ void test_complete_includes()
PASS;
}
+
+void test_parameters_hint()
+{
+ I_TEST(Function Parameters hint)
+ FileDB filedb;
+ filedb.set_project_root(TESTS_ROOT_DIR);
+ add_file(filedb, "parameters_hint1.cpp");
+ CppComprehensionEngine engine(filedb);
+
+ auto result = engine.get_function_params_hint("parameters_hint1.cpp", { 4, 9 });
+ if (!result.has_value())
+ FAIL("failed to get parameters hint (1)");
+ if (result->params != Vector<String> { "int x", "char y" } || result->current_index != 0)
+ FAIL("bad result (1)");
+
+ result = engine.get_function_params_hint("parameters_hint1.cpp", { 5, 15 });
+ if (!result.has_value())
+ FAIL("failed to get parameters hint (2)");
+ if (result->params != Vector<String> { "int x", "char y" } || result->current_index != 1)
+ FAIL("bad result (2)");
+
+ result = engine.get_function_params_hint("parameters_hint1.cpp", { 6, 8 });
+ if (!result.has_value())
+ FAIL("failed to get parameters hint (3)");
+ if (result->params != Vector<String> { "int x", "char y" } || result->current_index != 0)
+ FAIL("bad result (3)");
+
+ PASS;
+}
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/parameters_hint1.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/parameters_hint1.cpp
new file mode 100644
index 0000000000..43fc7c5e32
--- /dev/null
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/parameters_hint1.cpp
@@ -0,0 +1,8 @@
+void foo(int x, char y);
+
+void bar()
+{
+ foo();
+ foo(123, 'b');
+ foo(
+}