54 lines
1.7 KiB
C++
54 lines
1.7 KiB
C++
//
|
|
// Created by erki on 07.03.21.
|
|
//
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include "fixtures/RunOnCodeFixture.hpp"
|
|
|
|
TEST_CASE("Finds binary operations", "[basic_operation]")
|
|
{
|
|
auto binary_operand = GENERATE(std::string("="), std::string("+"), std::string("-"), std::string("/"),
|
|
std::string("*"), std::string("<<"), std::string(">>"),
|
|
std::string("^"), std::string("=="), std::string("|"), std::string("&"));
|
|
RunOnCodeFixture fixture;
|
|
|
|
const std::string code = "int main() { int a; (void)(a " + binary_operand + " 4); }";
|
|
const auto& operations = fixture(code);
|
|
|
|
REQUIRE(operations.size() == 1);
|
|
|
|
const OperationLog& log = operations.front();
|
|
|
|
REQUIRE(log.entry_type == OperationLog::BasicOperation::TYPE_NAME);
|
|
|
|
const OperationLog::BasicOperation* op = (OperationLog::BasicOperation*)(log.entry.get());
|
|
|
|
REQUIRE(op->operation_name == binary_operand);
|
|
REQUIRE(op->type_lhs == "int");
|
|
REQUIRE(op->type_rhs == "int");
|
|
REQUIRE(op->type_result == "int");
|
|
}
|
|
|
|
TEST_CASE("Find unary operations", "[basic_operation]")
|
|
{
|
|
auto unary_operand = GENERATE(std::string("++"), std::string("--"), std::string("~"), std::string("!"));
|
|
RunOnCodeFixture fixture;
|
|
|
|
const std::string code = "int main() { int a; (void)(" + unary_operand + "a); }";
|
|
const auto& operations = fixture(code);
|
|
|
|
REQUIRE(operations.size() == 1);
|
|
|
|
const OperationLog& log = operations.front();
|
|
|
|
REQUIRE(log.entry_type == OperationLog::BasicOperation::TYPE_NAME);
|
|
|
|
const OperationLog::BasicOperation* op = (OperationLog::BasicOperation*)(log.entry.get());
|
|
|
|
REQUIRE(op->operation_name == unary_operand);
|
|
REQUIRE(op->type_lhs == "int");
|
|
REQUIRE(op->type_rhs.empty());
|
|
REQUIRE(op->type_result == "int");
|
|
}
|