masters-thesis/op-finder-tests/function_calls.cpp
Erki a88a57e2ec
All checks were successful
continuous-integration/drone/push Build is passing
Function call tests
2021-03-07 18:37:13 +02:00

56 lines
1.4 KiB
C++

//
// Created by erki on 07.03.21.
//
#include <catch2/catch.hpp>
#include "fixtures/RunOnCodeFixture.hpp"
TEST_CASE("Find function call.", "[functions]")
{
RunOnCodeFixture fixture;
const std::string code = "int b(); int main() { b(); }";
const auto& operations = fixture(code);
REQUIRE(operations.size() == 1);
const OperationLog& log = operations.front();
REQUIRE(log.entry_type == OperationLog::FunctionCall::TYPE_NAME);
const OperationLog::FunctionCall* call = (OperationLog::FunctionCall*)log.entry.get();
REQUIRE(call->function_name == "b");
REQUIRE(call->call_result_type == "int");
}
TEST_CASE("Find stacked function calls.", "[functions]")
{
RunOnCodeFixture fixture;
const std::string code = "int a(int); int b(); int main() { a(b()); }";
const auto& operations = fixture(code);
REQUIRE(operations.size() == 2);
const OperationLog& log = operations.front();
REQUIRE(log.entry_type == OperationLog::FunctionCall::TYPE_NAME);
const OperationLog::FunctionCall* call = (OperationLog::FunctionCall*)log.entry.get();
REQUIRE(call->function_name == "a");
REQUIRE(call->call_result_type == "int");
const OperationLog& log_two = operations.back();
REQUIRE(log_two.entry_type == OperationLog::FunctionCall::TYPE_NAME);
const OperationLog::FunctionCall* call_two = (OperationLog::FunctionCall*)log_two.entry.get();
REQUIRE(call_two->function_name == "b");
REQUIRE(call_two->call_result_type == "int");
}