Skip to content
Snippets Groups Projects
Commit 6675ff79 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Begin CFunctionProcessor tests

parent e2dc76af
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -39,6 +39,7 @@ add_executable (unit_tests
test_BiCGStab.cpp
test_CFunctionEmbedder.cpp
test_CFunctionEmbedderTable.cpp
test_CFunctionProcessor.cpp
test_CMathModule.cpp
test_ContinueProcessor.cpp
test_ConcatExpressionProcessor.cpp
......
#include <catch2/catch.hpp>
#include <ASTNodeValueBuilder.hpp>
#include <ASTBuilder.hpp>
#include <ASTNodeDataTypeBuilder.hpp>
#include <ASTNodeDeclarationToAffectationConverter.hpp>
#include <ASTNodeTypeCleaner.hpp>
#include <ASTModulesImporter.hpp>
#include <ASTNodeExpressionBuilder.hpp>
#include <ASTNodeAffectationExpressionBuilder.hpp>
#include <ASTSymbolTableBuilder.hpp>
#include <ASTPrinter.hpp>
#include <Demangle.hpp>
#include <PEGGrammar.hpp>
#include <sstream>
#define CHECK_CFUNCTION_EVALUATION_RESULT(data, variable_name, expected_value) \
{ \
string_input input{data, "test.pgs"}; \
auto ast = ASTBuilder::build(input); \
\
ASTModulesImporter{*ast}; \
ASTNodeTypeCleaner<language::import_instruction>{*ast}; \
\
ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \
ASTNodeValueBuilder{*ast}; \
\
ASTNodeDeclarationToAffectationConverter{*ast}; \
ASTNodeTypeCleaner<language::declaration>{*ast}; \
ASTNodeTypeCleaner<language::let_declaration>{*ast}; \
\
ASTNodeExpressionBuilder{*ast}; \
ExecUntilBreakOrContinue exec_policy; \
ast->execute(exec_policy); \
\
auto symbol_table = ast->m_symbol_table; \
\
using namespace TAO_PEGTL_NAMESPACE; \
position use_position{internal::iterator{"fixture"}, "fixture"}; \
use_position.byte = 10000; \
auto [symbol, found] = symbol_table->find(variable_name, use_position); \
\
auto attributes = symbol->attributes(); \
auto value = std::get<decltype(expected_value)>(attributes.value()); \
\
REQUIRE(value == expected_value); \
}
TEST_CASE("CFunctionProcessor", "[language]")
{
SECTION("math module functions")
{
// @note HERE we do not use SECTION to be able to count tests and to check
// that all math functions are actually tested
std::set<std::string> tested_function_set;
{ // sqrt
tested_function_set.insert("sqrt");
std::string_view data = R"(
import math;
R x = sqrt(4);
)";
CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::sqrt(4l)});
}
{ // sin
tested_function_set.insert("sin");
std::string_view data = R"(
import math;
R x = sin(1.3);
)";
CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::sin(1.3)});
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment