add catch2 test

This commit is contained in:
2025-10-18 20:07:52 +08:00
parent 494569393d
commit 585dad42e4
4 changed files with 106 additions and 30 deletions

50
test/test_engine.cpp Normal file
View 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);
};
}