Skip to content

Commit 65ba720

Browse files
authored
Merge pull request #199 from scratchcpp/port_142
Port the fix for #142
2 parents 9a6c0e7 + f0d5ae5 commit 65ba720

File tree

4 files changed

+375
-5
lines changed

4 files changed

+375
-5
lines changed

include/scratchcpp/value.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,18 +443,20 @@ class LIBSCRATCHCPP_EXPORT Value : public ValueVariant
443443
}
444444
}
445445
} else {
446-
if (v1.isNumber() || v2.isNumber())
446+
if (v1.isString() || v2.isString())
447+
return stringsEqual(v1.toUtf16(), v2.toUtf16());
448+
else if (v1.isNumber() || v2.isNumber())
447449
return v1.toDouble() == v2.toDouble();
448450
else if (v1.isBool() || v2.isBool())
449451
return ((v1.m_type != Type::NaN && v2.m_type != Type::NaN) && (v1.toBool() == v2.toBool()));
450-
else if (v1.isString() || v2.isString())
451-
return stringsEqual(v1.toUtf16(), v2.toUtf16());
452452
else
453453
return false;
454454
}
455455
return false;
456456
}
457457

458+
friend bool operator!=(const Value &v1, const Value &v2) { return !(v1 == v2); }
459+
458460
friend bool operator>(const Value &v1, const Value &v2)
459461
{
460462
if ((static_cast<int>(v1.m_type) < 0) || (static_cast<int>(v2.m_type) < 0)) {

test/load_project/load_project_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ TEST(LoadProjectTest, LoadTestProject)
191191
ASSERT_EQ(prototype->argumentIds().size(), 2);
192192
ASSERT_EQ(prototype->argumentNames(), std::vector<std::string>({ "num or text", "bool" }));
193193
ASSERT_EQ(prototype->argumentTypes(), std::vector<BlockPrototype::ArgType>({ BlockPrototype::ArgType::StringNum, BlockPrototype::ArgType::Bool }));
194-
ASSERT_EQ(prototype->argumentDefaults(), std::vector<Value>({ 0, false }));
194+
ASSERT_EQ(prototype->argumentDefaults(), std::vector<Value>({ "", false }));
195195
ASSERT_EQ(prototype->procCode(), "custom block %s %b");
196196
ASSERT_INPUT(blockPrototype, prototype->argumentIds()[0]);
197197
auto argBlock = GET_INPUT(blockPrototype, prototype->argumentIds()[0])->valueBlock();

0 commit comments

Comments
 (0)