summaryrefslogtreecommitdiff
path: root/tiger-compiler/tests/unit/misc
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tests/unit/misc
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/tests/unit/misc')
-rw-r--r--tiger-compiler/tests/unit/misc/local.am5
-rw-r--r--tiger-compiler/tests/unit/misc/symbol/local.am2
-rw-r--r--tiger-compiler/tests/unit/misc/symbol/test_symbol_simple.cc21
-rw-r--r--tiger-compiler/tests/unit/misc/test_hello.cc6
-rw-r--r--tiger-compiler/tests/unit/misc/unique/local.am4
-rw-r--r--tiger-compiler/tests/unit/misc/unique/test_unique_char.cc18
-rw-r--r--tiger-compiler/tests/unit/misc/unique/test_unique_int.cc18
-rw-r--r--tiger-compiler/tests/unit/misc/unique/test_unique_string.cc19
-rw-r--r--tiger-compiler/tests/unit/misc/variant/local.am3
-rw-r--r--tiger-compiler/tests/unit/misc/variant/test_variant_three_types.cc35
-rw-r--r--tiger-compiler/tests/unit/misc/variant/test_variant_two_types.cc28
11 files changed, 159 insertions, 0 deletions
diff --git a/tiger-compiler/tests/unit/misc/local.am b/tiger-compiler/tests/unit/misc/local.am
new file mode 100644
index 0000000..db96069
--- /dev/null
+++ b/tiger-compiler/tests/unit/misc/local.am
@@ -0,0 +1,5 @@
+include %D%/unique/local.am
+include %D%/symbol/local.am
+include %D%/variant/local.am
+
+check_unit_SOURCES += %D%/test_hello.cc
diff --git a/tiger-compiler/tests/unit/misc/symbol/local.am b/tiger-compiler/tests/unit/misc/symbol/local.am
new file mode 100644
index 0000000..fbc4825
--- /dev/null
+++ b/tiger-compiler/tests/unit/misc/symbol/local.am
@@ -0,0 +1,2 @@
+check_unit_SOURCES += \
+ %D%/test_symbol_simple.cc
diff --git a/tiger-compiler/tests/unit/misc/symbol/test_symbol_simple.cc b/tiger-compiler/tests/unit/misc/symbol/test_symbol_simple.cc
new file mode 100644
index 0000000..a49ed27
--- /dev/null
+++ b/tiger-compiler/tests/unit/misc/symbol/test_symbol_simple.cc
@@ -0,0 +1,21 @@
+#include <criterion/criterion.h>
+#include <criterion/assert.h>
+#include <misc/symbol.hh>
+
+Test(test_symbol, simple)
+{
+ const misc::symbol toto1("toto");
+ const misc::symbol toto2("toto");
+ const misc::symbol titi1("titi");
+
+ cr_expect_eq(toto1, "toto");
+ cr_expect_neq(toto1, "titi");
+
+ cr_expect_eq(toto1, toto2);
+ cr_expect_neq(toto1, titi1);
+
+ std::string junk = "tata";
+ const misc::symbol tata1(junk);
+ junk = "toto";
+ cr_expect_eq(tata1, "tata");
+}
diff --git a/tiger-compiler/tests/unit/misc/test_hello.cc b/tiger-compiler/tests/unit/misc/test_hello.cc
new file mode 100644
index 0000000..e18e1d8
--- /dev/null
+++ b/tiger-compiler/tests/unit/misc/test_hello.cc
@@ -0,0 +1,6 @@
+#include <criterion/criterion.h>
+
+Test(misc, hello)
+{
+ 1;
+}
diff --git a/tiger-compiler/tests/unit/misc/unique/local.am b/tiger-compiler/tests/unit/misc/unique/local.am
new file mode 100644
index 0000000..9911c25
--- /dev/null
+++ b/tiger-compiler/tests/unit/misc/unique/local.am
@@ -0,0 +1,4 @@
+check_unit_SOURCES += \
+ %D%/test_unique_int.cc \
+ %D%/test_unique_char.cc \
+ %D%/test_unique_string.cc
diff --git a/tiger-compiler/tests/unit/misc/unique/test_unique_char.cc b/tiger-compiler/tests/unit/misc/unique/test_unique_char.cc
new file mode 100644
index 0000000..d69b42c
--- /dev/null
+++ b/tiger-compiler/tests/unit/misc/unique/test_unique_char.cc
@@ -0,0 +1,18 @@
+#include <criterion/criterion.h>
+#include <criterion/assert.h>
+#include <misc/unique.hh>
+
+Test(unique_char, simple)
+{
+ misc::unique<char> the_answer = 'a';
+ misc::unique<char> the_same_answer = 'a';
+ misc::unique<char> the_solution = 'b';
+
+ cr_expect_eq(the_answer, misc::unique<char>('a'));
+ cr_expect_eq(the_answer, the_same_answer);
+ cr_expect_neq(the_answer, the_solution);
+
+ cr_expect_eq(the_answer.get(), the_same_answer.get());
+ cr_expect_eq(the_answer.get(), misc::unique<char>('a').get());
+ cr_expect_neq(the_answer.get(), the_solution.get());
+}
diff --git a/tiger-compiler/tests/unit/misc/unique/test_unique_int.cc b/tiger-compiler/tests/unit/misc/unique/test_unique_int.cc
new file mode 100644
index 0000000..f25c3c2
--- /dev/null
+++ b/tiger-compiler/tests/unit/misc/unique/test_unique_int.cc
@@ -0,0 +1,18 @@
+#include <criterion/criterion.h>
+#include <criterion/assert.h>
+#include <misc/unique.hh>
+
+Test(unique_int, simple)
+{
+ misc::unique<int> the_answer = 42;
+ misc::unique<int> the_same_answer = 42;
+ misc::unique<int> the_solution = 51;
+
+ cr_expect_eq(the_answer, misc::unique<int>(42));
+ cr_expect_eq(the_answer, the_same_answer);
+ cr_expect_neq(the_answer, the_solution);
+
+ cr_expect_eq(the_answer.get(), the_same_answer.get());
+ cr_expect_eq(the_answer.get(), misc::unique<int>(42).get());
+ cr_expect_neq(the_answer.get(), the_solution.get());
+}
diff --git a/tiger-compiler/tests/unit/misc/unique/test_unique_string.cc b/tiger-compiler/tests/unit/misc/unique/test_unique_string.cc
new file mode 100644
index 0000000..2542375
--- /dev/null
+++ b/tiger-compiler/tests/unit/misc/unique/test_unique_string.cc
@@ -0,0 +1,19 @@
+#include <criterion/criterion.h>
+#include <criterion/assert.h>
+#include <misc/unique.hh>
+#include <string>
+
+Test(unique_string, simple)
+{
+ misc::unique<std::string> the_answer = std::string("skibidi");
+ misc::unique<std::string> the_same_answer = std::string("skibidi");
+ misc::unique<std::string> the_solution = std::string("yes yes");
+
+ cr_expect_eq(the_answer, misc::unique<std::string>(std::string("skibidi")));
+ cr_expect_eq(the_answer, the_same_answer);
+ cr_expect_neq(the_answer, the_solution);
+
+ cr_expect_eq(the_answer.get(), the_same_answer.get());
+ cr_expect_eq(the_answer.get(), misc::unique<std::string>(std::string("skibidi")).get());
+ cr_expect_neq(the_answer.get(), the_solution.get());
+}
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 <criterion/criterion.h>
+#include <criterion/assert.h>
+#include <misc/variant.hh>
+
+using multiple_variant_type = misc::variant<int, std::string, double>;
+
+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 <criterion/criterion.h>
+#include <criterion/assert.h>
+#include <misc/variant.hh>
+
+using variant_type = misc::variant<int, std::string>;
+
+Test(variant_two_types, simple_success)
+{
+ misc::variant<int, std::string> 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");
+}