Skip to content

Commit

Permalink
#401: test constructing some cmd::Argument types
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Jul 19, 2022
1 parent b899bf7 commit 1824db7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/icommandsystem.h
Expand Up @@ -25,7 +25,13 @@ enum ArgumentTypeFlags
ARGTYPE_OPTIONAL = 1 << 16,
};

// One command argument, provides several getter methods
/**
* @brief A single command argument which may be of several different types.
*
* The argument maintains a list of type flags which indicate which types this argument may be
* interpreted as. For example, an argument constructed from an integer may also be interpreted as
* a double, so will have both ARGTYPE_INT and ARGTYPE_DOUBLE.
*/
class Argument
{
std::string _strValue;
Expand Down
43 changes: 43 additions & 0 deletions test/CommandSystem.cpp
Expand Up @@ -5,6 +5,49 @@ namespace test

using CommandSystemTest = RadiantTest;

TEST_F(CommandSystemTest, ConstructVoidArg)
{
cmd::Argument voidArg;

EXPECT_EQ(voidArg.getType(), cmd::ARGTYPE_VOID);
EXPECT_EQ(voidArg.getInt(), 0);
EXPECT_EQ(voidArg.getDouble(), 0);
EXPECT_EQ(voidArg.getString(), "");
}

TEST_F(CommandSystemTest, ConstructIntArg)
{
cmd::Argument intArg(357);

EXPECT_EQ(intArg.getType(), cmd::ARGTYPE_INT | cmd::ARGTYPE_DOUBLE);
EXPECT_EQ(intArg.getInt(), 357);
EXPECT_EQ(intArg.getDouble(), 357.0);
EXPECT_EQ(intArg.getString(), "357");
}

TEST_F(CommandSystemTest, ConstructStringArg)
{
cmd::Argument stringArg("arbitrary string");

EXPECT_EQ(stringArg.getType(), cmd::ARGTYPE_STRING);
EXPECT_EQ(stringArg.getString(), "arbitrary string");

// String should be interpreted as numeric if possible
cmd::Argument intStringArg("81924");
EXPECT_EQ(intStringArg.getType(),
cmd::ARGTYPE_STRING | cmd::ARGTYPE_INT | cmd::ARGTYPE_DOUBLE);
EXPECT_EQ(intStringArg.getDouble(), 81924.0);
EXPECT_EQ(intStringArg.getInt(), 81924);
EXPECT_EQ(intStringArg.getString(), "81924");
}

TEST_F(CommandSystemTest, ConstructVectorArg)
{
cmd::Argument v2Arg(Vector2(123, -8.6));
EXPECT_EQ(v2Arg.getType(), cmd::ARGTYPE_VECTOR2);
EXPECT_EQ(v2Arg.getVector2(), Vector2(123, -8.6));
}

TEST_F(CommandSystemTest, GetCommandSystem)
{
const auto& mod = GlobalCommandSystem();
Expand Down

0 comments on commit 1824db7

Please sign in to comment.