comparison C++/tests/Js/main.cpp @ 415:ac4573b9bb4b

Js: add js::Pointer for non-managed pointers
author David Demelier <markand@malikania.fr>
date Thu, 08 Oct 2015 08:29:48 +0200
parents 2a0b8613498f
children 865224c2191a
comparison
equal deleted inserted replaced
414:0b6f7f7c8a6c 415:ac4573b9bb4b
135 ASSERT_EQ(1, array[0]); 135 ASSERT_EQ(1, array[0]);
136 ASSERT_EQ(2, array[1]); 136 ASSERT_EQ(2, array[1]);
137 ASSERT_EQ(3, array[2]); 137 ASSERT_EQ(3, array[2]);
138 } 138 }
139 139
140 TEST(PushAndGet, pointer)
141 {
142 Context context;
143
144 ASSERT_EQ(0, context.top());
145 context.push(Pointer<int>{new int(1)});
146 ASSERT_EQ(1, *context.get<Pointer<int>>(-1));
147 ASSERT_EQ(1, context.top());
148 }
149
140 /* -------------------------------------------------------- 150 /* --------------------------------------------------------
141 * Require 151 * Require
142 * -------------------------------------------------------- */ 152 * -------------------------------------------------------- */
143 153
144 TEST(Require, boolean) 154 TEST(Require, boolean)
244 } 254 }
245 255
246 ASSERT_EQ(0, context.top()); 256 ASSERT_EQ(0, context.top());
247 } 257 }
248 258
259 TEST(Require, pointer)
260 {
261 Context context;
262
263 ASSERT_EQ(0, context.top());
264
265 try {
266 context.push(Function{[] (Context &ctx) -> int {
267 ctx.require<Pointer<int>>(0);
268
269 return 0;
270 }});
271 context.peval();
272
273 FAIL() << "exception expected";
274 } catch (...) {
275 }
276
277 ASSERT_EQ(0, context.top());
278 }
279
249 /* -------------------------------------------------------- 280 /* --------------------------------------------------------
250 * Is 281 * Is
251 * -------------------------------------------------------- */ 282 * -------------------------------------------------------- */
252 283
253 TEST(Is, boolean) 284 TEST(Is, boolean)
338 context.push(Array{}); 369 context.push(Array{});
339 ASSERT_TRUE(context.is<Array>(-1)); 370 ASSERT_TRUE(context.is<Array>(-1));
340 ASSERT_EQ(1, context.top()); 371 ASSERT_EQ(1, context.top());
341 } 372 }
342 373
374 TEST(Is, pointer)
375 {
376 Context context;
377
378 ASSERT_EQ(0, context.top());
379 context.push(Pointer<int>{new int(1)});
380 ASSERT_TRUE(context.is<Pointer<int>>(-1));
381 ASSERT_EQ(1, context.top());
382 }
383
343 /* -------------------------------------------------------- 384 /* --------------------------------------------------------
344 * Optional 385 * Optional
345 * -------------------------------------------------------- */ 386 * -------------------------------------------------------- */
346 387
347 TEST(Optional, boolean) 388 TEST(Optional, boolean)
389 Context context; 430 Context context;
390 431
391 ASSERT_EQ(0, context.top()); 432 ASSERT_EQ(0, context.top());
392 ASSERT_STREQ("no", context.optional<const char *>(0, "no")); 433 ASSERT_STREQ("no", context.optional<const char *>(0, "no"));
393 ASSERT_STREQ("yes", context.optional<const char *>(0, "yes")); 434 ASSERT_STREQ("yes", context.optional<const char *>(0, "yes"));
435 ASSERT_EQ(0, context.top());
436 }
437
438 TEST(Optional, pointer)
439 {
440 Context context;
441
442 ASSERT_EQ(0, context.top());
443 ASSERT_EQ(nullptr, context.optional<js::Pointer<int>>(0, js::Pointer<int>{nullptr}));
394 ASSERT_EQ(0, context.top()); 444 ASSERT_EQ(0, context.top());
395 } 445 }
396 446
397 /* -------------------------------------------------------- 447 /* --------------------------------------------------------
398 * Basics 448 * Basics