Skip to content

Commit f2bf692

Browse files
committed
Add support for To_Ruby<T&> for types missing it - this is driven by supporting rvalues in Object#call and in Constructor.
1 parent e58f0d0 commit f2bf692

6 files changed

Lines changed: 51 additions & 2 deletions

File tree

test/test_Proc.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ TESTCASE(SquareProc)
5959
ASSERT_EQUAL(81, detail::From_Ruby<int>().convert(result));
6060
}
6161

62+
TESTCASE(SquareProcLvalueToRuby)
63+
{
64+
auto proc = square;
65+
using To_Ruby_T = detail::remove_cv_recursive_t<decltype((proc))>;
66+
67+
VALUE value = detail::To_Ruby<To_Ruby_T>().convert(proc);
68+
Object result(value);
69+
ASSERT_EQUAL(81, detail::From_Ruby<int>().convert(result.call("call", 9)));
70+
}
71+
6272
TESTCASE(SquareWithBlock)
6373
{
6474
Module m = define_module("TestingModuleMakeBlock");
@@ -97,4 +107,4 @@ TESTCASE(SquareWithProc)
97107

98108
Object result = m.module_eval(code);
99109
ASSERT_EQUAL(16, detail::From_Ruby<int>().convert(result));
100-
}
110+
}

test/test_Reference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ TESTCASE(double_reference_object)
117117
TESTCASE(float_reference_object)
118118
{
119119
Module m = define_module("Testing");
120-
120+
define_reference<float>();
121121
std::string code = R"(ref = Rice::Reference≺float≻.new(1.25)
122122
ref.value)";
123123
Object result = m.module_eval(code);

test/test_Stl_Optional.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ TESTCASE(OptionalReturn)
6767
ASSERT(result.is_nil());
6868
}
6969

70+
TESTCASE(NulloptToRubyReference)
71+
{
72+
const std::nullopt_t& nullopt = std::nullopt;
73+
using To_Ruby_T = detail::remove_cv_recursive_t<decltype((nullopt))>;
74+
75+
VALUE result = detail::To_Ruby<To_Ruby_T>().convert(nullopt);
76+
ASSERT_EQUAL(Qnil, result);
77+
}
78+
7079
TESTCASE(OptionalArgument)
7180
{
7281
Module m = define_module("Testing");

test/test_Stl_Reference_Wrapper.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ TESTCASE(Return)
7575
ASSERT_EQUAL("A ref wrapped string", detail::From_Ruby<std::string>().convert(result));
7676
}
7777

78+
TESTCASE(LvalueToRuby)
79+
{
80+
MyClass instance;
81+
std::reference_wrapper<MyClass> wrapper = std::ref(instance);
82+
const std::reference_wrapper<MyClass>& ref = wrapper;
83+
using To_Ruby_T = detail::remove_cv_recursive_t<decltype((ref))>;
84+
85+
VALUE result = detail::To_Ruby<To_Ruby_T>().convert(ref);
86+
ASSERT_EQUAL(&instance, detail::unwrap<MyClass>(result, Data_Type<MyClass>::ruby_data_type(), false));
87+
}
88+
7889
TESTCASE(Argument)
7990
{
8091
Module m = define_module("Testing");

test/test_Stl_Vector.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ TESTCASE(StringVectorData)
8383
ASSERT_EQUAL("World", detail::From_Ruby<std::string>().convert(array[1].value()).c_str());
8484
}
8585

86+
TESTCASE(VectorBoolReferenceLvalueToRuby)
87+
{
88+
std::vector<bool> values{ true };
89+
auto reference = values[0];
90+
const auto& ref = reference;
91+
using To_Ruby_T = detail::remove_cv_recursive_t<decltype((ref))>;
92+
93+
VALUE result = detail::To_Ruby<To_Ruby_T>().convert(ref);
94+
ASSERT_EQUAL(Qtrue, result);
95+
}
96+
8697
TESTCASE(Constructors)
8798
{
8899
Module m = define_module("Testing");

test/test_To_Ruby.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ TESTCASE(object_to_ruby)
2626
ASSERT_EQUAL(o.value(), detail::to_ruby(o));
2727
}
2828

29+
TESTCASE(nullptr_lvalue_to_ruby)
30+
{
31+
const std::nullptr_t& value = nullptr;
32+
using To_Ruby_T = detail::remove_cv_recursive_t<decltype((value))>;
33+
34+
ASSERT_EQUAL(Qnil, detail::To_Ruby<To_Ruby_T>().convert(value));
35+
}
36+
2937
TESTCASE(short_to_ruby)
3038
{
3139
#undef min

0 commit comments

Comments
 (0)