Browse Source

CppLanguageServer: Add test for "get_parameters_hint"

Itamar 4 năm trước cách đây
mục cha
commit
2af5bb9083

+ 32 - 0
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_complete_type();
 static void test_find_variable_definition();
 static void test_find_variable_definition();
 static void test_complete_includes();
 static void test_complete_includes();
+static void test_parameters_hint();
 
 
 int run_tests()
 int run_tests()
 {
 {
@@ -50,6 +51,7 @@ int run_tests()
     test_complete_type();
     test_complete_type();
     test_find_variable_definition();
     test_find_variable_definition();
     test_complete_includes();
     test_complete_includes();
+    test_parameters_hint();
     return s_some_test_failed ? 1 : 0;
     return s_some_test_failed ? 1 : 0;
 }
 }
 
 
@@ -122,6 +124,7 @@ void test_find_variable_definition()
         PASS;
         PASS;
     FAIL("wrong declaration location");
     FAIL("wrong declaration location");
 }
 }
+
 void test_complete_includes()
 void test_complete_includes()
 {
 {
     I_TEST(Complete Type)
     I_TEST(Complete Type)
@@ -147,3 +150,32 @@ void test_complete_includes()
 
 
     PASS;
     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;
+}

+ 8 - 0
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(
+}