Skip to content

Commit 6e1db6e

Browse files
committed
Implement operator_or
1 parent 1ce8e6f commit 6e1db6e

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/dev/blocks/operatorblocks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void OperatorBlocks::registerBlocks(IEngine *engine)
2929
engine->addCompileFunction(this, "operator_equals", &compileEquals);
3030
engine->addCompileFunction(this, "operator_gt", &compileGt);
3131
engine->addCompileFunction(this, "operator_and", &compileAnd);
32+
engine->addCompileFunction(this, "operator_or", &compileOr);
3233
}
3334

3435
CompilerValue *OperatorBlocks::compileAdd(Compiler *compiler)
@@ -77,3 +78,8 @@ CompilerValue *OperatorBlocks::compileAnd(Compiler *compiler)
7778
{
7879
return compiler->createAnd(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
7980
}
81+
82+
CompilerValue *OperatorBlocks::compileOr(Compiler *compiler)
83+
{
84+
return compiler->createOr(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
85+
}

src/dev/blocks/operatorblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class OperatorBlocks : public IExtension
2727
static CompilerValue *compileEquals(Compiler *compiler);
2828
static CompilerValue *compileGt(Compiler *compiler);
2929
static CompilerValue *compileAnd(Compiler *compiler);
30+
static CompilerValue *compileOr(Compiler *compiler);
3031
};
3132

3233
} // namespace libscratchcpp

test/dev/blocks/operator_blocks_test.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,40 @@ TEST_F(OperatorBlocksTest, And)
293293
ASSERT_EQ(Value(values[2]), false);
294294
ASSERT_EQ(Value(values[3]), true);
295295
}
296+
297+
TEST_F(OperatorBlocksTest, Or)
298+
{
299+
auto target = std::make_shared<Sprite>();
300+
ScriptBuilder builder(m_extension.get(), m_engine, target);
301+
302+
builder.addBlock("operator_or");
303+
builder.addValueInput("OPERAND1", false);
304+
builder.addValueInput("OPERAND2", false);
305+
builder.captureBlockReturnValue();
306+
307+
builder.addBlock("operator_or");
308+
builder.addValueInput("OPERAND1", true);
309+
builder.addValueInput("OPERAND2", false);
310+
builder.captureBlockReturnValue();
311+
312+
builder.addBlock("operator_or");
313+
builder.addValueInput("OPERAND1", false);
314+
builder.addValueInput("OPERAND2", true);
315+
builder.captureBlockReturnValue();
316+
317+
builder.addBlock("operator_or");
318+
builder.addValueInput("OPERAND1", true);
319+
builder.addValueInput("OPERAND2", true);
320+
builder.captureBlockReturnValue();
321+
322+
builder.build();
323+
builder.run();
324+
325+
List *valueList = builder.capturedValues();
326+
ValueData *values = valueList->data();
327+
ASSERT_EQ(valueList->size(), 4);
328+
ASSERT_EQ(Value(values[0]), false);
329+
ASSERT_EQ(Value(values[1]), true);
330+
ASSERT_EQ(Value(values[2]), true);
331+
ASSERT_EQ(Value(values[3]), true);
332+
}

0 commit comments

Comments
 (0)