#include #include #include #include #include namespace { using namespace vls::features::document_links; using Void::Testing::expect; using Void::Testing::require; } // namespace VOID_TEST(DocumentLinks, resolves_quoted_includes_from_the_document_directory) { const std::string text = "#pragma once\n#include \"extra.hpp\"\nint x;\n"; const auto links = includes(text, "/project/main.cpp"); require(links.size() == 1); expect(links.front().path == "/project/extra.hpp"); expect(links.front().range.start == Position{1, 10}); expect(links.front().range.end == Position{1, 19}); const auto nested = includes("#include \"sub/extra.hpp\"\n", "/project/main.cpp"); require(nested.size() == 1); expect(nested.front().path == "/project/sub/extra.hpp"); } VOID_TEST(DocumentLinks, skips_angle_includes_and_system_roots) { const std::string text = "#include \n#include \"local.hpp\"\n"; const auto links = includes(text, "/project/main.cpp"); require(links.size() == 1); expect(links.front().path == "/project/local.hpp"); } VOID_TEST(DocumentLinks, keeps_absolute_spellings) { const auto links = includes("#include \"/opt/inc/a.hpp\"\n", "/project/main.cpp"); require(links.size() == 1); expect(links.front().path == "/opt/inc/a.hpp"); } VOID_TEST(DocumentLinks, skips_unterminated_and_indented_forms) { expect(includes("#include \"unterminated\n", "/project/main.cpp").empty()); const auto indented = includes(" #include \"a.hpp\"\n", "/project/main.cpp"); require(indented.size() == 1); expect(indented.front().range.start.character == 12); } VOID_TEST(DocumentLinks, counts_lines_across_the_document) { const std::string text = "int a;\n\n#include \"x.hpp\"\n"; const auto links = includes(text, "/project/main.cpp"); require(links.size() == 1); expect(links.front().range.start.line == 2); } VOID_TEST(DocumentLinks, is_bounded) { std::string text; for (int line = 0; line != 4; ++line) text += "#include \"a.hpp\"\n"; expect(includes(text, "/project/main.cpp", Limits{.links = 2}).size() == 2); expect(includes(text, "/project/main.cpp", Limits{.scanBytes = 10}).empty()); expect(includes(text, "/project/main.cpp", Limits{.pathBytes = 4}).empty()); }