User-defined operators: Tests

This commit is contained in:
wechman
2023-02-22 00:40:03 +01:00
committed by Kamil Śliwak
parent 5b5e853ea0
commit aba5ac5e2a
114 changed files with 3956 additions and 1 deletions
@@ -1702,6 +1702,72 @@ BOOST_AUTO_TEST_CASE(using_for)
checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges);
}
BOOST_AUTO_TEST_CASE(user_defined_binary_operator)
{
unique_ptr<CompilerStack> compilerStack = parseAndAnalyzeContracts(R"(
type Int is int128;
using {add as +} for Int global;
function add(Int, Int) pure returns (Int) {
return Int.wrap(0);
}
contract C {
function pub() public {
Int.wrap(0) + Int.wrap(1);
}
}
)"s);
tuple<CallGraphMap, CallGraphMap> graphs = collectGraphs(*compilerStack);
map<string, EdgeNames> expectedCreationEdges = {
{"C", {}},
};
map<string, EdgeNames> expectedDeployedEdges = {
{"C", {
{"Entry", "function C.pub()"},
{"function C.pub()", "function add(Int,Int)"},
}},
};
checkCallGraphExpectations(get<0>(graphs), expectedCreationEdges);
checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges);
}
BOOST_AUTO_TEST_CASE(user_defined_unary_operator)
{
unique_ptr<CompilerStack> compilerStack = parseAndAnalyzeContracts(R"(
type Int is int128;
using {sub as -} for Int global;
function sub(Int) pure returns (Int) {
return Int.wrap(0);
}
contract C {
function pub() public {
-Int.wrap(1);
}
}
)"s);
tuple<CallGraphMap, CallGraphMap> graphs = collectGraphs(*compilerStack);
map<string, EdgeNames> expectedCreationEdges = {
{"C", {}},
};
map<string, EdgeNames> expectedDeployedEdges = {
{"C", {
{"Entry", "function C.pub()"},
{"function C.pub()", "function sub(Int)"},
}},
};
checkCallGraphExpectations(get<0>(graphs), expectedCreationEdges);
checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges);
}
BOOST_AUTO_TEST_CASE(getters)
{
unique_ptr<CompilerStack> compilerStack = parseAndAnalyzeContracts(R"(