From 336c2aa8861b4a786c60a61a9f86bb30ef8cb076 Mon Sep 17 00:00:00 2001 From: Mikolaj Izdebski Date: Tue, 22 Jul 2025 13:36:14 +0200 Subject: [PATCH] Eliminate use of assert_that in favor of assert_eq Replace all uses of assert_that with assert_eq for consistency and clearer test failure messages. assert_eq is already used elsewhere and provides better diagnostics by showing expected vs. actual values. --- src/jurand_test.cpp | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/jurand_test.cpp b/src/jurand_test.cpp index f6c9ce7..cc0bb2b 100644 --- a/src/jurand_test.cpp +++ b/src/jurand_test.cpp @@ -5,6 +5,12 @@ using namespace java_symbols; +template +static std::ostream &operator<<(std::ostream &os, const std::tuple &t) +{ + return os << "(" << std::get<0>(t) << ", " << std::get<1>(t) << ")"; +} + static void assert_eq(const auto& expected, const auto& actual) { if (expected != actual) @@ -15,14 +21,6 @@ static void assert_eq(const auto& expected, const auto& actual) } } -static void assert_that(bool value) -{ - if (not value) - { - throw std::runtime_error("Test failed"); - } -} - int main() { std::cout << "Running tests..." << "\n"; @@ -96,28 +94,28 @@ int main() assert_eq(0, find_token("import/", "import", 0, true)); assert_eq(0, find_token("import+", "import", 0, true)); - assert_that(next_annotation_t("@A", "A") == next_annotation("@A")); - assert_that(next_annotation_t("@A", "A") == next_annotation("@A\n")); - assert_that(next_annotation_t("@A()", "A") == next_annotation("@A()")); + assert_eq(next_annotation_t("@A", "A"), next_annotation("@A")); + assert_eq(next_annotation_t("@A", "A"), next_annotation("@A\n")); + assert_eq(next_annotation_t("@A()", "A"), next_annotation("@A()")); - assert_that(next_annotation_t("@A", "A") == next_annotation("@A class B {}")); + assert_eq(next_annotation_t("@A", "A"), next_annotation("@A class B {}")); - assert_that(next_annotation_t("@A(a = ')')", "A") == next_annotation("@A(a = ')')")); - assert_that(next_annotation_t("@A(a = ')')", "A") == next_annotation("@A(a = ')') class B {}")); + assert_eq(next_annotation_t("@A(a = ')')", "A"), next_annotation("@A(a = ')')")); + assert_eq(next_annotation_t("@A(a = ')')", "A"), next_annotation("@A(a = ')') class B {}")); - assert_that(next_annotation_t("@A(a = \")\")", "A") == next_annotation("@A(a = \")\")")); - assert_that(next_annotation_t("@A(a = \")))\" /*)))*/)", "A") == next_annotation("@A(a = \")))\" /*)))*/) class B {}")); - assert_that(next_annotation_t("@A(/* ) */)", "A") == next_annotation("@A(/* ) */)")); - assert_that(next_annotation_t("@A", "A") == next_annotation("method(@A Object o)")); + assert_eq(next_annotation_t("@A(a = \")\")", "A"), next_annotation("@A(a = \")\")")); + assert_eq(next_annotation_t("@A(a = \")))\" /*)))*/)", "A"), next_annotation("@A(a = \")))\" /*)))*/) class B {}")); + assert_eq(next_annotation_t("@A(/* ) */)", "A"), next_annotation("@A(/* ) */)")); + assert_eq(next_annotation_t("@A", "A"), next_annotation("method(@A Object o)")); - assert_that(next_annotation_t("@A(\nvalue = \")\" /* ) */\n// )\n)", "A") == next_annotation("@A(\nvalue = \")\" /* ) */\n// )\n)\n")); + assert_eq(next_annotation_t("@A(\nvalue = \")\" /* ) */\n// )\n)", "A"), next_annotation("@A(\nvalue = \")\" /* ) */\n// )\n)\n")); - assert_that(next_annotation_t("@D", "D") == next_annotation(" // @A\n/* @B */\nvalue = \"@C\";\n@D")); + assert_eq(next_annotation_t("@D", "D"), next_annotation(" // @A\n/* @B */\nvalue = \"@C\";\n@D")); - assert_that(next_annotation_t("@a.b.C", "a.b.C") == next_annotation("@a.b.C")); - assert_that(next_annotation_t("@a/**/.B", "a.B") == next_annotation("@a/**/.B")); + assert_eq(next_annotation_t("@a.b.C", "a.b.C"), next_annotation("@a.b.C")); + assert_eq(next_annotation_t("@a/**/.B", "a.B"), next_annotation("@a/**/.B")); - assert_that(next_annotation_t("@A(value = /* ) */ \")\")", "A") == next_annotation("@A(value = /* ) */ \")\")//)")); + assert_eq(next_annotation_t("@A(value = /* ) */ \")\")", "A"), next_annotation("@A(value = /* ) */ \")\")//)")); { constexpr std::string_view original_content = R"(