rice 4.2.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +169 -162
- data/include/rice/rice.hpp +8762 -8672
- data/include/rice/stl.hpp +128 -10
- data/lib/version.rb +3 -3
- data/rice/Data_Object.ipp +386 -313
- data/rice/Data_Type.ipp +1 -0
- data/rice/Identifier.hpp +50 -50
- data/rice/Identifier.ipp +28 -28
- data/rice/detail/NativeFunction.hpp +119 -119
- data/rice/detail/NativeFunction.ipp +300 -300
- data/rice/detail/NativeIterator.hpp +1 -1
- data/rice/detail/NativeIterator.ipp +101 -101
- data/rice/detail/Wrapper.ipp +11 -1
- data/rice/stl.hpp +1 -0
- data/test/embed_ruby.cpp +2 -2
- data/test/test_Array.cpp +301 -301
- data/test/test_Iterator.cpp +356 -290
- data/test/test_Stl_SmartPointer.cpp +45 -2
- data/test/test_Stl_String_View.cpp +88 -0
- data/test/test_Stl_Unordered_Map.cpp +38 -34
- data/test/test_Stl_Vector.cpp +871 -811
- data/test/test_String.cpp +15 -0
- metadata +4 -3
data/test/test_Array.cpp
CHANGED
@@ -1,301 +1,301 @@
|
|
1
|
-
#include "unittest.hpp"
|
2
|
-
#include "embed_ruby.hpp"
|
3
|
-
#include <rice/rice.hpp>
|
4
|
-
|
5
|
-
#include <vector>
|
6
|
-
|
7
|
-
using namespace Rice;
|
8
|
-
|
9
|
-
TESTSUITE(Array);
|
10
|
-
|
11
|
-
namespace {
|
12
|
-
// This is needed to make unittest compile (it uses ostream to report errors)
|
13
|
-
template<typename T>
|
14
|
-
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vector) {
|
15
|
-
for (T &i: vector) {
|
16
|
-
os << i << ", ";
|
17
|
-
}
|
18
|
-
return os;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
SETUP(Array)
|
23
|
-
{
|
24
|
-
embed_ruby();
|
25
|
-
}
|
26
|
-
|
27
|
-
TESTCASE(default_construct)
|
28
|
-
{
|
29
|
-
Array a;
|
30
|
-
ASSERT_EQUAL(T_ARRAY, rb_type(a));
|
31
|
-
ASSERT_EQUAL(0, RARRAY_LEN(a.value()));
|
32
|
-
}
|
33
|
-
|
34
|
-
TESTCASE(construct_from_vector_of_int)
|
35
|
-
{
|
36
|
-
std::vector<int> v;
|
37
|
-
v.push_back(10);
|
38
|
-
v.push_back(6);
|
39
|
-
v.push_back(42);
|
40
|
-
Array a(v.begin(), v.end());
|
41
|
-
ASSERT_EQUAL(3, a.size());
|
42
|
-
ASSERT(rb_equal(detail::to_ruby(10), a[0].value()));
|
43
|
-
ASSERT(rb_equal(detail::to_ruby(6), a[1].value()));
|
44
|
-
ASSERT(rb_equal(detail::to_ruby(42), a[2].value()));
|
45
|
-
}
|
46
|
-
|
47
|
-
TESTCASE(construct_from_c_array)
|
48
|
-
{
|
49
|
-
int arr[] = { 10, 6, 42 };
|
50
|
-
Array a(arr);
|
51
|
-
ASSERT_EQUAL(3, a.size());
|
52
|
-
ASSERT(rb_equal(detail::to_ruby(10), a[0].value()));
|
53
|
-
ASSERT(rb_equal(detail::to_ruby(6), a[1].value()));
|
54
|
-
ASSERT(rb_equal(detail::to_ruby(42), a[2].value()));
|
55
|
-
}
|
56
|
-
|
57
|
-
TESTCASE(push_no_items)
|
58
|
-
{
|
59
|
-
Array a;
|
60
|
-
ASSERT_EQUAL(0, a.size());
|
61
|
-
}
|
62
|
-
|
63
|
-
TESTCASE(push_one_item)
|
64
|
-
{
|
65
|
-
Array a;
|
66
|
-
a.push(Rice::True);
|
67
|
-
ASSERT_EQUAL(1, a.size());
|
68
|
-
ASSERT_EQUAL(Qtrue, a[0]);
|
69
|
-
}
|
70
|
-
|
71
|
-
TESTCASE(push_two_items)
|
72
|
-
{
|
73
|
-
Array a;
|
74
|
-
a.push(42);
|
75
|
-
a.push(43);
|
76
|
-
ASSERT_EQUAL(2, a.size());
|
77
|
-
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
78
|
-
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
|
79
|
-
}
|
80
|
-
|
81
|
-
TESTCASE(push_three_items)
|
82
|
-
{
|
83
|
-
Array a;
|
84
|
-
a.push(42);
|
85
|
-
a.push(43);
|
86
|
-
a.push(44);
|
87
|
-
ASSERT_EQUAL(3, a.size());
|
88
|
-
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
89
|
-
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
|
90
|
-
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[2].value()));
|
91
|
-
}
|
92
|
-
|
93
|
-
TESTCASE(push_int)
|
94
|
-
{
|
95
|
-
Array a;
|
96
|
-
a.push(42);
|
97
|
-
ASSERT_EQUAL(1, a.size());
|
98
|
-
ASSERT(rb_equal(detail::to_ruby(42), a[0].value()));
|
99
|
-
}
|
100
|
-
|
101
|
-
TESTCASE(bracket_equals)
|
102
|
-
{
|
103
|
-
Array a;
|
104
|
-
a.push(42);
|
105
|
-
a.push(43);
|
106
|
-
a.push(44);
|
107
|
-
a[1] = 10;
|
108
|
-
ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[1].value()));
|
109
|
-
}
|
110
|
-
|
111
|
-
TESTCASE(to_s)
|
112
|
-
{
|
113
|
-
Array a;
|
114
|
-
a.push(42);
|
115
|
-
a.push(43);
|
116
|
-
a.push(44);
|
117
|
-
String s1(a.call("to_s"));
|
118
|
-
String s2(a.to_s());
|
119
|
-
ASSERT_EQUAL(s1.str(), s2.str());
|
120
|
-
}
|
121
|
-
|
122
|
-
TESTCASE(pop)
|
123
|
-
{
|
124
|
-
Array a;
|
125
|
-
a.push(42);
|
126
|
-
a.push(43);
|
127
|
-
a.push(44);
|
128
|
-
VALUE result = a.pop();
|
129
|
-
ASSERT_EQUAL(2, a.size());
|
130
|
-
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
131
|
-
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
|
132
|
-
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(result));
|
133
|
-
}
|
134
|
-
|
135
|
-
TESTCASE(unshift)
|
136
|
-
{
|
137
|
-
Array a;
|
138
|
-
a.push(42);
|
139
|
-
a.push(43);
|
140
|
-
a.push(44);
|
141
|
-
a.unshift(10);
|
142
|
-
ASSERT_EQUAL(4, a.size());
|
143
|
-
ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[0].value()));
|
144
|
-
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[1].value()));
|
145
|
-
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[2].value()));
|
146
|
-
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[3].value()));
|
147
|
-
}
|
148
|
-
|
149
|
-
TESTCASE(unshift_int)
|
150
|
-
{
|
151
|
-
Array a;
|
152
|
-
a.unshift(42);
|
153
|
-
ASSERT_EQUAL(1, a.size());
|
154
|
-
ASSERT(rb_equal(detail::to_ruby(42), a[0].value()));
|
155
|
-
}
|
156
|
-
|
157
|
-
TESTCASE(shift)
|
158
|
-
{
|
159
|
-
Array a;
|
160
|
-
a.push(42);
|
161
|
-
a.push(43);
|
162
|
-
a.push(44);
|
163
|
-
VALUE result = a.shift();
|
164
|
-
ASSERT_EQUAL(2, a.size());
|
165
|
-
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
166
|
-
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[0].value()));
|
167
|
-
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[1].value()));
|
168
|
-
}
|
169
|
-
|
170
|
-
TESTCASE(iterate)
|
171
|
-
{
|
172
|
-
Array a;
|
173
|
-
a.push(42);
|
174
|
-
a.push(43);
|
175
|
-
a.push(44);
|
176
|
-
int ca[] = { 42, 43, 44 };
|
177
|
-
Array::iterator it = a.begin();
|
178
|
-
Array::iterator end = a.end();
|
179
|
-
for(int j = 0; it != end; ++j, ++it)
|
180
|
-
{
|
181
|
-
ASSERT_EQUAL(ca[j], detail::From_Ruby<int>().convert(it->value()));
|
182
|
-
}
|
183
|
-
}
|
184
|
-
|
185
|
-
TESTCASE(const_iterate)
|
186
|
-
{
|
187
|
-
Array a;
|
188
|
-
a.push(42);
|
189
|
-
a.push(43);
|
190
|
-
a.push(44);
|
191
|
-
int ca[] = { 42, 43, 44 };
|
192
|
-
Array::const_iterator it = a.begin();
|
193
|
-
Array::const_iterator end = a.end();
|
194
|
-
for(int j = 0; it != end; ++j, ++it)
|
195
|
-
{
|
196
|
-
ASSERT_EQUAL(ca[j], detail::From_Ruby<int>().convert(*it));
|
197
|
-
}
|
198
|
-
}
|
199
|
-
|
200
|
-
TESTCASE(iterate_and_change)
|
201
|
-
{
|
202
|
-
Array a;
|
203
|
-
a.push(42);
|
204
|
-
a.push(43);
|
205
|
-
a.push(44);
|
206
|
-
Array::iterator it = a.begin();
|
207
|
-
Array::iterator end = a.end();
|
208
|
-
for(int j = 0; it != end; ++j, ++it)
|
209
|
-
{
|
210
|
-
int value = detail::From_Ruby<int>().convert(it->value());
|
211
|
-
*it = value + j;
|
212
|
-
}
|
213
|
-
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
214
|
-
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[1].value()));
|
215
|
-
ASSERT_EQUAL(46, detail::From_Ruby<int>().convert(a[2].value()));
|
216
|
-
}
|
217
|
-
|
218
|
-
TESTCASE(iterate_and_call_member)
|
219
|
-
{
|
220
|
-
Array a;
|
221
|
-
a.push(42);
|
222
|
-
a.push(43);
|
223
|
-
a.push(44);
|
224
|
-
Array::iterator it = a.begin();
|
225
|
-
Array::iterator end = a.end();
|
226
|
-
std::vector<Object> v;
|
227
|
-
for(int j = 0; it != end; ++j, ++it)
|
228
|
-
{
|
229
|
-
v.push_back(it->to_s());
|
230
|
-
}
|
231
|
-
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
232
|
-
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
|
233
|
-
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[2].value()));
|
234
|
-
ASSERT_EQUAL(3u, v.size());
|
235
|
-
ASSERT_EQUAL(Object(a[0]).to_s(), v[0]);
|
236
|
-
ASSERT_EQUAL(Object(a[1]).to_s(), v[1]);
|
237
|
-
ASSERT_EQUAL(Object(a[2]).to_s(), v[2]);
|
238
|
-
}
|
239
|
-
|
240
|
-
TESTCASE(find_if)
|
241
|
-
{
|
242
|
-
Array rubyValues;
|
243
|
-
rubyValues.push(42);
|
244
|
-
rubyValues.push(43);
|
245
|
-
rubyValues.push(44);
|
246
|
-
|
247
|
-
auto iter = std::find_if(rubyValues.begin(), rubyValues.end(),
|
248
|
-
[&rubyValues](const Object& object)
|
249
|
-
{
|
250
|
-
return object == rubyValues[1];
|
251
|
-
});
|
252
|
-
|
253
|
-
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(iter->value()));
|
254
|
-
}
|
255
|
-
|
256
|
-
TESTCASE(assign_int)
|
257
|
-
{
|
258
|
-
Array a;
|
259
|
-
a.push(42);
|
260
|
-
a[0] = 10;
|
261
|
-
ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[0].value()));
|
262
|
-
}
|
263
|
-
|
264
|
-
/**
|
265
|
-
* Issue 59 - Copy constructor compilation problem.
|
266
|
-
*/
|
267
|
-
|
268
|
-
namespace {
|
269
|
-
void testArrayArg(Object self, Array string) {
|
270
|
-
}
|
271
|
-
}
|
272
|
-
|
273
|
-
TESTCASE(use_array_in_wrapped_function) {
|
274
|
-
define_global_function("test_array_arg", &testArrayArg);
|
275
|
-
}
|
276
|
-
|
277
|
-
TESTCASE(array_to_ruby)
|
278
|
-
{
|
279
|
-
Array a(rb_ary_new());
|
280
|
-
ASSERT(rb_equal(a.value(), detail::to_ruby(a)));
|
281
|
-
}
|
282
|
-
|
283
|
-
TESTCASE(array_ref_to_ruby)
|
284
|
-
{
|
285
|
-
Array a(rb_ary_new());
|
286
|
-
Array& ref = a;
|
287
|
-
ASSERT(rb_equal(a.value(), detail::to_ruby(ref)));
|
288
|
-
}
|
289
|
-
|
290
|
-
TESTCASE(array_ptr_to_ruby)
|
291
|
-
{
|
292
|
-
Array a(rb_ary_new());
|
293
|
-
Array* ptr = &a;
|
294
|
-
ASSERT(rb_equal(a.value(), detail::to_ruby(ptr)));
|
295
|
-
}
|
296
|
-
|
297
|
-
TESTCASE(array_from_ruby)
|
298
|
-
{
|
299
|
-
Array a(rb_ary_new());
|
300
|
-
ASSERT_EQUAL(a, detail::From_Ruby<Array>().convert(a));
|
301
|
-
}
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
4
|
+
|
5
|
+
#include <vector>
|
6
|
+
|
7
|
+
using namespace Rice;
|
8
|
+
|
9
|
+
TESTSUITE(Array);
|
10
|
+
|
11
|
+
namespace {
|
12
|
+
// This is needed to make unittest compile (it uses ostream to report errors)
|
13
|
+
template<typename T>
|
14
|
+
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vector) {
|
15
|
+
for (T &i: vector) {
|
16
|
+
os << i << ", ";
|
17
|
+
}
|
18
|
+
return os;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
SETUP(Array)
|
23
|
+
{
|
24
|
+
embed_ruby();
|
25
|
+
}
|
26
|
+
|
27
|
+
TESTCASE(default_construct)
|
28
|
+
{
|
29
|
+
Array a;
|
30
|
+
ASSERT_EQUAL(T_ARRAY, rb_type(a));
|
31
|
+
ASSERT_EQUAL(0, RARRAY_LEN(a.value()));
|
32
|
+
}
|
33
|
+
|
34
|
+
TESTCASE(construct_from_vector_of_int)
|
35
|
+
{
|
36
|
+
std::vector<int> v;
|
37
|
+
v.push_back(10);
|
38
|
+
v.push_back(6);
|
39
|
+
v.push_back(42);
|
40
|
+
Array a(v.begin(), v.end());
|
41
|
+
ASSERT_EQUAL(3, a.size());
|
42
|
+
ASSERT(rb_equal(detail::to_ruby(10), a[0].value()));
|
43
|
+
ASSERT(rb_equal(detail::to_ruby(6), a[1].value()));
|
44
|
+
ASSERT(rb_equal(detail::to_ruby(42), a[2].value()));
|
45
|
+
}
|
46
|
+
|
47
|
+
TESTCASE(construct_from_c_array)
|
48
|
+
{
|
49
|
+
int arr[] = { 10, 6, 42 };
|
50
|
+
Array a(arr);
|
51
|
+
ASSERT_EQUAL(3, a.size());
|
52
|
+
ASSERT(rb_equal(detail::to_ruby(10), a[0].value()));
|
53
|
+
ASSERT(rb_equal(detail::to_ruby(6), a[1].value()));
|
54
|
+
ASSERT(rb_equal(detail::to_ruby(42), a[2].value()));
|
55
|
+
}
|
56
|
+
|
57
|
+
TESTCASE(push_no_items)
|
58
|
+
{
|
59
|
+
Array a;
|
60
|
+
ASSERT_EQUAL(0, a.size());
|
61
|
+
}
|
62
|
+
|
63
|
+
TESTCASE(push_one_item)
|
64
|
+
{
|
65
|
+
Array a;
|
66
|
+
a.push(Rice::True);
|
67
|
+
ASSERT_EQUAL(1, a.size());
|
68
|
+
ASSERT_EQUAL(Qtrue, a[0]);
|
69
|
+
}
|
70
|
+
|
71
|
+
TESTCASE(push_two_items)
|
72
|
+
{
|
73
|
+
Array a;
|
74
|
+
a.push(42);
|
75
|
+
a.push(43);
|
76
|
+
ASSERT_EQUAL(2, a.size());
|
77
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
78
|
+
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
|
79
|
+
}
|
80
|
+
|
81
|
+
TESTCASE(push_three_items)
|
82
|
+
{
|
83
|
+
Array a;
|
84
|
+
a.push(42);
|
85
|
+
a.push(43);
|
86
|
+
a.push(44);
|
87
|
+
ASSERT_EQUAL(3, a.size());
|
88
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
89
|
+
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
|
90
|
+
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[2].value()));
|
91
|
+
}
|
92
|
+
|
93
|
+
TESTCASE(push_int)
|
94
|
+
{
|
95
|
+
Array a;
|
96
|
+
a.push(42);
|
97
|
+
ASSERT_EQUAL(1, a.size());
|
98
|
+
ASSERT(rb_equal(detail::to_ruby(42), a[0].value()));
|
99
|
+
}
|
100
|
+
|
101
|
+
TESTCASE(bracket_equals)
|
102
|
+
{
|
103
|
+
Array a;
|
104
|
+
a.push(42);
|
105
|
+
a.push(43);
|
106
|
+
a.push(44);
|
107
|
+
a[1] = 10;
|
108
|
+
ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[1].value()));
|
109
|
+
}
|
110
|
+
|
111
|
+
TESTCASE(to_s)
|
112
|
+
{
|
113
|
+
Array a;
|
114
|
+
a.push(42);
|
115
|
+
a.push(43);
|
116
|
+
a.push(44);
|
117
|
+
String s1(a.call("to_s"));
|
118
|
+
String s2(a.to_s());
|
119
|
+
ASSERT_EQUAL(s1.str(), s2.str());
|
120
|
+
}
|
121
|
+
|
122
|
+
TESTCASE(pop)
|
123
|
+
{
|
124
|
+
Array a;
|
125
|
+
a.push(42);
|
126
|
+
a.push(43);
|
127
|
+
a.push(44);
|
128
|
+
VALUE result = a.pop();
|
129
|
+
ASSERT_EQUAL(2, a.size());
|
130
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
131
|
+
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
|
132
|
+
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(result));
|
133
|
+
}
|
134
|
+
|
135
|
+
TESTCASE(unshift)
|
136
|
+
{
|
137
|
+
Array a;
|
138
|
+
a.push(42);
|
139
|
+
a.push(43);
|
140
|
+
a.push(44);
|
141
|
+
a.unshift(10);
|
142
|
+
ASSERT_EQUAL(4, a.size());
|
143
|
+
ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[0].value()));
|
144
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[1].value()));
|
145
|
+
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[2].value()));
|
146
|
+
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[3].value()));
|
147
|
+
}
|
148
|
+
|
149
|
+
TESTCASE(unshift_int)
|
150
|
+
{
|
151
|
+
Array a;
|
152
|
+
a.unshift(42);
|
153
|
+
ASSERT_EQUAL(1, a.size());
|
154
|
+
ASSERT(rb_equal(detail::to_ruby(42), a[0].value()));
|
155
|
+
}
|
156
|
+
|
157
|
+
TESTCASE(shift)
|
158
|
+
{
|
159
|
+
Array a;
|
160
|
+
a.push(42);
|
161
|
+
a.push(43);
|
162
|
+
a.push(44);
|
163
|
+
VALUE result = a.shift();
|
164
|
+
ASSERT_EQUAL(2, a.size());
|
165
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
166
|
+
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[0].value()));
|
167
|
+
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[1].value()));
|
168
|
+
}
|
169
|
+
|
170
|
+
TESTCASE(iterate)
|
171
|
+
{
|
172
|
+
Array a;
|
173
|
+
a.push(42);
|
174
|
+
a.push(43);
|
175
|
+
a.push(44);
|
176
|
+
int ca[] = { 42, 43, 44 };
|
177
|
+
Array::iterator it = a.begin();
|
178
|
+
Array::iterator end = a.end();
|
179
|
+
for(int j = 0; it != end; ++j, ++it)
|
180
|
+
{
|
181
|
+
ASSERT_EQUAL(ca[j], detail::From_Ruby<int>().convert(it->value()));
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
TESTCASE(const_iterate)
|
186
|
+
{
|
187
|
+
Array a;
|
188
|
+
a.push(42);
|
189
|
+
a.push(43);
|
190
|
+
a.push(44);
|
191
|
+
int ca[] = { 42, 43, 44 };
|
192
|
+
Array::const_iterator it = a.begin();
|
193
|
+
Array::const_iterator end = a.end();
|
194
|
+
for(int j = 0; it != end; ++j, ++it)
|
195
|
+
{
|
196
|
+
ASSERT_EQUAL(ca[j], detail::From_Ruby<int>().convert(*it));
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
TESTCASE(iterate_and_change)
|
201
|
+
{
|
202
|
+
Array a;
|
203
|
+
a.push(42);
|
204
|
+
a.push(43);
|
205
|
+
a.push(44);
|
206
|
+
Array::iterator it = a.begin();
|
207
|
+
Array::iterator end = a.end();
|
208
|
+
for(int j = 0; it != end; ++j, ++it)
|
209
|
+
{
|
210
|
+
int value = detail::From_Ruby<int>().convert(it->value());
|
211
|
+
*it = value + j;
|
212
|
+
}
|
213
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
214
|
+
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[1].value()));
|
215
|
+
ASSERT_EQUAL(46, detail::From_Ruby<int>().convert(a[2].value()));
|
216
|
+
}
|
217
|
+
|
218
|
+
TESTCASE(iterate_and_call_member)
|
219
|
+
{
|
220
|
+
Array a;
|
221
|
+
a.push(42);
|
222
|
+
a.push(43);
|
223
|
+
a.push(44);
|
224
|
+
Array::iterator it = a.begin();
|
225
|
+
Array::iterator end = a.end();
|
226
|
+
std::vector<Object> v;
|
227
|
+
for(int j = 0; it != end; ++j, ++it)
|
228
|
+
{
|
229
|
+
v.push_back(it->to_s());
|
230
|
+
}
|
231
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
|
232
|
+
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
|
233
|
+
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(a[2].value()));
|
234
|
+
ASSERT_EQUAL(3u, v.size());
|
235
|
+
ASSERT_EQUAL(Object(a[0]).to_s(), v[0]);
|
236
|
+
ASSERT_EQUAL(Object(a[1]).to_s(), v[1]);
|
237
|
+
ASSERT_EQUAL(Object(a[2]).to_s(), v[2]);
|
238
|
+
}
|
239
|
+
|
240
|
+
TESTCASE(find_if)
|
241
|
+
{
|
242
|
+
Array rubyValues;
|
243
|
+
rubyValues.push(42);
|
244
|
+
rubyValues.push(43);
|
245
|
+
rubyValues.push(44);
|
246
|
+
|
247
|
+
auto iter = std::find_if(rubyValues.begin(), rubyValues.end(),
|
248
|
+
[&rubyValues](const Object& object)
|
249
|
+
{
|
250
|
+
return object == rubyValues[1];
|
251
|
+
});
|
252
|
+
|
253
|
+
ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(iter->value()));
|
254
|
+
}
|
255
|
+
|
256
|
+
TESTCASE(assign_int)
|
257
|
+
{
|
258
|
+
Array a;
|
259
|
+
a.push(42);
|
260
|
+
a[0] = 10;
|
261
|
+
ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[0].value()));
|
262
|
+
}
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Issue 59 - Copy constructor compilation problem.
|
266
|
+
*/
|
267
|
+
|
268
|
+
namespace {
|
269
|
+
void testArrayArg(Object self, Array string) {
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
TESTCASE(use_array_in_wrapped_function) {
|
274
|
+
define_global_function("test_array_arg", &testArrayArg);
|
275
|
+
}
|
276
|
+
|
277
|
+
TESTCASE(array_to_ruby)
|
278
|
+
{
|
279
|
+
Array a(rb_ary_new());
|
280
|
+
ASSERT(rb_equal(a.value(), detail::to_ruby(a)));
|
281
|
+
}
|
282
|
+
|
283
|
+
TESTCASE(array_ref_to_ruby)
|
284
|
+
{
|
285
|
+
Array a(rb_ary_new());
|
286
|
+
Array& ref = a;
|
287
|
+
ASSERT(rb_equal(a.value(), detail::to_ruby(ref)));
|
288
|
+
}
|
289
|
+
|
290
|
+
TESTCASE(array_ptr_to_ruby)
|
291
|
+
{
|
292
|
+
Array a(rb_ary_new());
|
293
|
+
Array* ptr = &a;
|
294
|
+
ASSERT(rb_equal(a.value(), detail::to_ruby(ptr)));
|
295
|
+
}
|
296
|
+
|
297
|
+
TESTCASE(array_from_ruby)
|
298
|
+
{
|
299
|
+
Array a(rb_ary_new());
|
300
|
+
ASSERT_EQUAL(a, detail::From_Ruby<Array>().convert(a));
|
301
|
+
}
|