diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f99ebffec64c8142a222956d43cafff8949e62da..05ddfa76c1721fea5931f1bf1f0a59f7a7dc0eec 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_BinaryExpressionProcessor_shift.cpp test_BinaryOperatorMangler.cpp test_BiCGStab.cpp test_BuildInfo.cpp diff --git a/tests/test_BinaryExpressionProcessor_shift.cpp b/tests/test_BinaryExpressionProcessor_shift.cpp new file mode 100644 index 0000000000000000000000000000000000000000..082d5fc5e829e11ac14e700e226f07278fca13c8 --- /dev/null +++ b/tests/test_BinaryExpressionProcessor_shift.cpp @@ -0,0 +1,62 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_all.hpp> + +#include <test_BinaryExpressionProcessor_utils.hpp> + +#include <fstream> +#include <unistd.h> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("BinaryExpressionProcessor shift", "[language]") +{ + SECTION("<<") + { + std::filesystem::path path = std::filesystem::temp_directory_path(); + + path.append(std::string{"binary_expression_processor_"} + std::to_string(getpid())); + + std::string filename = path.string(); + + { + std::ostringstream data; + data << "let fout:ostream, fout = ofstream(\"" << path.string() << "\");\n"; + data << R"(fout << 2 << " " << true << " " << 2 + 3 << "\n";)"; + + TAO_PEGTL_NAMESPACE::string_input input{data.str(), "test.pgs"}; + auto ast = ASTBuilder::build(input); + + ASTModulesImporter{*ast}; + ASTNodeTypeCleaner<language::import_instruction>{*ast}; + + ASTSymbolTableBuilder{*ast}; + ASTNodeDataTypeBuilder{*ast}; + + ASTNodeDeclarationToAffectationConverter{*ast}; + ASTNodeTypeCleaner<language::var_declaration>{*ast}; + + ASTNodeExpressionBuilder{*ast}; + ExecutionPolicy exec_policy; + ast->execute(exec_policy); + } + + REQUIRE(std::filesystem::exists(filename)); + + { + std::string file_content; + std::ifstream fin(filename.c_str()); + + do { + char c = fin.get(); + if (c != EOF) { + file_content += c; + } + } while (fin); + + REQUIRE(file_content == "2 true 5\n"); + } + + std::filesystem::remove(filename); + REQUIRE(not std::filesystem::exists(filename)); + } +}