mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
LibCpp: Support for parsing c-style fixed arrays (arr[2])
Also adds tests for finding declaration of arrays inside CppComprehension which requires proper parsing for passing. Side-effect of this patch: if we ctrl+click on array variables, it should jump to the correct declaration inside HackStudio.
This commit is contained in:
parent
34b04271f4
commit
ac435f914c
7 changed files with 184 additions and 8 deletions
|
@ -33,6 +33,12 @@ static bool s_some_test_failed = false;
|
|||
return; \
|
||||
} while (0)
|
||||
|
||||
#define RUN(function) \
|
||||
function; \
|
||||
if (s_some_test_failed) { \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
constexpr auto TESTS_ROOT_DIR = "/home/anon/Tests/cpp-tests/comprehension"sv;
|
||||
|
||||
class FileDB : public CodeComprehension::FileDB {
|
||||
|
@ -61,18 +67,24 @@ 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_find_array_variable_declaration_single();
|
||||
static void test_find_array_variable_declaration_single_empty();
|
||||
static void test_find_array_variable_declaration_double();
|
||||
static void test_complete_includes();
|
||||
static void test_parameters_hint();
|
||||
|
||||
int run_tests()
|
||||
{
|
||||
test_complete_local_args();
|
||||
test_complete_local_vars();
|
||||
test_complete_type();
|
||||
test_find_variable_definition();
|
||||
test_complete_includes();
|
||||
test_parameters_hint();
|
||||
return s_some_test_failed ? 1 : 0;
|
||||
RUN(test_complete_local_args());
|
||||
RUN(test_complete_local_vars());
|
||||
RUN(test_complete_type());
|
||||
RUN(test_find_variable_definition());
|
||||
RUN(test_find_array_variable_declaration_single());
|
||||
RUN(test_find_array_variable_declaration_single_empty());
|
||||
RUN(test_find_array_variable_declaration_double());
|
||||
RUN(test_complete_includes());
|
||||
RUN(test_parameters_hint());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void add_file(FileDB& filedb, DeprecatedString const& name)
|
||||
|
@ -145,6 +157,60 @@ void test_find_variable_definition()
|
|||
FAIL("wrong declaration location");
|
||||
}
|
||||
|
||||
void test_find_array_variable_declaration_single()
|
||||
{
|
||||
I_TEST(Find 1D Array as a Variable Declaration)
|
||||
FileDB filedb;
|
||||
auto filename = "find_array_variable_declaration.cpp";
|
||||
add_file(filedb, filename);
|
||||
CodeComprehension::Cpp::CppComprehensionEngine engine(filedb);
|
||||
auto position = engine.find_declaration_of(filename, { 3, 6 });
|
||||
if (!position.has_value())
|
||||
FAIL("declaration not found");
|
||||
|
||||
if (position.value().file == filename && position.value().line == 2 && position.value().column >= 4)
|
||||
PASS;
|
||||
|
||||
printf("Found at position %zu %zu\n", position.value().line, position.value().column);
|
||||
FAIL("wrong declaration location");
|
||||
}
|
||||
|
||||
void test_find_array_variable_declaration_single_empty()
|
||||
{
|
||||
I_TEST(Find 1D Empty size Array as a Variable Declaration)
|
||||
FileDB filedb;
|
||||
auto filename = "find_array_variable_declaration.cpp";
|
||||
add_file(filedb, filename);
|
||||
CodeComprehension::Cpp::CppComprehensionEngine engine(filedb);
|
||||
auto position = engine.find_declaration_of(filename, { 6, 6 });
|
||||
if (!position.has_value())
|
||||
FAIL("declaration not found");
|
||||
|
||||
if (position.value().file == filename && position.value().line == 5 && position.value().column >= 4)
|
||||
PASS;
|
||||
|
||||
printf("Found at position %zu %zu\n", position.value().line, position.value().column);
|
||||
FAIL("wrong declaration location");
|
||||
}
|
||||
|
||||
void test_find_array_variable_declaration_double()
|
||||
{
|
||||
I_TEST(Find 2D Array as a Variable Declaration)
|
||||
FileDB filedb;
|
||||
auto filename = "find_array_variable_declaration.cpp";
|
||||
add_file(filedb, filename);
|
||||
CodeComprehension::Cpp::CppComprehensionEngine engine(filedb);
|
||||
auto position = engine.find_declaration_of(filename, { 9, 6 });
|
||||
if (!position.has_value())
|
||||
FAIL("declaration not found");
|
||||
|
||||
if (position.value().file == filename && position.value().line == 8 && position.value().column >= 4)
|
||||
PASS;
|
||||
|
||||
printf("Found at position %zu %zu\n", position.value().line, position.value().column);
|
||||
FAIL("wrong declaration location");
|
||||
}
|
||||
|
||||
void test_complete_includes()
|
||||
{
|
||||
I_TEST(Complete include statements)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue