1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

CppLanguageServer: Put cpp test files in /home/anon/cpp-tests/

This is similar to the LibJS test data that resides in
/home/anon/js-tests.
It's more convenient than storing the test programs as raw strings
in the code.
This commit is contained in:
Itamar 2021-05-16 18:50:45 +03:00 committed by Andreas Kling
parent 28ed518142
commit eeb98335d5
8 changed files with 47 additions and 37 deletions

View file

@ -104,10 +104,12 @@ mkdir -p mnt/home/anon
mkdir -p mnt/home/anon/Desktop
mkdir -p mnt/home/anon/Downloads
mkdir -p mnt/home/nona
rm -fr mnt/home/anon/js-tests mnt/home/anon/web-tests
rm -fr mnt/home/anon/js-tests mnt/home/anon/web-tests mnt/home/anon/cpp-tests
mkdir -p mnt/home/anon/cpp-tests/
cp "$SERENITY_SOURCE_DIR"/README.md mnt/home/anon/
cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibJS/Tests mnt/home/anon/js-tests
cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibWeb/Tests mnt/home/anon/web-tests
cp -r "$SERENITY_SOURCE_DIR"/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests mnt/home/anon/cpp-tests/comprehension
chmod 700 mnt/root
chmod 700 mnt/home/anon
chmod 700 mnt/home/nona

View file

@ -12,7 +12,7 @@ cd "$script_path/.." || exit 1
# */
GOOD_LICENSE_HEADER_PATTERN=$'^/\*\n( \* Copyright \(c\) [0-9]{4}(-[0-9]{4})?, .*\n)+ \*\n \* SPDX-License-Identifier: BSD-2-Clause\n \*/\n\n'
BAD_LICENSE_HEADER_ERRORS=()
LICENSE_HEADER_CHECK_EXCUDES=(AK/Checked.h AK/Function.h Userland/Libraries/LibC/elf.h)
LICENSE_HEADER_CHECK_EXCLUDES=(AK/Checked.h AK/Function.h Userland/Libraries/LibC/elf.h Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/*)
# We check that "#pragma once" is present
PRAGMA_ONCE_PATTERN='#pragma once'
@ -28,7 +28,7 @@ LIBM_MATH_H_INCLUDE_ERRORS=()
while IFS= read -r f; do
file_content="$(< "$f")"
if [[ ! "${LICENSE_HEADER_CHECK_EXCUDES[*]} " =~ $f ]]; then
if [[ ! "${LICENSE_HEADER_CHECK_EXCLUDES[*]} " =~ $f ]]; then
if [[ ! "$file_content" =~ $GOOD_LICENSE_HEADER_PATTERN ]]; then
BAD_LICENSE_HEADER_ERRORS+=("$f")
fi

View file

@ -12,7 +12,8 @@ if [ "$#" -eq "1" ]; then
'*.h' \
':!:Base' \
':!:Kernel/FileSystem/ext2_fs.h' \
':!:Userland/Libraries/LibC/syslog.h'
':!:Userland/Libraries/LibC/syslog.h' \
':!:Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests/*'
)
else
files=()

View file

@ -7,6 +7,8 @@
#include "Tests.h"
#include "../FileDB.h"
#include "CppComprehensionEngine.h"
#include <AK/LexicalPath.h>
#include <LibCore/File.h>
using namespace LanguageServers;
using namespace LanguageServers::Cpp;
@ -33,6 +35,8 @@ static bool s_some_test_failed = false;
return; \
} while (0)
constexpr char TESTS_ROOT_DIR[] = "/home/anon/cpp-tests/comprehension";
static void test_complete_local_args();
static void test_complete_local_vars();
static void test_complete_type();
@ -47,18 +51,20 @@ int run_tests()
return s_some_test_failed ? 1 : 0;
}
static void add_file(FileDB& filedb, const String& name)
{
auto file = Core::File::open(LexicalPath::join(TESTS_ROOT_DIR, name).string(), Core::OpenMode::ReadOnly);
VERIFY(!file.is_error());
filedb.add(name, file.value()->fd());
}
void test_complete_local_args()
{
I_TEST(Complete Local Args)
FileDB filedb;
String content = R"(
int main(int argc, char** argv){
ar
}
)";
filedb.add("a.cpp", content);
add_file(filedb, "complete_local_args.cpp");
CppComprehensionEngine engine(filedb);
auto suggestions = engine.get_suggestions("a.cpp", { 2, 2 });
auto suggestions = engine.get_suggestions("complete_local_args.cpp", { 2, 6 });
if (suggestions.size() != 2)
FAIL(bad size);
@ -72,15 +78,9 @@ void test_complete_local_vars()
{
I_TEST(Complete Local Vars)
FileDB filedb;
String content = R"(
int main(int argc, char** argv){
int myvar1 = 3;
myv
}
)";
filedb.add("a.cpp", content);
add_file(filedb, "complete_local_vars.cpp");
CppComprehensionEngine autocomplete(filedb);
auto suggestions = autocomplete.get_suggestions("a.cpp", { 3, 3 });
auto suggestions = autocomplete.get_suggestions("complete_local_vars.cpp", { 3, 7 });
if (suggestions.size() != 1)
FAIL(bad size);
@ -94,17 +94,9 @@ void test_complete_type()
{
I_TEST(Complete Type)
FileDB filedb;
String content = R"(
struct MyStruct {
int x;
};
void foo(){
MyS
}
)";
filedb.add("a.cpp", content);
add_file(filedb, "complete_type.cpp");
CppComprehensionEngine autocomplete(filedb);
auto suggestions = autocomplete.get_suggestions("a.cpp", { 5, 3 });
auto suggestions = autocomplete.get_suggestions("complete_type.cpp", { 5, 7 });
if (suggestions.size() != 1)
FAIL(bad size);
@ -118,18 +110,13 @@ void test_find_variable_definition()
{
I_TEST(Find Variable Declaration)
FileDB filedb;
String content = R"(
int main(int argc, char** argv){
argv = nullptr;
}
)";
filedb.add("a.cpp", content);
add_file(filedb, "find_variable_declaration.cpp");
CppComprehensionEngine engine(filedb);
auto position = engine.find_declaration_of("a.cpp", { 2, 1 });
auto position = engine.find_declaration_of("find_variable_declaration.cpp", { 2, 5 });
if (!position.has_value())
FAIL("declaration not found");
if (position.value().file == "a.cpp" && position.value().line == 1 && position.value().column >= 19)
if (position.value().file == "find_variable_declaration.cpp" && position.value().line == 0 && position.value().column >= 19)
PASS;
FAIL("wrong declaration location");
}

View file

@ -0,0 +1,4 @@
int main(int argc, char** argv)
{
ar
}

View file

@ -0,0 +1,5 @@
int main(int argc, char** argv)
{
int myvar1 = 3;
myv
}

View file

@ -0,0 +1,7 @@
struct MyStruct {
int x;
};
void foo()
{
MyS
}

View file

@ -0,0 +1,4 @@
int main(int argc, char** argv)
{
argv = nullptr;
}