Skip to content

Commit be9846a

Browse files
committed
Use case sensitive string comparison in list blocks
1 parent 61c4496 commit be9846a

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/dev/blocks/listblocks.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ CompilerValue *ListBlocks::getListIndex(Compiler *compiler, CompilerValue *input
4848
{
4949
CompilerLocalVariable *ret = compiler->createLocalVariable(Compiler::StaticType::Number);
5050

51-
CompilerValue *isRandom1 = compiler->createCmpEQ(input, compiler->addConstValue("random"));
52-
CompilerValue *isRandom2 = compiler->createCmpEQ(input, compiler->addConstValue("any"));
51+
CompilerValue *isRandom1 = compiler->createStrCmpEQ(input, compiler->addConstValue("random"), true);
52+
CompilerValue *isRandom2 = compiler->createStrCmpEQ(input, compiler->addConstValue("any"), true);
5353
CompilerValue *isRandom = compiler->createOr(isRandom1, isRandom2);
5454

5555
compiler->beginIfStatement(isRandom);
@@ -59,7 +59,7 @@ CompilerValue *ListBlocks::getListIndex(Compiler *compiler, CompilerValue *input
5959
}
6060
compiler->beginElseBranch();
6161
{
62-
CompilerValue *isLast = compiler->createCmpEQ(input, compiler->addConstValue("last"));
62+
CompilerValue *isLast = compiler->createStrCmpEQ(input, compiler->addConstValue("last"), true);
6363
compiler->createLocalVariableWrite(ret, compiler->createSelect(isLast, listSize, input, Compiler::StaticType::Number));
6464
}
6565
compiler->endIf();
@@ -74,7 +74,7 @@ CompilerValue *ListBlocks::compileDeleteOfList(Compiler *compiler)
7474

7575
if (list) {
7676
CompilerValue *index = compiler->addInput("INDEX");
77-
CompilerValue *cond = compiler->createCmpEQ(index, compiler->addConstValue("all"));
77+
CompilerValue *cond = compiler->createStrCmpEQ(index, compiler->addConstValue("all"), true);
7878
compiler->beginIfStatement(cond);
7979
{
8080
compiler->createListClear(list);

test/dev/blocks/list_blocks_test.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ TEST_F(ListBlocksTest, DeleteOfList)
121121

122122
addTest("all", list3);
123123

124+
addTest("Last", list2);
125+
addTest("raNdom", list2);
126+
addTest("aNY", list2);
127+
128+
addTest("aLl", list3);
129+
124130
builder.build();
125131

126132
Compiler compiler(&m_engineMock, target.get());
@@ -200,6 +206,10 @@ TEST_F(ListBlocksTest, InsertAtList)
200206
addTest("random", "ipsum", list2);
201207
addTest("any", "dolor", list2);
202208

209+
addTest("lAsT", "lorem", list2);
210+
addTest("raNDom", "ipsum", list2);
211+
addTest("Any", "dolor", list2);
212+
203213
builder.build();
204214

205215
Compiler compiler(&m_engineMock, target.get());
@@ -257,6 +267,10 @@ TEST_F(ListBlocksTest, ReplaceItemOfList)
257267
addTest("random", "ipsum", list2);
258268
addTest("any", "dolor", list2);
259269

270+
addTest("LasT", "lorem", list2);
271+
addTest("rAndOm", "ipsum", list2);
272+
addTest("AnY", "dolor", list2);
273+
260274
builder.build();
261275

262276
Compiler compiler(&m_engineMock, target.get());
@@ -311,6 +325,10 @@ TEST_F(ListBlocksTest, ItemOfList)
311325
addTest("random", list);
312326
addTest("any", list);
313327

328+
addTest("laSt", list);
329+
addTest("RAndom", list);
330+
addTest("aNy", list);
331+
314332
builder.build();
315333

316334
Compiler compiler(&m_engineMock, target.get());
@@ -328,7 +346,10 @@ TEST_F(ListBlocksTest, ItemOfList)
328346
"0\n"
329347
"true\n"
330348
"123\n"
331-
"Lorem\n";
349+
"Lorem\n"
350+
"0\n"
351+
"0\n"
352+
"0\n";
332353

333354
EXPECT_CALL(m_rng, randint(1, 5)).WillOnce(Return(4)).WillOnce(Return(1));
334355
testing::internal::CaptureStdout();

0 commit comments

Comments
 (0)