From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/tests/unit/misc/variant/local.am | 3 ++ .../unit/misc/variant/test_variant_three_types.cc | 35 ++++++++++++++++++++++ .../unit/misc/variant/test_variant_two_types.cc | 28 +++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tiger-compiler/tests/unit/misc/variant/local.am create mode 100644 tiger-compiler/tests/unit/misc/variant/test_variant_three_types.cc create mode 100644 tiger-compiler/tests/unit/misc/variant/test_variant_two_types.cc (limited to 'tiger-compiler/tests/unit/misc/variant') diff --git a/tiger-compiler/tests/unit/misc/variant/local.am b/tiger-compiler/tests/unit/misc/variant/local.am new file mode 100644 index 0000000..f09d993 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/variant/local.am @@ -0,0 +1,3 @@ +check_unit_SOURCES += \ + %D%/test_variant_two_types.cc \ + %D%/test_variant_three_types.cc diff --git a/tiger-compiler/tests/unit/misc/variant/test_variant_three_types.cc b/tiger-compiler/tests/unit/misc/variant/test_variant_three_types.cc new file mode 100644 index 0000000..8728059 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/variant/test_variant_three_types.cc @@ -0,0 +1,35 @@ +#include +#include +#include + +using multiple_variant_type = misc::variant; + +Test(variant_three_types, simple_success_type_a) +{ + multiple_variant_type v("Hello"); + std::string s = v; + cr_expect_str_eq(s.c_str(), "Hello"); +} + +Test(variant_three_types, simple_success_type_b) +{ + multiple_variant_type v(56.7); + double d = v; + cr_expect_eq(d, 56.7); +} + +Test(variant_three_types, simple_failure_type_c) +{ + multiple_variant_type v(34.5); + + try + { + [[maybe_unused]] int i = v; + } + catch (const std::bad_variant_access& e) + { + return; + } + + cr_expect_eq(1, 0, "copy assignment did not throw an exception"); +} diff --git a/tiger-compiler/tests/unit/misc/variant/test_variant_two_types.cc b/tiger-compiler/tests/unit/misc/variant/test_variant_two_types.cc new file mode 100644 index 0000000..9a63d6a --- /dev/null +++ b/tiger-compiler/tests/unit/misc/variant/test_variant_two_types.cc @@ -0,0 +1,28 @@ +#include +#include +#include + +using variant_type = misc::variant; + +Test(variant_two_types, simple_success) +{ + misc::variant v("Hello"); + std::string s = v; + cr_expect_str_eq(s.c_str(), "Hello"); +} + +Test(variant_two_types, simple_failure) +{ + variant_type v(42); + + try + { + std::string s = v; + } + catch (const std::bad_variant_access& e) + { + return; + } + + cr_expect_eq(1, 0, "copy assignment did not throw an exception"); +} -- cgit v1.2.3