Skip to content

Commit 4ee628a

Browse files
committed
Implement operator_not
1 parent 6e1db6e commit 4ee628a

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/dev/blocks/operatorblocks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void OperatorBlocks::registerBlocks(IEngine *engine)
3030
engine->addCompileFunction(this, "operator_gt", &compileGt);
3131
engine->addCompileFunction(this, "operator_and", &compileAnd);
3232
engine->addCompileFunction(this, "operator_or", &compileOr);
33+
engine->addCompileFunction(this, "operator_not", &compileNot);
3334
}
3435

3536
CompilerValue *OperatorBlocks::compileAdd(Compiler *compiler)
@@ -83,3 +84,8 @@ CompilerValue *OperatorBlocks::compileOr(Compiler *compiler)
8384
{
8485
return compiler->createOr(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
8586
}
87+
88+
CompilerValue *OperatorBlocks::compileNot(Compiler *compiler)
89+
{
90+
return compiler->createNot(compiler->addInput("OPERAND"));
91+
}

src/dev/blocks/operatorblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class OperatorBlocks : public IExtension
2828
static CompilerValue *compileGt(Compiler *compiler);
2929
static CompilerValue *compileAnd(Compiler *compiler);
3030
static CompilerValue *compileOr(Compiler *compiler);
31+
static CompilerValue *compileNot(Compiler *compiler);
3132
};
3233

3334
} // namespace libscratchcpp

test/dev/blocks/operator_blocks_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,26 @@ TEST_F(OperatorBlocksTest, Or)
330330
ASSERT_EQ(Value(values[2]), true);
331331
ASSERT_EQ(Value(values[3]), true);
332332
}
333+
334+
TEST_F(OperatorBlocksTest, Not)
335+
{
336+
auto target = std::make_shared<Sprite>();
337+
ScriptBuilder builder(m_extension.get(), m_engine, target);
338+
339+
builder.addBlock("operator_not");
340+
builder.addValueInput("OPERAND", false);
341+
builder.captureBlockReturnValue();
342+
343+
builder.addBlock("operator_not");
344+
builder.addValueInput("OPERAND", true);
345+
builder.captureBlockReturnValue();
346+
347+
builder.build();
348+
builder.run();
349+
350+
List *valueList = builder.capturedValues();
351+
ValueData *values = valueList->data();
352+
ASSERT_EQ(valueList->size(), 2);
353+
ASSERT_EQ(Value(values[0]), true);
354+
ASSERT_EQ(Value(values[1]), false);
355+
}

0 commit comments

Comments
 (0)