|
1 | 1 | #include <scratchcpp/broadcast.h> |
2 | 2 | #include <scratchcpp/block.h> |
| 3 | +#include <scratchcpp/project.h> |
3 | 4 | #include <scratchcpp/variable.h> |
4 | 5 | #include <scratchcpp/list.h> |
5 | 6 |
|
@@ -331,3 +332,48 @@ TEST(EngineTest, ListOwner) |
331 | 332 | ASSERT_EQ(engine.listOwner(list3.get()), t3.get()); |
332 | 333 | ASSERT_EQ(engine.listOwner(list4.get()), t1.get()); |
333 | 334 | } |
| 335 | + |
| 336 | +TEST(EngineTest, Clones) |
| 337 | +{ |
| 338 | + Project p("clones.sb3"); |
| 339 | + ASSERT_TRUE(p.load()); |
| 340 | + p.run(); |
| 341 | + |
| 342 | + auto engine = p.engine(); |
| 343 | + |
| 344 | + Target *stage = engine->targetAt(engine->findTarget("Stage")); |
| 345 | + ASSERT_TRUE(stage); |
| 346 | + |
| 347 | + ASSERT_VAR(stage, "clone1"); |
| 348 | + ASSERT_EQ(GET_VAR(stage, "clone1")->value().toInt(), 1); |
| 349 | + ASSERT_VAR(stage, "clone2"); |
| 350 | + ASSERT_EQ(GET_VAR(stage, "clone2")->value().toInt(), 1); |
| 351 | + ASSERT_VAR(stage, "clone3"); |
| 352 | + ASSERT_EQ(GET_VAR(stage, "clone3")->value().toInt(), 1); |
| 353 | + ASSERT_VAR(stage, "clone4"); |
| 354 | + ASSERT_EQ(GET_VAR(stage, "clone4")->value().toInt(), 1); |
| 355 | + ASSERT_VAR(stage, "clone5"); |
| 356 | + ASSERT_EQ(GET_VAR(stage, "clone5")->value().toInt(), 110); |
| 357 | + ASSERT_VAR(stage, "delete_passed"); |
| 358 | + ASSERT_TRUE(GET_VAR(stage, "delete_passed")->value().toBool()); |
| 359 | + |
| 360 | + ASSERT_LIST(stage, "log1"); |
| 361 | + auto list = GET_LIST(stage, "log1"); |
| 362 | + |
| 363 | + for (int i = 0; i < list->size(); i++) { |
| 364 | + if (i < 10) |
| 365 | + ASSERT_EQ((*list)[i].toInt(), 1); |
| 366 | + else |
| 367 | + ASSERT_EQ((*list)[i].toInt(), 2); |
| 368 | + } |
| 369 | + |
| 370 | + ASSERT_LIST(stage, "log2"); |
| 371 | + list = GET_LIST(stage, "log2"); |
| 372 | + |
| 373 | + for (int i = 0; i < list->size(); i++) { |
| 374 | + if (i < 10) |
| 375 | + ASSERT_EQ((*list)[i].toInt(), 1); |
| 376 | + else |
| 377 | + ASSERT_EQ((*list)[i].toString(), "1 2"); // TODO: Change this to "12" after #188 is fixed |
| 378 | + } |
| 379 | +} |
0 commit comments