add catch2 test
This commit is contained in:
50
test/test_engine.cpp
Normal file
50
test/test_engine.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// Created by ZekeXiao on 2025/10/18.
|
||||
//
|
||||
//
|
||||
// Created by ZekeXiao on 2025/10/18.
|
||||
//
|
||||
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include "mrubypp.h"
|
||||
|
||||
TEST_CASE("none args call", "[engine]") {
|
||||
mrubypp engine;
|
||||
engine.load(R"(
|
||||
def get_1()
|
||||
1
|
||||
end
|
||||
)");
|
||||
|
||||
auto b = engine.call<int>("get_1");
|
||||
REQUIRE(b == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("args call", "[engine]") {
|
||||
mrubypp engine;
|
||||
engine.load(R"(
|
||||
def add(a)
|
||||
a.sort!
|
||||
a[0]
|
||||
end
|
||||
)");
|
||||
|
||||
std::vector<int> a{3, 1, 2};
|
||||
auto b = engine.call<int>("add", a);
|
||||
REQUIRE(b == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("call benchmark", "[!benchmark]") {
|
||||
mrubypp engine;
|
||||
engine.load(R"(
|
||||
def get_same(a)
|
||||
return a
|
||||
end
|
||||
)");
|
||||
|
||||
BENCHMARK("call and return") {
|
||||
auto b = engine.call<int>("get_same", 1);
|
||||
REQUIRE(b == 1);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user