diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-12-04 13:45:37 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-12-04 13:45:37 +0100 |
commit | 8da0229a7e172a86c023edc6bb25ba803c68f5d3 (patch) | |
tree | c305cf094528b70ae99af79a9a650f9dc98fc0b9 /modules/core/tests/core.cpp | |
parent | fb7ed24d557c9f9ac5eaa60dbf22cba509953c1a (diff) |
core, tests: Moving core tests to core module
Diffstat (limited to 'modules/core/tests/core.cpp')
-rw-r--r-- | modules/core/tests/core.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/modules/core/tests/core.cpp b/modules/core/tests/core.cpp new file mode 100644 index 0000000..2b63b94 --- /dev/null +++ b/modules/core/tests/core.cpp @@ -0,0 +1,67 @@ +#include "../c++/test/suite.h" +#include "../c++/id.h" +#include "../c++/id_map.h" +#include "../c++/string_literal.h" + +namespace { +SAW_TEST("ID functionality") { + using namespace saw; + struct foo {}; + + id<foo> a{1}; + id<foo> b{1}; + id<foo> c{2}; + + /** + * The following doesn't compile, so it's commented out as an example + */ + /** + * struct bar {}; + * + * id<bar> d{1}; + * + * SAW_EXPECT(a == d, "Shouldn't compile"); + */ + + SAW_EXPECT(a == b, "Should be equal"); + SAW_EXPECT(a != c, "Shouldn't be equal"); + SAW_EXPECT(b != c, "Shouldn't be equal"); + SAW_EXPECT(a.get_value() == 1, "Lost original value"); +} + +SAW_TEST("String Literal Append"){ + using namespace saw; + + constexpr string_literal a = "foo"; + constexpr string_literal b = "bar"; + constexpr string_literal c = a+b; + + SAW_EXPECT(c == "foobar", "CT String sum is not \"foobar\""); +} + +SAW_TEST("ID Map Insert"){ + using namespace saw; + + struct foo {}; + + id_map<foo> map; + { + auto eoid = map.insert(foo{}); + SAW_EXPECT(eoid.is_value(), "First insert failed"); + + auto& id = eoid.get_value(); + + auto eoid_2 = map.insert(foo{}); + SAW_EXPECT(eoid_2.is_value(), "Second Insert failed"); + auto& id_2 = eoid_2.get_value(); + + SAW_EXPECT(id != id_2, "Shouldn't be equal"); + + auto eov = map.erase(id); + SAW_EXPECT(eov.is_value(), "Erase failed"); + + auto eov_2 = map.erase(id); + SAW_EXPECT(eov_2.is_error(), "This is a double free"); + } +} +} |