aboutsummaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2024-07-21 03:02:30 +0200
committer Spartan322 <Megacake1234@gmail.com>2024-07-22 02:49:25 +0200
commita07c64148eb60b886f92caa46a9c687240ec420c (patch)
treee43aae271fe5aa75f1b0c918c1428e7f766a14f8 /tests/src
parentba8addc72595607206da654bc79c994121b7a3ae (diff)
Add backslash identifier support to v2scriptadd/backslash-identifier
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
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/Error.cpp59
1 files changed, 38 insertions, 21 deletions
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<error::Root>;
dryad::node_map<const error::Error, NodeLocation> map;
@@ -27,42 +27,59 @@ struct ErrorTree : SymbolIntern {
}
template<typename T, typename LocCharT, typename... Args>
- T* create(BasicNodeLocation<LocCharT> loc, Args&&... args) {
+ T* create(BasicNodeLocation<LocCharT> loc, std::string_view message, Args&&... args) {
using node_creator = dryad::node_creator<decltype(DRYAD_DECLVAL(T).kind()), void>;
- T* result = tree.create<T>(DRYAD_FWD(args)...);
+ T* result = tree.create<T>(symbol_interner.intern(message.data(), message.length()), DRYAD_FWD(args)...);
map.insert(result, loc);
return result;
}
template<typename T, typename... Args>
- T* create(Args&&... args) {
+ T* create(std::string_view message, Args&&... args) {
using node_creator = dryad::node_creator<decltype(DRYAD_DECLVAL(T).kind()), void>;
- T* result = tree.create<T>(DRYAD_FWD(args)...);
+ T* result = tree.create<T>(symbol_interner.intern(message.data(), message.length()), DRYAD_FWD(args)...);
return result;
}
+ template<typename T>
+ T* create() {
+ static_assert(!std::same_as<T, error::Root>, "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<error::Root>() {
+ using node_creator = dryad::node_creator<decltype(DRYAD_DECLVAL(error::Root).kind()), void>;
+ error::Root* result = tree.create<error::Root>();
+ return result;
+}
+
TEST_CASE("Error Nodes", "[error-nodes]") {
ErrorTree errors;
auto* buffer_error = errors.create<BufferError>("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<ExpectedLiteral>("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<ExpectedKeyword>("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<ExpectedCharClass>("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<GenericParseError>("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<SemanticError>("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<SemanticWarning>("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<SemanticInfo>("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<SemanticDebug>("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<SemanticFixit>("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<SemanticHelp>("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<PrimaryAnnotation>("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<SecondaryAnnotation>("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<SemanticError>("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<ExpectedLiteral>(NodeLocation::make_from(&fake_buffer[0], &fake_buffer[1]), "expected lit", "production");
+ auto* expected_lit = errors.create<ExpectedLiteral>(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);