mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 03:55:49 +00:00
Add unit test for conversion from clang-format edits to LSP ranges
This commit is contained in:
parent
903d517b0a
commit
a7215c233c
@ -2,6 +2,8 @@
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
namespace {
|
||||
|
||||
lsRange GetLsRangeForFixIt(const CXSourceRange& range) {
|
||||
@ -126,6 +128,7 @@ std::vector<lsTextEdit> ConvertClangReplacementsIntoTextEdits(
|
||||
}
|
||||
return text_edits_result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
std::string FileName(CXFile file) {
|
||||
@ -146,3 +149,52 @@ std::string ToString(CXString cx_string) {
|
||||
std::string ToString(CXCursorKind kind) {
|
||||
return ToString(clang_getCursorKindSpelling(kind));
|
||||
}
|
||||
|
||||
#if USE_CLANG_CXX
|
||||
TEST_SUITE("ClangUtils") {
|
||||
TEST_CASE("replacements") {
|
||||
const std::string sample_document =
|
||||
"int \n"
|
||||
"main() { int *i = 0; return 0; \n"
|
||||
"}";
|
||||
const std::vector<clang::tooling::Replacement> clang_replacements = {
|
||||
{"foo.cc", 3, 2, " "}, {"foo.cc", 13, 1, "\n "},
|
||||
{"foo.cc", 17, 1, ""}, {"foo.cc", 19, 0, " "},
|
||||
{"foo.cc", 25, 1, "\n "}, {"foo.cc", 35, 2, "\n"}};
|
||||
|
||||
// Expected format:
|
||||
//
|
||||
// int main() {
|
||||
// int *i = 0;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
const auto text_edits = ConvertClangReplacementsIntoTextEdits(
|
||||
sample_document, clang_replacements);
|
||||
REQUIRE(text_edits.size() == 6);
|
||||
REQUIRE(text_edits[0].range.start.line == 0);
|
||||
REQUIRE(text_edits[0].range.start.character == 3);
|
||||
REQUIRE(text_edits[0].newText == " ");
|
||||
|
||||
REQUIRE(text_edits[1].range.start.line == 1);
|
||||
REQUIRE(text_edits[1].range.start.character == 8);
|
||||
REQUIRE(text_edits[1].newText == "\n ");
|
||||
|
||||
REQUIRE(text_edits[2].range.start.line == 1);
|
||||
REQUIRE(text_edits[2].range.start.character == 12);
|
||||
REQUIRE(text_edits[2].newText == "");
|
||||
|
||||
REQUIRE(text_edits[3].range.start.line == 1);
|
||||
REQUIRE(text_edits[3].range.start.character == 14);
|
||||
REQUIRE(text_edits[3].newText == " ");
|
||||
|
||||
REQUIRE(text_edits[4].range.start.line == 1);
|
||||
REQUIRE(text_edits[4].range.start.character == 20);
|
||||
REQUIRE(text_edits[4].newText == "\n ");
|
||||
|
||||
REQUIRE(text_edits[5].range.start.line == 1);
|
||||
REQUIRE(text_edits[5].range.start.character == 30);
|
||||
REQUIRE(text_edits[5].newText == "\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user