Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/scratchcpp/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class LIBSCRATCHCPP_EXPORT Variable : public Entity
{
public:
Variable(const std::string &id, const std::string &name, const Value &value = Value(), bool isCloudVariable = false);
Variable(const std::string &id, const std::string &name, bool isCloudVariable);
Variable(const Variable &) = delete;

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

void add(const Value &v);

private:
spimpl::unique_impl_ptr<VariablePrivate> impl;
};
Expand Down
12 changes: 0 additions & 12 deletions src/scratch/variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ Variable::Variable(const std::string &id, const std::string &name, const Value &
{
}

/*! Constructs an empty Variable. */
Variable::Variable(const std::string &id, const std::string &name, bool isCloudVariable) :
Variable(id, name, Value(), isCloudVariable)
{
}

/*! Returns the name of the variable. */
const std::string &Variable::name() const
{
Expand Down Expand Up @@ -54,9 +48,3 @@ void Variable::setIsCloudVariable(bool isCloudVariable)
{
impl->isCloudVariable = isCloudVariable;
}

/*! Adds the given value to the variable's value. \see Value::add() */
void Variable::add(const Value &v)
{
impl->value.add(v);
}
14 changes: 14 additions & 0 deletions test/scratch_classes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,17 @@ target_link_libraries(
)

gtest_discover_tests(block_test)

# variable_test
add_executable(
variable_test
variable_test.cpp
)

target_link_libraries(
variable_test
GTest::gtest_main
scratchcpp
)

gtest_discover_tests(variable_test)
58 changes: 58 additions & 0 deletions test/scratch_classes/variable_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <scratchcpp/variable.h>

#include "../common.h"

using namespace libscratchcpp;

TEST(VariableTest, Constructors)
{
Variable var1("abc", "var1");
ASSERT_EQ(var1.id(), "abc");
ASSERT_EQ(var1.name(), "var1");
ASSERT_EQ(var1.value(), Value());
ASSERT_FALSE(var1.isCloudVariable());

Variable var2("abc", "var2", "test");
ASSERT_EQ(var2.id(), "abc");
ASSERT_EQ(var2.name(), "var2");
ASSERT_EQ(var2.value().toString(), "test");
ASSERT_FALSE(var2.isCloudVariable());

Variable var3("abc", "var3", "test", true);
ASSERT_EQ(var3.id(), "abc");
ASSERT_EQ(var3.name(), "var3");
ASSERT_EQ(var3.value().toString(), "test");
ASSERT_TRUE(var3.isCloudVariable());

Variable var4("abc", "var4", "test", false);
ASSERT_EQ(var4.id(), "abc");
ASSERT_EQ(var4.name(), "var4");
ASSERT_EQ(var4.value().toString(), "test");
ASSERT_FALSE(var4.isCloudVariable());
}

TEST(VariableTest, Value)
{
Variable var("", "");

var.setValue("hello");
ASSERT_EQ(var.value().toString(), "hello");
}

TEST(VariableTest, ValuePtr)
{
Variable var("", "");
ASSERT_TRUE(var.valuePtr());
ASSERT_EQ(*var.valuePtr(), Value());

var.setValue("Hello, world!");
ASSERT_EQ(var.valuePtr()->toString(), "Hello, world!");
}

TEST(VariableTest, IsCloudVariable)
{
Variable var("", "");

var.setIsCloudVariable(true);
ASSERT_TRUE(var.isCloudVariable());
}