File indexing completed on 2026-10-29 08:25:01
0001
0002
0003
0004
0005
0006 #include <algorithms/error.h>
0007
0008 #include <catch2/catch_test_macros.hpp>
0009
0010 #include <exception>
0011 #include <string>
0012 #include <type_traits>
0013
0014 using namespace algorithms;
0015
0016 TEST_CASE("Error carries a message and a default type", "[error]") {
0017 const Error e{"something went wrong"};
0018 CHECK(std::string{e.what()} == "something went wrong");
0019 CHECK(std::string{e.type()} == "algorithms::Error");
0020 }
0021
0022 TEST_CASE("Error carries a custom type", "[error]") {
0023 const Error e{"bad value", "my::CustomError"};
0024 CHECK(std::string{e.what()} == "bad value");
0025 CHECK(std::string{e.type()} == "my::CustomError");
0026 }
0027
0028 TEST_CASE("Error can be caught as std::exception", "[error]") {
0029 STATIC_REQUIRE(std::is_base_of_v<std::exception, Error>);
0030 try {
0031 throw Error{"thrown"};
0032 } catch (const std::exception& e) {
0033 CHECK(std::string{e.what()} == "thrown");
0034 }
0035 }