From b9b30bf1ee82b30f3fdc70af96729ba4839fcf1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Mon, 13 Sep 2021 11:25:14 +0200 Subject: [PATCH] Add tests for UnaryOperatorMangler and BinaryOperatorMangler --- tests/CMakeLists.txt | 2 ++ tests/test_BinaryOperatorMangler.cpp | 31 ++++++++++++++++++++++++++++ tests/test_UnaryOperatorMangler.cpp | 17 +++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tests/test_BinaryOperatorMangler.cpp create mode 100644 tests/test_UnaryOperatorMangler.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5902fa80c..f99ebffec 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,6 +44,7 @@ add_executable (unit_tests test_BinaryExpressionProcessor_comparison.cpp test_BinaryExpressionProcessor_equality.cpp test_BinaryExpressionProcessor_logic.cpp + test_BinaryOperatorMangler.cpp test_BiCGStab.cpp test_BuildInfo.cpp test_BuiltinFunctionEmbedder.cpp @@ -102,6 +103,7 @@ add_executable (unit_tests test_TinyVector.cpp test_TupleToVectorProcessor.cpp test_UnaryExpressionProcessor.cpp + test_UnaryOperatorMangler.cpp test_Vector.cpp test_WhileProcessor.cpp ) diff --git a/tests/test_BinaryOperatorMangler.cpp b/tests/test_BinaryOperatorMangler.cpp new file mode 100644 index 000000000..329c59dcb --- /dev/null +++ b/tests/test_BinaryOperatorMangler.cpp @@ -0,0 +1,31 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_all.hpp> + +#include <language/utils/BinaryOperatorMangler.hpp> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("BinaryOperatorMangler", "[language]") +{ + SECTION("binary operators") + { + const ASTNodeDataType R = ASTNodeDataType::build<ASTNodeDataType::double_t>(); + const ASTNodeDataType Z = ASTNodeDataType::build<ASTNodeDataType::int_t>(); + + REQUIRE(binaryOperatorMangler<language::multiply_op>(R, Z) == "R * Z"); + REQUIRE(binaryOperatorMangler<language::divide_op>(R, Z) == "R / Z"); + REQUIRE(binaryOperatorMangler<language::plus_op>(R, Z) == "R + Z"); + REQUIRE(binaryOperatorMangler<language::minus_op>(R, Z) == "R - Z"); + REQUIRE(binaryOperatorMangler<language::or_op>(R, Z) == "R or Z"); + REQUIRE(binaryOperatorMangler<language::and_op>(R, Z) == "R and Z"); + REQUIRE(binaryOperatorMangler<language::xor_op>(R, Z) == "R xor Z"); + REQUIRE(binaryOperatorMangler<language::greater_op>(R, Z) == "R > Z"); + REQUIRE(binaryOperatorMangler<language::greater_or_eq_op>(R, Z) == "R >= Z"); + REQUIRE(binaryOperatorMangler<language::lesser_op>(R, Z) == "R < Z"); + REQUIRE(binaryOperatorMangler<language::lesser_or_eq_op>(R, Z) == "R <= Z"); + REQUIRE(binaryOperatorMangler<language::eqeq_op>(R, Z) == "R == Z"); + REQUIRE(binaryOperatorMangler<language::not_eq_op>(R, Z) == "R != Z"); + REQUIRE(binaryOperatorMangler<language::shift_left_op>(R, Z) == "R << Z"); + REQUIRE(binaryOperatorMangler<language::shift_right_op>(R, Z) == "R >> Z"); + } +} diff --git a/tests/test_UnaryOperatorMangler.cpp b/tests/test_UnaryOperatorMangler.cpp new file mode 100644 index 000000000..c533e882a --- /dev/null +++ b/tests/test_UnaryOperatorMangler.cpp @@ -0,0 +1,17 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_all.hpp> + +#include <language/utils/UnaryOperatorMangler.hpp> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("UnaryOperatorMangler", "[language]") +{ + SECTION("unary operators") + { + const ASTNodeDataType Z = ASTNodeDataType::build<ASTNodeDataType::int_t>(); + + REQUIRE(unaryOperatorMangler<language::unary_minus>(Z) == "- Z"); + REQUIRE(unaryOperatorMangler<language::unary_not>(Z) == "not Z"); + } +} -- GitLab