From a07c64148eb60b886f92caa46a9c687240ec420c Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sat, 20 Jul 2024 21:02:30 -0400 Subject: Add backslash identifier support to v2script Add buffer::char_type size multiplier to max file size of string intern buffer Fix list grammar segfaults Fix diagnostic logger intern segfaults from buffer reallocation Fix non-string-supported CSV parser not supporting Victoria 2 CSV escaping behavior --- tests/src/Error.cpp | 59 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'tests/src/Error.cpp') diff --git a/tests/src/Error.cpp b/tests/src/Error.cpp index 136b650..7c78cd4 100644 --- a/tests/src/Error.cpp +++ b/tests/src/Error.cpp @@ -14,7 +14,7 @@ using namespace ovdl; using namespace ovdl::error; using namespace std::string_view_literals; -struct ErrorTree : SymbolIntern { +struct ErrorTree : ovdl::error::ErrorSymbolInterner { using error_range = detail::error_range; dryad::node_map map; @@ -27,42 +27,59 @@ struct ErrorTree : SymbolIntern { } template - T* create(BasicNodeLocation loc, Args&&... args) { + T* create(BasicNodeLocation loc, std::string_view message, Args&&... args) { using node_creator = dryad::node_creator; - T* result = tree.create(DRYAD_FWD(args)...); + T* result = tree.create(symbol_interner.intern(message.data(), message.length()), DRYAD_FWD(args)...); map.insert(result, loc); return result; } template - T* create(Args&&... args) { + T* create(std::string_view message, Args&&... args) { using node_creator = dryad::node_creator; - T* result = tree.create(DRYAD_FWD(args)...); + T* result = tree.create(symbol_interner.intern(message.data(), message.length()), DRYAD_FWD(args)...); return result; } + template + T* create() { + static_assert(!std::same_as, "Only supports error::Root"); + return nullptr; + } + error_range get_errors() const { return tree.root()->errors(); } + std::string_view error(const ovdl::error::Error* error) const { + return error->message(symbol_interner); + } + void insert(error::Error* root) { tree.root()->insert_back(root); } }; +template<> +inline error::Root* ErrorTree::create() { + using node_creator = dryad::node_creator; + error::Root* result = tree.create(); + return result; +} + TEST_CASE("Error Nodes", "[error-nodes]") { ErrorTree errors; auto* buffer_error = errors.create("error"); CHECK_IF(buffer_error) { CHECK(buffer_error->kind() == ErrorKind::BufferError); - CHECK(buffer_error->message() == "error"sv); + CHECK(errors.error(buffer_error) == "error"sv); } auto* expect_lit = errors.create("expected lit", "production"); CHECK_IF(expect_lit) { CHECK(expect_lit->kind() == ErrorKind::ExpectedLiteral); - CHECK(expect_lit->message() == "expected lit"sv); + CHECK(errors.error(expect_lit) == "expected lit"sv); CHECK(expect_lit->production_name() == "production"sv); CHECK(expect_lit->annotations().empty()); } @@ -70,7 +87,7 @@ TEST_CASE("Error Nodes", "[error-nodes]") { auto* expect_kw = errors.create("expected keyword", "production2"); CHECK_IF(expect_kw) { CHECK(expect_kw->kind() == ErrorKind::ExpectedKeyword); - CHECK(expect_kw->message() == "expected keyword"sv); + CHECK(errors.error(expect_kw) == "expected keyword"sv); CHECK(expect_kw->production_name() == "production2"sv); CHECK(expect_kw->annotations().empty()); } @@ -78,7 +95,7 @@ TEST_CASE("Error Nodes", "[error-nodes]") { auto* expect_char_c = errors.create("expected char", "production3"); CHECK_IF(expect_char_c) { CHECK(expect_char_c->kind() == ErrorKind::ExpectedCharClass); - CHECK(expect_char_c->message() == "expected char"sv); + CHECK(errors.error(expect_char_c) == "expected char"sv); CHECK(expect_char_c->production_name() == "production3"sv); CHECK(expect_char_c->annotations().empty()); } @@ -86,7 +103,7 @@ TEST_CASE("Error Nodes", "[error-nodes]") { auto* generic_error = errors.create("generic error", "production 4"); CHECK_IF(generic_error) { CHECK(generic_error->kind() == ErrorKind::GenericParseError); - CHECK(generic_error->message() == "generic error"sv); + CHECK(errors.error(generic_error) == "generic error"sv); CHECK(generic_error->production_name() == "production 4"sv); CHECK(generic_error->annotations().empty()); } @@ -94,55 +111,55 @@ TEST_CASE("Error Nodes", "[error-nodes]") { auto* sem_error = errors.create("sem error"); CHECK_IF(sem_error) { CHECK(sem_error->kind() == ErrorKind::SemanticError); - CHECK(sem_error->message() == "sem error"sv); + CHECK(errors.error(sem_error) == "sem error"sv); CHECK(sem_error->annotations().empty()); } auto* sem_warn = errors.create("sem warn"); CHECK_IF(sem_warn) { CHECK(sem_warn->kind() == ErrorKind::SemanticWarning); - CHECK(sem_warn->message() == "sem warn"sv); + CHECK(errors.error(sem_warn) == "sem warn"sv); CHECK(sem_warn->annotations().empty()); } auto* sem_info = errors.create("sem info"); CHECK_IF(sem_info) { CHECK(sem_info->kind() == ErrorKind::SemanticInfo); - CHECK(sem_info->message() == "sem info"sv); + CHECK(errors.error(sem_info) == "sem info"sv); CHECK(sem_info->annotations().empty()); } auto* sem_debug = errors.create("sem debug"); CHECK_IF(sem_debug) { CHECK(sem_debug->kind() == ErrorKind::SemanticDebug); - CHECK(sem_debug->message() == "sem debug"sv); + CHECK(errors.error(sem_debug) == "sem debug"sv); CHECK(sem_debug->annotations().empty()); } auto* sem_fixit = errors.create("sem fixit"); CHECK_IF(sem_fixit) { CHECK(sem_fixit->kind() == ErrorKind::SemanticFixit); - CHECK(sem_fixit->message() == "sem fixit"sv); + CHECK(errors.error(sem_fixit) == "sem fixit"sv); CHECK(sem_fixit->annotations().empty()); } auto* sem_help = errors.create("sem help"); CHECK_IF(sem_help) { CHECK(sem_help->kind() == ErrorKind::SemanticHelp); - CHECK(sem_help->message() == "sem help"sv); + CHECK(errors.error(sem_help) == "sem help"sv); CHECK(sem_help->annotations().empty()); } auto* prim_annotation = errors.create("primary annotation"); CHECK_IF(prim_annotation) { CHECK(prim_annotation->kind() == ErrorKind::PrimaryAnnotation); - CHECK(prim_annotation->message() == "primary annotation"sv); + CHECK(errors.error(prim_annotation) == "primary annotation"sv); } auto* sec_annotation = errors.create("secondary annotation"); CHECK_IF(sec_annotation) { CHECK(sec_annotation->kind() == ErrorKind::SecondaryAnnotation); - CHECK(sec_annotation->message() == "secondary annotation"sv); + CHECK(errors.error(sec_annotation) == "secondary annotation"sv); } AnnotationList annotation_list {}; @@ -153,7 +170,7 @@ TEST_CASE("Error Nodes", "[error-nodes]") { auto* annotated_error = errors.create("annotated error", annotation_list); CHECK_IF(annotated_error) { CHECK(annotated_error->kind() == ErrorKind::SemanticError); - CHECK(annotated_error->message() == "annotated error"sv); + CHECK(errors.error(annotated_error) == "annotated error"sv); auto annotations = annotated_error->annotations(); CHECK_FALSE(annotations.empty()); for (const auto [annotation, list_val] : ranges::views::zip(annotations, annotation_list)) { @@ -216,10 +233,10 @@ TEST_CASE("Error Nodes Location", "[error-nodes-location]") { constexpr auto fake_buffer = "id"sv; - auto* expected_lit = errors.create(NodeLocation::make_from(&fake_buffer[0], &fake_buffer[1]), "expected lit", "production"); + auto* expected_lit = errors.create(NodeLocation::make_from(&fake_buffer[0], &fake_buffer[1]), "expected lit"sv, "production"); CHECK_IF(expected_lit) { - CHECK(expected_lit->message() == "expected lit"sv); + CHECK(errors.error(expected_lit) == "expected lit"sv); CHECK(expected_lit->production_name() == "production"sv); auto location = errors.location_of(expected_lit); -- cgit v1.2.3-56-ga3b1