use namespace & not fix return

This commit is contained in:
2025-10-22 22:42:30 +08:00
parent 2e5df6f1d6
commit 75caef3bd2
7 changed files with 123 additions and 138 deletions

View File

@@ -4,12 +4,11 @@
#include <catch2/catch_all.hpp>
#include "mrubypp.h"
#include "engine.h"
class Point {
public:
Point(int x, int y) : x_(x), y_(y) {
}
Point(int x, int y) : x_(x), y_(y) {}
void set_values(int x, int y) {
x_ = x;
@@ -18,15 +17,11 @@ public:
int get_x() const { return x_; }
void set_x(int x) {
x_ = x;
}
void set_x(int x) { x_ = x; }
int get_y() const { return y_; }
void set_y(int y) {
y_ = y;
}
void set_y(int y) { y_ = y; }
void add(const Point &other) {
this->x_ += other.x_;
@@ -48,12 +43,11 @@ static mrb_value point_native_div(mrb_state *mrb, mrb_value self) {
return self;
}
template<>
struct mrubypp_converter<Point> {
template <> struct mrubypp_converter<Point> {
static mrb_value to_mrb(mrb_state *mrb, const Point &var) {
mrb_value obj = mrb_obj_value(
mrb_data_object_alloc(mrb, mrb->object_class, new Point(var),
&mrubypp_class_builder<Point>::data_type));
mrb_data_object_alloc(mrb, mrb->object_class, new Point(var),
&mrubypp_class_builder<Point>::data_type));
return obj;
}
@@ -67,7 +61,7 @@ struct mrubypp_converter<Point> {
};
TEST_CASE("Point", "[class]") {
mrubypp engine;
engine engine;
engine.class_builder<Point>("Point")
.def_constructor<int, int>()
.def_method("add", &Point::add)

View File

@@ -7,10 +7,10 @@
#include <catch2/catch_all.hpp>
#include "mrubypp.h"
#include "engine.h"
TEST_CASE("none args call", "[engine]") {
mrubypp engine;
engine engine;
engine.load(R"(
def get_1()
1
@@ -22,7 +22,7 @@ TEST_CASE("none args call", "[engine]") {
}
TEST_CASE("args call", "[engine]") {
mrubypp engine;
engine engine;
engine.load(R"(
def sort_and_get_first(a)
a.sort!
@@ -36,7 +36,7 @@ TEST_CASE("args call", "[engine]") {
}
TEST_CASE("call benchmark", "[!benchmark]") {
mrubypp engine;
engine engine;
engine.load(R"(
def get_same(a)
return a