Native VBS and CMake builds of the server and every registered suite: protocol and document sync, VBS/compdb providers, stock GCC diagnostics (including in-process default profile preparation), the stock occurrence observer and hover/definition, the bounded Scheduler, C++ module graph, scan and artifact cache with real CMI production, the context-aware symbol index with schema-2 snapshot migration, navigation and guarded rename, reflection provenance with splice-origin extraction, index-backed completion and signature help, live GCC worker control with a registered DAP suite, and the Neovim and VS Code clients. VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced from the versioned patches and verified stepping reflection/template code with projected values 17/34 and 41/82.
140 lines
6.4 KiB
C++
140 lines
6.4 KiB
C++
#include <Void/LanguageServer/Documents/DocumentStore.hpp>
|
|
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <utility>
|
|
|
|
namespace {
|
|
|
|
using namespace Void::LanguageServer::Documents;
|
|
using Void::Testing::expect;
|
|
using Void::Testing::expect_eq;
|
|
using Void::Testing::require;
|
|
|
|
constexpr auto utf8 = PositionEncoding::utf8;
|
|
constexpr auto utf16 = PositionEncoding::utf16;
|
|
constexpr std::uint32_t line_bytes = 64 * 1024;
|
|
constexpr std::uint32_t pivot = line_bytes / 2 - 1;
|
|
constexpr std::string_view uri = "untitled:long-line.cpp";
|
|
constexpr auto astral = "\U0001F600";
|
|
|
|
} // namespace
|
|
|
|
VOID_TEST(LongLines, ascii_endpoints_clamp_and_text_size_stays_checked) {
|
|
const auto text = std::string(line_bytes, 'a') + "\r\nz";
|
|
const auto shorter = std::string_view{text}.substr(0, text.size() - 1);
|
|
const LineIndex index{text};
|
|
for (const auto encoding : {utf8, utf16}) {
|
|
expect(index.range_to_offsets(text, {{0, 2}, {0, 3}}, encoding) ==
|
|
std::pair<std::size_t, std::size_t>{2, 3});
|
|
expect(
|
|
index.range_to_offsets(text, {{0, line_bytes - 3}, {0, kMaxPositionValue}}, encoding) ==
|
|
std::pair<std::size_t, std::size_t>{line_bytes - 3, line_bytes});
|
|
expect(index.range_to_offsets(text, {{0, line_bytes + 1}, {1, 0}}, encoding) ==
|
|
std::pair<std::size_t, std::size_t>{line_bytes, line_bytes + 2});
|
|
expect(index.offset_to_position(text, line_bytes, encoding) == Position{0, line_bytes});
|
|
expect(!index.offset_to_position(text, line_bytes + 1, encoding));
|
|
expect(!index.offset_to_position(text, text.size() + 1, encoding));
|
|
expect(!index.position_to_offset(text, {kMaxPositionValue + 1, 0}, encoding));
|
|
expect(!index.position_to_offset(text, {0, kMaxPositionValue + 1}, encoding));
|
|
expect(
|
|
!index.range_to_offsets(text, {{0, line_bytes}, {0, kMaxPositionValue + 1}}, encoding));
|
|
expect(!index.range_to_offsets(text, {{0, line_bytes}, {0, 2}}, encoding));
|
|
expect(!index.position_to_offset(shorter, {0, 2}, encoding));
|
|
expect(!index.offset_to_position(shorter, 2, encoding));
|
|
expect(!index.range_to_offsets(shorter, {{0, 2}, {0, 3}}, encoding));
|
|
}
|
|
}
|
|
|
|
VOID_TEST(LongLines, mixed_ascii_and_unicode_ranges_check_both_endpoints) {
|
|
auto text = std::string(pivot, 'a') + "\u03B2" + astral;
|
|
text.append(line_bytes - pivot, 'b');
|
|
const LineIndex index{text};
|
|
for (const auto encoding : {utf8, utf16}) {
|
|
const auto astral_start = pivot + (encoding == utf8 ? 2 : 1);
|
|
const auto end = line_bytes + (encoding == utf8 ? 6 : 3);
|
|
expect(index.range_to_offsets(text, {{0, astral_start}, {0, end}}, encoding) ==
|
|
std::pair<std::size_t, std::size_t>{pivot + 2, text.size()});
|
|
expect(index.position_to_offset(text, {0, kMaxPositionValue}, encoding) == text.size());
|
|
expect(index.offset_to_position(text, text.size(), encoding) == Position{0, end});
|
|
|
|
const auto split = astral_start + 1;
|
|
expect(!index.range_to_offsets(text, {{0, pivot}, {0, split}}, encoding));
|
|
expect(!index.range_to_offsets(text, {{0, split}, {0, end}}, encoding));
|
|
expect(!index.offset_to_position(text, pivot + 3, encoding));
|
|
}
|
|
}
|
|
|
|
VOID_TEST(LongLines, invalid_utf8_after_an_ascii_run_is_still_rejected) {
|
|
for (const std::string_view suffix : {"\x80", "\xF0\x9F"}) {
|
|
const auto text = std::string(pivot, 'a') + std::string{suffix};
|
|
const LineIndex index{text};
|
|
for (const auto encoding : {utf8, utf16}) {
|
|
expect(index.position_to_offset(text, {0, pivot}, encoding) == pivot);
|
|
const auto range =
|
|
index.range_to_offsets(text, {{0, pivot - 1}, {0, kMaxPositionValue}}, encoding);
|
|
require(!range.has_value());
|
|
expect_eq(range.error(), std::string{"invalid UTF-8 encountered on line"});
|
|
expect(!index.offset_to_position(text, text.size(), encoding));
|
|
}
|
|
}
|
|
}
|
|
|
|
VOID_TEST(LongLines, edits_insert_remove_and_rebuild_unicode_positions) {
|
|
const std::string ascii(line_bytes, 'a');
|
|
for (const auto encoding : {utf8, utf16}) {
|
|
DocumentStore store{encoding};
|
|
const auto original = store.open(uri, "cpp", 1, ascii);
|
|
require(original.has_value());
|
|
|
|
const auto scalar_units = encoding == utf8 ? 4U : 2U;
|
|
const auto after_scalar = pivot + scalar_units;
|
|
const std::array adding{
|
|
TextEdit{Range{{0, pivot}, {0, pivot + 1}}, astral},
|
|
TextEdit{Range{{0, after_scalar}, {0, after_scalar + 1}}, "x"},
|
|
};
|
|
const auto mixed = store.apply_changes(uri, 2, adding);
|
|
require(mixed.has_value());
|
|
auto expected_mixed = ascii;
|
|
expected_mixed.replace(pivot, 2, std::string{astral} + "x");
|
|
expect_eq((*mixed)->text, expected_mixed);
|
|
expect((*mixed)->position_to_offset({0, after_scalar + 1}) == pivot + 5);
|
|
|
|
const std::array removing{
|
|
TextEdit{Range{{0, pivot}, {0, after_scalar}}, "a"},
|
|
TextEdit{Range{{0, pivot + 1}, {0, pivot + 2}}, "a"},
|
|
};
|
|
const auto restored = store.apply_changes(uri, 3, removing);
|
|
require(restored.has_value());
|
|
expect_eq((*restored)->text, ascii);
|
|
expect((*restored)->position_to_offset({0, kMaxPositionValue}) == line_bytes);
|
|
|
|
const std::array rebuilding{
|
|
TextEdit{std::nullopt, ascii + "\r" + astral + "a"},
|
|
TextEdit{Range{{1, 0}, {1, 0}}, "\n"},
|
|
TextEdit{Range{{1, scalar_units}, {1, scalar_units + 1}}, "!"},
|
|
};
|
|
const auto rebuilt = store.apply_changes(uri, 4, rebuilding);
|
|
require(rebuilt.has_value());
|
|
expect_eq((*rebuilt)->text, ascii + "\r\n" + astral + "!");
|
|
expect((*rebuilt)->position_to_offset({1, scalar_units}) == line_bytes + 6);
|
|
expect(!(*rebuilt)->offset_to_position(line_bytes + 1));
|
|
|
|
const auto replaced =
|
|
store.apply_changes(uri, 5, std::array{TextEdit{std::nullopt, ascii}});
|
|
require(replaced.has_value());
|
|
expect((*replaced)->offset_to_position(line_bytes) == Position{0, line_bytes});
|
|
expect(!(*replaced)->position_to_offset({1, 0}));
|
|
expect((*original)->position_to_offset({0, pivot + 1}) == pivot + 1);
|
|
expect(!(*mixed)->position_to_offset({0, pivot + 1}));
|
|
expect_eq((*mixed)->text, expected_mixed);
|
|
}
|
|
}
|