Skip to content

Commit c03ad04

Browse files
authored
Merge pull request #171 from scratchcpp/variable_test
Add Variable test
2 parents 56fc4e4 + e98d348 commit c03ad04

File tree

4 files changed

+72
-15
lines changed

4 files changed

+72
-15
lines changed

include/scratchcpp/variable.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class LIBSCRATCHCPP_EXPORT Variable : public Entity
1616
{
1717
public:
1818
Variable(const std::string &id, const std::string &name, const Value &value = Value(), bool isCloudVariable = false);
19-
Variable(const std::string &id, const std::string &name, bool isCloudVariable);
2019
Variable(const Variable &) = delete;
2120

2221
const std::string &name() const;
@@ -30,8 +29,6 @@ class LIBSCRATCHCPP_EXPORT Variable : public Entity
3029
bool isCloudVariable() const;
3130
void setIsCloudVariable(bool isCloudVariable);
3231

33-
void add(const Value &v);
34-
3532
private:
3633
spimpl::unique_impl_ptr<VariablePrivate> impl;
3734
};

src/scratch/variable.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ Variable::Variable(const std::string &id, const std::string &name, const Value &
1313
{
1414
}
1515

16-
/*! Constructs an empty Variable. */
17-
Variable::Variable(const std::string &id, const std::string &name, bool isCloudVariable) :
18-
Variable(id, name, Value(), isCloudVariable)
19-
{
20-
}
21-
2216
/*! Returns the name of the variable. */
2317
const std::string &Variable::name() const
2418
{
@@ -54,9 +48,3 @@ void Variable::setIsCloudVariable(bool isCloudVariable)
5448
{
5549
impl->isCloudVariable = isCloudVariable;
5650
}
57-
58-
/*! Adds the given value to the variable's value. \see Value::add() */
59-
void Variable::add(const Value &v)
60-
{
61-
impl->value.add(v);
62-
}

test/scratch_classes/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,17 @@ target_link_libraries(
169169
)
170170

171171
gtest_discover_tests(block_test)
172+
173+
# variable_test
174+
add_executable(
175+
variable_test
176+
variable_test.cpp
177+
)
178+
179+
target_link_libraries(
180+
variable_test
181+
GTest::gtest_main
182+
scratchcpp
183+
)
184+
185+
gtest_discover_tests(variable_test)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <scratchcpp/variable.h>
2+
3+
#include "../common.h"
4+
5+
using namespace libscratchcpp;
6+
7+
TEST(VariableTest, Constructors)
8+
{
9+
Variable var1("abc", "var1");
10+
ASSERT_EQ(var1.id(), "abc");
11+
ASSERT_EQ(var1.name(), "var1");
12+
ASSERT_EQ(var1.value(), Value());
13+
ASSERT_FALSE(var1.isCloudVariable());
14+
15+
Variable var2("abc", "var2", "test");
16+
ASSERT_EQ(var2.id(), "abc");
17+
ASSERT_EQ(var2.name(), "var2");
18+
ASSERT_EQ(var2.value().toString(), "test");
19+
ASSERT_FALSE(var2.isCloudVariable());
20+
21+
Variable var3("abc", "var3", "test", true);
22+
ASSERT_EQ(var3.id(), "abc");
23+
ASSERT_EQ(var3.name(), "var3");
24+
ASSERT_EQ(var3.value().toString(), "test");
25+
ASSERT_TRUE(var3.isCloudVariable());
26+
27+
Variable var4("abc", "var4", "test", false);
28+
ASSERT_EQ(var4.id(), "abc");
29+
ASSERT_EQ(var4.name(), "var4");
30+
ASSERT_EQ(var4.value().toString(), "test");
31+
ASSERT_FALSE(var4.isCloudVariable());
32+
}
33+
34+
TEST(VariableTest, Value)
35+
{
36+
Variable var("", "");
37+
38+
var.setValue("hello");
39+
ASSERT_EQ(var.value().toString(), "hello");
40+
}
41+
42+
TEST(VariableTest, ValuePtr)
43+
{
44+
Variable var("", "");
45+
ASSERT_TRUE(var.valuePtr());
46+
ASSERT_EQ(*var.valuePtr(), Value());
47+
48+
var.setValue("Hello, world!");
49+
ASSERT_EQ(var.valuePtr()->toString(), "Hello, world!");
50+
}
51+
52+
TEST(VariableTest, IsCloudVariable)
53+
{
54+
Variable var("", "");
55+
56+
var.setIsCloudVariable(true);
57+
ASSERT_TRUE(var.isCloudVariable());
58+
}

0 commit comments

Comments
 (0)