Skip to content

Commit 2a913f8

Browse files
committed
Add BlockPrototype test
1 parent a2c35cb commit 2a913f8

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ include(GoogleTest)
1515
add_subdirectory(zip)
1616
add_subdirectory(load_project)
1717
add_subdirectory(compiler)
18+
add_subdirectory(scratch_classes)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_executable(
2+
blockprototype_test
3+
blockprototype_test.cpp
4+
)
5+
6+
target_link_libraries(
7+
blockprototype_test
8+
GTest::gtest_main
9+
scratchcpp
10+
)
11+
12+
gtest_discover_tests(blockprototype_test)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "scratch/blockprototype.h"
2+
#include "../common.h"
3+
4+
using namespace libscratchcpp;
5+
6+
TEST(BlockPrototypeTest, ProcCode)
7+
{
8+
BlockPrototype prototype("test block");
9+
ASSERT_EQ(prototype.procCode(), "test block");
10+
ASSERT_TRUE(prototype.argumentTypes().empty());
11+
ASSERT_TRUE(prototype.argumentDefaults().empty());
12+
13+
prototype.setProcCode("test %s block %s %b");
14+
ASSERT_EQ(prototype.procCode(), "test %s block %s %b");
15+
ASSERT_EQ(
16+
prototype.argumentTypes(),
17+
std::vector<BlockPrototype::ArgType>({
18+
BlockPrototype::ArgType::StringNum,
19+
BlockPrototype::ArgType::StringNum,
20+
BlockPrototype::ArgType::Bool,
21+
}));
22+
ASSERT_EQ(prototype.argumentDefaults(), std::vector<Value>({ "", "", false }));
23+
24+
prototype.setProcCode("%b %s test %b block %b");
25+
ASSERT_EQ(prototype.procCode(), "%b %s test %b block %b");
26+
ASSERT_EQ(
27+
prototype.argumentTypes(),
28+
std::vector<BlockPrototype::ArgType>({ BlockPrototype::ArgType::Bool, BlockPrototype::ArgType::StringNum, BlockPrototype::ArgType::Bool, BlockPrototype::ArgType::Bool }));
29+
ASSERT_EQ(prototype.argumentDefaults(), std::vector<Value>({ false, "", false, false }));
30+
}

0 commit comments

Comments
 (0)