Renamed Hazelnupp class in code to CmdArgsInterface

This commit is contained in:
Leonetienne 2021-06-08 14:00:20 +02:00
parent 8f5253a1ed
commit 4382254218
11 changed files with 461 additions and 461 deletions

View File

@ -1,4 +1,4 @@
#include "Hazelnupp.h"
#include "CmdArgsInterface.h"
#include "VoidValue.h"
#include "IntValue.h"
#include "FloatValue.h"
@ -12,18 +12,18 @@
using namespace Hazelnp;
Hazelnupp::Hazelnupp()
CmdArgsInterface::CmdArgsInterface()
{
return;
}
Hazelnupp::Hazelnupp(const int argc, const char* const* argv)
CmdArgsInterface::CmdArgsInterface(const int argc, const char* const* argv)
{
Parse(argc, argv);
return;
}
Hazelnupp::~Hazelnupp()
CmdArgsInterface::~CmdArgsInterface()
{
for (auto& it : parameters)
delete it.second;
@ -33,7 +33,7 @@ Hazelnupp::~Hazelnupp()
return;
}
void Hazelnupp::Parse(const int argc, const char* const* argv)
void CmdArgsInterface::Parse(const int argc, const char* const* argv)
{
try
{
@ -98,7 +98,7 @@ void Hazelnupp::Parse(const int argc, const char* const* argv)
return;
}
std::size_t Hazelnupp::ParseNextParameter(const std::size_t parIndex, Parameter*& out_Par)
std::size_t CmdArgsInterface::ParseNextParameter(const std::size_t parIndex, Parameter*& out_Par)
{
std::size_t i = parIndex;
const std::string key = rawArgs[parIndex];
@ -131,7 +131,7 @@ std::size_t Hazelnupp::ParseNextParameter(const std::size_t parIndex, Parameter*
return i;
}
void Hazelnupp::PopulateRawArgs(const int argc, const char* const* argv)
void CmdArgsInterface::PopulateRawArgs(const int argc, const char* const* argv)
{
rawArgs.clear();
rawArgs.reserve(argc);
@ -142,7 +142,7 @@ void Hazelnupp::PopulateRawArgs(const int argc, const char* const* argv)
return;
}
void Hazelnupp::ExpandAbbreviations()
void CmdArgsInterface::ExpandAbbreviations()
{
// Abort if no abbreviations
if (parameterAbreviations.size() == 0)
@ -162,12 +162,12 @@ void Hazelnupp::ExpandAbbreviations()
return;
}
bool Hazelnupp::HasParam(const std::string& key) const
bool CmdArgsInterface::HasParam(const std::string& key) const
{
return parameters.find(key) != parameters.end();
}
Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const ParamConstraint* constraint)
Value* CmdArgsInterface::ParseValue(const std::vector<std::string>& values, const ParamConstraint* constraint)
{
// This is the raw (unconverted) data type the user provided
DATA_TYPE rawInputType;
@ -326,40 +326,40 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
return nullptr;
}
bool Hazelnupp::GetCrashOnFail() const
bool CmdArgsInterface::GetCrashOnFail() const
{
return crashOnFail;
}
void Hazelnupp::SetCatchHelp(bool catchHelp)
void CmdArgsInterface::SetCatchHelp(bool catchHelp)
{
this->catchHelp = catchHelp;
return;
}
bool Hazelnupp::GetCatchHelp() const
bool CmdArgsInterface::GetCatchHelp() const
{
return catchHelp;
}
void Hazelnupp::SetBriefDescription(const std::string& description)
void CmdArgsInterface::SetBriefDescription(const std::string& description)
{
briefDescription = description;
return;
}
const std::string& Hazelnupp::GetBriefDescription()
const std::string& CmdArgsInterface::GetBriefDescription()
{
return briefDescription;
}
void Hazelnp::Hazelnupp::RegisterDescription(const std::string& parameter, const std::string& description)
void Hazelnp::CmdArgsInterface::RegisterDescription(const std::string& parameter, const std::string& description)
{
parameterDescriptions[parameter] = description;
return;
}
const std::string& Hazelnp::Hazelnupp::GetDescription(const std::string& parameter) const
const std::string& Hazelnp::CmdArgsInterface::GetDescription(const std::string& parameter) const
{
// Do we already have a description for this parameter?
if (!HasDescription(parameter))
@ -370,25 +370,25 @@ const std::string& Hazelnp::Hazelnupp::GetDescription(const std::string& paramet
return parameterDescriptions.find(parameter)->second;
}
bool Hazelnupp::HasDescription(const std::string& parameter) const
bool CmdArgsInterface::HasDescription(const std::string& parameter) const
{
return parameterDescriptions.find(parameter) != parameterDescriptions.end();
}
void Hazelnupp::ClearDescription(const std::string& parameter)
void CmdArgsInterface::ClearDescription(const std::string& parameter)
{
// This will just do nothing if the entry does not exist
parameterDescriptions.erase(parameter);
return;
}
void Hazelnp::Hazelnupp::ClearDescriptions()
void Hazelnp::CmdArgsInterface::ClearDescriptions()
{
parameterDescriptions.clear();
return;
}
std::string Hazelnupp::GenerateDocumentation() const
std::string CmdArgsInterface::GenerateDocumentation() const
{
std::stringstream ss;
@ -502,7 +502,7 @@ std::string Hazelnupp::GenerateDocumentation() const
return ss.str();
}
void Hazelnupp::ApplyConstraints()
void CmdArgsInterface::ApplyConstraints()
{
// Enforce required parameters / default values
for (const auto& pc : parameterConstraints)
@ -539,23 +539,23 @@ void Hazelnupp::ApplyConstraints()
return;
}
ParamConstraint Hazelnupp::GetConstraint(const std::string& parameter) const
ParamConstraint CmdArgsInterface::GetConstraint(const std::string& parameter) const
{
return parameterConstraints.find(parameter)->second;
}
void Hazelnupp::ClearConstraint(const std::string& parameter)
void CmdArgsInterface::ClearConstraint(const std::string& parameter)
{
parameterConstraints.erase(parameter);
return;
}
const std::string& Hazelnupp::GetExecutableName() const
const std::string& CmdArgsInterface::GetExecutableName() const
{
return executableName;
}
const Value& Hazelnupp::operator[](const std::string& key) const
const Value& CmdArgsInterface::operator[](const std::string& key) const
{
// Throw exception if param is unknown
if (!HasParam(key))
@ -564,13 +564,13 @@ const Value& Hazelnupp::operator[](const std::string& key) const
return *parameters.find(key)->second->GetValue();
}
void Hazelnupp::RegisterAbbreviation(const std::string& abbrev, const std::string& target)
void CmdArgsInterface::RegisterAbbreviation(const std::string& abbrev, const std::string& target)
{
parameterAbreviations.insert(std::pair<std::string, std::string>(abbrev, target));
return;
}
const std::string& Hazelnupp::GetAbbreviation(const std::string& abbrev) const
const std::string& CmdArgsInterface::GetAbbreviation(const std::string& abbrev) const
{
if (!HasAbbreviation(abbrev))
return Placeholders::g_emptyString;
@ -578,43 +578,43 @@ const std::string& Hazelnupp::GetAbbreviation(const std::string& abbrev) const
return parameterAbreviations.find(abbrev)->second;
}
bool Hazelnupp::HasAbbreviation(const std::string& abbrev) const
bool CmdArgsInterface::HasAbbreviation(const std::string& abbrev) const
{
return parameterAbreviations.find(abbrev) != parameterAbreviations.end();
}
void Hazelnupp::ClearAbbreviation(const std::string& abbrevation)
void CmdArgsInterface::ClearAbbreviation(const std::string& abbrevation)
{
parameterAbreviations.erase(abbrevation);
return;
}
void Hazelnupp::ClearAbbreviations()
void CmdArgsInterface::ClearAbbreviations()
{
parameterAbreviations.clear();
return;
}
void Hazelnupp::RegisterConstraint(const std::string& key, const ParamConstraint& constraint)
void CmdArgsInterface::RegisterConstraint(const std::string& key, const ParamConstraint& constraint)
{
// Magic syntax, wooo
(parameterConstraints[key] = constraint).key = key;
return;
}
void Hazelnupp::ClearConstraints()
void CmdArgsInterface::ClearConstraints()
{
parameterConstraints.clear();
return;
}
void Hazelnupp::SetCrashOnFail(bool crashOnFail)
void CmdArgsInterface::SetCrashOnFail(bool crashOnFail)
{
this->crashOnFail = crashOnFail;
return;
}
const ParamConstraint* Hazelnupp::GetConstraintForKey(const std::string& key) const
const ParamConstraint* CmdArgsInterface::GetConstraintForKey(const std::string& key) const
{
const auto constraint = parameterConstraints.find(key);

View File

@ -8,13 +8,13 @@ namespace Hazelnp
{
/** The main class to interface with
*/
class Hazelnupp
class CmdArgsInterface
{
public:
Hazelnupp();
Hazelnupp(const int argc, const char* const* argv);
CmdArgsInterface();
CmdArgsInterface(const int argc, const char* const* argv);
~Hazelnupp();
~CmdArgsInterface();
//! Will parse command line arguments
void Parse(const int argc, const char* const* argv);
@ -67,10 +67,10 @@ namespace Hazelnp
//! Gets whether the application crashes on an exception whilst parsing, and prints to stderr.
bool GetCrashOnFail() const;
//! Sets whether the Hazelnupp should automatically catch the --help parameter, print the parameter documentation to stdout, and exit or not.
//! Sets whether the CmdArgsInterface should automatically catch the --help parameter, print the parameter documentation to stdout, and exit or not.
void SetCatchHelp(bool catchHelp);
//! Retruns whether the Hazelnupp should automatically catch the --help parameter, print the parameter documentation to stdout, and exit or not.
//! Retruns whether the CmdArgsInterface should automatically catch the --help parameter, print the parameter documentation to stdout, and exit or not.
bool GetCatchHelp() const;
//! Sets a brief description of the application to be automatically added to the documentation.
@ -137,10 +137,10 @@ namespace Hazelnp
//! A brief description of the application to be added to the generated documentation. Optional.
std::string briefDescription;
//! If set to true, Hazelnupp will automatically catch the --help parameter, print the parameter documentation to stdout and exit.
//! If set to true, CmdArgsInterface will automatically catch the --help parameter, print the parameter documentation to stdout and exit.
bool catchHelp = true;
//! If set to true, Hazelnupp will crash the application with output to stderr when an exception is thrown whilst parsing.
//! If set to true, CmdArgsInterface will crash the application with output to stderr when an exception is thrown whilst parsing.
bool crashOnFail = true;
};
}

View File

@ -140,7 +140,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="FloatValue.cpp" />
<ClCompile Include="Hazelnupp.cpp" />
<ClCompile Include="CmdArgsInterface.cpp" />
<ClCompile Include="IntValue.cpp" />
<ClCompile Include="ListValue.cpp" />
<ClCompile Include="Parameter.cpp" />
@ -151,7 +151,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="FloatValue.h" />
<ClInclude Include="Hazelnupp.h" />
<ClInclude Include="CmdArgsInterface.h" />
<ClInclude Include="HazelnuppException.h" />
<ClInclude Include="IntValue.h" />
<ClInclude Include="ListValue.h" />

View File

@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Hazelnupp.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="Parameter.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
@ -42,11 +39,11 @@
<ClCompile Include="StringTools.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="CmdArgsInterface.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Hazelnupp.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="Parameter.h">
<Filter>Headerdateien</Filter>
</ClInclude>
@ -83,5 +80,8 @@
<ClInclude Include="Placeholders.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="CmdArgsInterface.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -64,6 +64,6 @@ namespace Hazelnp
//! This value is automatically set by Hazelnupp.
std::string key;
friend class Hazelnupp;
friend class CmdArgsInterface;
};
}

View File

@ -1,31 +1,31 @@
#include <iostream>
#include "../Hazelnupp/Hazelnupp.h"
#include "../Hazelnupp/CmdArgsInterface.h"
using namespace Hazelnp;
int main(int argc, char** argv)
{
Hazelnupp nupp;
CmdArgsInterface args;
nupp.SetBriefDescription("This is the testing application for Hazelnupp.");
args.SetBriefDescription("This is the testing application for Hazelnupp.");
nupp.RegisterDescription("--help", "This will display the parameter documentation.");
nupp.RegisterDescription("--force", "Just forces it.");
nupp.RegisterDescription("--width", "The width of something...");
nupp.RegisterDescription("--name", "The names to target");
nupp.RegisterDescription("--fruit", "The fruit to use");
args.RegisterDescription("--help", "This will display the parameter documentation.");
args.RegisterDescription("--force", "Just forces it.");
args.RegisterDescription("--width", "The width of something...");
args.RegisterDescription("--name", "The names to target");
args.RegisterDescription("--fruit", "The fruit to use");
nupp.RegisterAbbreviation("-f", "--force");
nupp.RegisterAbbreviation("-w", "--width");
nupp.RegisterAbbreviation("-h", "--height");
nupp.RegisterAbbreviation("-d", "--depth");
args.RegisterAbbreviation("-f", "--force");
args.RegisterAbbreviation("-w", "--width");
args.RegisterAbbreviation("-h", "--height");
args.RegisterAbbreviation("-d", "--depth");
nupp.RegisterConstraint("--width", ParamConstraint::TypeSafety(DATA_TYPE::FLOAT));
nupp.RegisterConstraint("--depth", ParamConstraint::TypeSafety(DATA_TYPE::FLOAT));
nupp.RegisterConstraint("--name", ParamConstraint(true, DATA_TYPE::LIST, { "peter", "hannes" }, true));
nupp.RegisterConstraint("--fruit", ParamConstraint(true, DATA_TYPE::STRING, {}, true));
args.RegisterConstraint("--width", ParamConstraint::TypeSafety(DATA_TYPE::FLOAT));
args.RegisterConstraint("--depth", ParamConstraint::TypeSafety(DATA_TYPE::FLOAT));
args.RegisterConstraint("--name", ParamConstraint(true, DATA_TYPE::LIST, { "peter", "hannes" }, true));
args.RegisterConstraint("--fruit", ParamConstraint(true, DATA_TYPE::STRING, {}, true));
nupp.Parse(argc, argv);
args.Parse(argc, argv);
return 0;
}

View File

@ -1,6 +1,6 @@
#include "CppUnitTest.h"
#include "helper.h"
#include "../Hazelnupp/Hazelnupp.h"
#include "../Hazelnupp/CmdArgsInterface.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Hazelnp;
@ -36,25 +36,25 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterAbbreviation("-ms", "--my_string");
nupp.RegisterAbbreviation("-mv", "--my_void");
nupp.RegisterAbbreviation("-mi", "--my_int");
nupp.RegisterAbbreviation("-mf", "--my_float");
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
nupp.RegisterAbbreviation("-msl", "--my_str_list");
cmdArgsI.RegisterAbbreviation("-ms", "--my_string");
cmdArgsI.RegisterAbbreviation("-mv", "--my_void");
cmdArgsI.RegisterAbbreviation("-mi", "--my_int");
cmdArgsI.RegisterAbbreviation("-mf", "--my_float");
cmdArgsI.RegisterAbbreviation("-mnl", "--my_num_list");
cmdArgsI.RegisterAbbreviation("-msl", "--my_str_list");
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp.HasParam("--my_string"));
Assert::IsTrue(nupp.HasParam("--my_void"));
Assert::IsTrue(nupp.HasParam("--my_float"));
Assert::IsTrue(nupp.HasParam("--my_int"));
Assert::IsTrue(nupp.HasParam("--my_num_list"));
Assert::IsTrue(nupp.HasParam("--my_str_list"));
Assert::IsTrue(cmdArgsI.HasParam("--my_string"));
Assert::IsTrue(cmdArgsI.HasParam("--my_void"));
Assert::IsTrue(cmdArgsI.HasParam("--my_float"));
Assert::IsTrue(cmdArgsI.HasParam("--my_int"));
Assert::IsTrue(cmdArgsI.HasParam("--my_num_list"));
Assert::IsTrue(cmdArgsI.HasParam("--my_str_list"));
return;
}
@ -84,25 +84,25 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterAbbreviation("-ms", "--my_string");
nupp.RegisterAbbreviation("-mv", "--my_void");
nupp.RegisterAbbreviation("-mi", "--my_int");
nupp.RegisterAbbreviation("-mf", "--my_float");
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
nupp.RegisterAbbreviation("-msl", "--my_str_list");
cmdArgsI.RegisterAbbreviation("-ms", "--my_string");
cmdArgsI.RegisterAbbreviation("-mv", "--my_void");
cmdArgsI.RegisterAbbreviation("-mi", "--my_int");
cmdArgsI.RegisterAbbreviation("-mf", "--my_float");
cmdArgsI.RegisterAbbreviation("-mnl", "--my_num_list");
cmdArgsI.RegisterAbbreviation("-msl", "--my_str_list");
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp["--my_string"].GetDataType() == DATA_TYPE::STRING);
Assert::IsTrue(nupp["--my_void"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(nupp["--my_float"].GetDataType() == DATA_TYPE::FLOAT);
Assert::IsTrue(nupp["--my_int"].GetDataType() == DATA_TYPE::INT);
Assert::IsTrue(nupp["--my_num_list"].GetDataType() == DATA_TYPE::LIST);
Assert::IsTrue(nupp["--my_str_list"].GetDataType() == DATA_TYPE::LIST);
Assert::IsTrue(cmdArgsI["--my_string"].GetDataType() == DATA_TYPE::STRING);
Assert::IsTrue(cmdArgsI["--my_void"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(cmdArgsI["--my_float"].GetDataType() == DATA_TYPE::FLOAT);
Assert::IsTrue(cmdArgsI["--my_int"].GetDataType() == DATA_TYPE::INT);
Assert::IsTrue(cmdArgsI["--my_num_list"].GetDataType() == DATA_TYPE::LIST);
Assert::IsTrue(cmdArgsI["--my_str_list"].GetDataType() == DATA_TYPE::LIST);
return;
}
@ -132,29 +132,29 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterAbbreviation("-ms", "--my_string");
nupp.RegisterAbbreviation("-mv", "--my_void");
nupp.RegisterAbbreviation("-mi", "--my_int");
nupp.RegisterAbbreviation("-mf", "--my_float");
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
nupp.RegisterAbbreviation("-msl", "--my_str_list");
cmdArgsI.RegisterAbbreviation("-ms", "--my_string");
cmdArgsI.RegisterAbbreviation("-mv", "--my_void");
cmdArgsI.RegisterAbbreviation("-mi", "--my_int");
cmdArgsI.RegisterAbbreviation("-mf", "--my_float");
cmdArgsI.RegisterAbbreviation("-mnl", "--my_num_list");
cmdArgsI.RegisterAbbreviation("-msl", "--my_str_list");
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::AreEqual(nupp["--my_string"].GetString(), std::string("billybob"));
Assert::AreEqual(nupp["--my_float"].GetFloat32(), -23.199);
Assert::AreEqual(nupp["--my_int"].GetInt32(), 199);
Assert::AreEqual(nupp["--my_num_list"].GetList()[0]->GetInt32(), 1);
Assert::AreEqual(nupp["--my_num_list"].GetList()[1]->GetInt32(), 2);
Assert::AreEqual(nupp["--my_num_list"].GetList()[2]->GetInt32(), 3);
Assert::AreEqual(nupp["--my_num_list"].GetList()[3]->GetInt32(), 4);
Assert::AreEqual(nupp["--my_str_list"].GetList()[0]->GetString(), std::string("apple"));
Assert::AreEqual(nupp["--my_str_list"].GetList()[1]->GetString(), std::string("banana"));
Assert::AreEqual(nupp["--my_str_list"].GetList()[2]->GetString(), std::string("pumpkin"));
Assert::AreEqual(cmdArgsI["--my_string"].GetString(), std::string("billybob"));
Assert::AreEqual(cmdArgsI["--my_float"].GetFloat32(), -23.199);
Assert::AreEqual(cmdArgsI["--my_int"].GetInt32(), 199);
Assert::AreEqual(cmdArgsI["--my_num_list"].GetList()[0]->GetInt32(), 1);
Assert::AreEqual(cmdArgsI["--my_num_list"].GetList()[1]->GetInt32(), 2);
Assert::AreEqual(cmdArgsI["--my_num_list"].GetList()[2]->GetInt32(), 3);
Assert::AreEqual(cmdArgsI["--my_num_list"].GetList()[3]->GetInt32(), 4);
Assert::AreEqual(cmdArgsI["--my_str_list"].GetList()[0]->GetString(), std::string("apple"));
Assert::AreEqual(cmdArgsI["--my_str_list"].GetList()[1]->GetString(), std::string("banana"));
Assert::AreEqual(cmdArgsI["--my_str_list"].GetList()[2]->GetString(), std::string("pumpkin"));
return;
}
@ -163,19 +163,19 @@ namespace TestHazelnupp
TEST_METHOD(Get_Abbreviation)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterAbbreviation("-ms", "--my_string");
nupp.RegisterAbbreviation("-mv", "--my_void");
nupp.RegisterAbbreviation("-mi", "--my_int");
nupp.RegisterAbbreviation("-mf", "--my_float");
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
nupp.RegisterAbbreviation("-msl", "--my_str_list");
cmdArgsI.RegisterAbbreviation("-ms", "--my_string");
cmdArgsI.RegisterAbbreviation("-mv", "--my_void");
cmdArgsI.RegisterAbbreviation("-mi", "--my_int");
cmdArgsI.RegisterAbbreviation("-mf", "--my_float");
cmdArgsI.RegisterAbbreviation("-mnl", "--my_num_list");
cmdArgsI.RegisterAbbreviation("-msl", "--my_str_list");
// Exercise, verify
Assert::AreEqual(std::string("--my_num_list"), nupp.GetAbbreviation("-mnl"));
Assert::AreEqual(std::string("--my_void"), nupp.GetAbbreviation("-mv"));
Assert::AreEqual(std::string("--my_num_list"), cmdArgsI.GetAbbreviation("-mnl"));
Assert::AreEqual(std::string("--my_void"), cmdArgsI.GetAbbreviation("-mv"));
return;
}
@ -184,21 +184,21 @@ namespace TestHazelnupp
TEST_METHOD(Unknown_Abbrevation_Is_Empty_String)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterAbbreviation("-ms", "--my_string");
nupp.RegisterAbbreviation("-mv", "--my_void");
nupp.RegisterAbbreviation("-mi", "--my_int");
nupp.RegisterAbbreviation("-mf", "--my_float");
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
nupp.RegisterAbbreviation("-msl", "--my_str_list");
cmdArgsI.RegisterAbbreviation("-ms", "--my_string");
cmdArgsI.RegisterAbbreviation("-mv", "--my_void");
cmdArgsI.RegisterAbbreviation("-mi", "--my_int");
cmdArgsI.RegisterAbbreviation("-mf", "--my_float");
cmdArgsI.RegisterAbbreviation("-mnl", "--my_num_list");
cmdArgsI.RegisterAbbreviation("-msl", "--my_str_list");
// Exercise
nupp.ClearAbbreviations();
cmdArgsI.ClearAbbreviations();
// Verify
Assert::AreEqual(std::string(), nupp.GetAbbreviation("-t"));
Assert::AreEqual(std::string(), cmdArgsI.GetAbbreviation("-t"));
return;
}
@ -207,17 +207,17 @@ namespace TestHazelnupp
TEST_METHOD(Has_Abbreviation)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
// Exercise, verify
Assert::IsFalse(nupp.HasAbbreviation("-f"));
Assert::IsFalse(nupp.HasAbbreviation("-m"));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-f"));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-m"));
nupp.RegisterAbbreviation("-f", "--force");
cmdArgsI.RegisterAbbreviation("-f", "--force");
Assert::IsTrue(nupp.HasAbbreviation("-f"));
Assert::IsFalse(nupp.HasAbbreviation("-m"));
Assert::IsTrue(cmdArgsI.HasAbbreviation("-f"));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-m"));
return;
}
@ -226,28 +226,28 @@ namespace TestHazelnupp
TEST_METHOD(Clear_Abbreviation)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterAbbreviation("-ms", "--my_string");
nupp.RegisterAbbreviation("-mv", "--my_void");
nupp.RegisterAbbreviation("-mi", "--my_int");
nupp.RegisterAbbreviation("-mf", "--my_float");
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
nupp.RegisterAbbreviation("-msl", "--my_str_list");
cmdArgsI.RegisterAbbreviation("-ms", "--my_string");
cmdArgsI.RegisterAbbreviation("-mv", "--my_void");
cmdArgsI.RegisterAbbreviation("-mi", "--my_int");
cmdArgsI.RegisterAbbreviation("-mf", "--my_float");
cmdArgsI.RegisterAbbreviation("-mnl", "--my_num_list");
cmdArgsI.RegisterAbbreviation("-msl", "--my_str_list");
// Exercise
nupp.ClearAbbreviation("-mv");
nupp.ClearAbbreviation("-mf");
nupp.ClearAbbreviation("-msl");
cmdArgsI.ClearAbbreviation("-mv");
cmdArgsI.ClearAbbreviation("-mf");
cmdArgsI.ClearAbbreviation("-msl");
// Verify
Assert::IsTrue(nupp.HasAbbreviation("-ms"));
Assert::IsFalse(nupp.HasAbbreviation("-mv"));
Assert::IsTrue(nupp.HasAbbreviation("-mi"));
Assert::IsFalse(nupp.HasAbbreviation("-mf"));
Assert::IsTrue(nupp.HasAbbreviation("-mnl"));
Assert::IsFalse(nupp.HasAbbreviation("-msl"));
Assert::IsTrue(cmdArgsI.HasAbbreviation("-ms"));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-mv"));
Assert::IsTrue(cmdArgsI.HasAbbreviation("-mi"));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-mf"));
Assert::IsTrue(cmdArgsI.HasAbbreviation("-mnl"));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-msl"));
return;
}
@ -256,26 +256,26 @@ namespace TestHazelnupp
TEST_METHOD(Clear_Abbreviations)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterAbbreviation("-ms" , "--my_string");
nupp.RegisterAbbreviation("-mv" , "--my_void");
nupp.RegisterAbbreviation("-mi" , "--my_int");
nupp.RegisterAbbreviation("-mf" , "--my_float");
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
nupp.RegisterAbbreviation("-msl", "--my_str_list");
cmdArgsI.RegisterAbbreviation("-ms" , "--my_string");
cmdArgsI.RegisterAbbreviation("-mv" , "--my_void");
cmdArgsI.RegisterAbbreviation("-mi" , "--my_int");
cmdArgsI.RegisterAbbreviation("-mf" , "--my_float");
cmdArgsI.RegisterAbbreviation("-mnl", "--my_num_list");
cmdArgsI.RegisterAbbreviation("-msl", "--my_str_list");
// Exercise
nupp.ClearAbbreviations();
cmdArgsI.ClearAbbreviations();
// Verify
Assert::IsFalse(nupp.HasAbbreviation("-ms" ));
Assert::IsFalse(nupp.HasAbbreviation("-mv" ));
Assert::IsFalse(nupp.HasAbbreviation("-mi" ));
Assert::IsFalse(nupp.HasAbbreviation("-mf" ));
Assert::IsFalse(nupp.HasAbbreviation("-mnl"));
Assert::IsFalse(nupp.HasAbbreviation("-msl"));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-ms" ));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-mv" ));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-mi" ));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-mf" ));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-mnl"));
Assert::IsFalse(cmdArgsI.HasAbbreviation("-msl"));
return;
}

View File

@ -1,6 +1,6 @@
#include "CppUnitTest.h"
#include "helper.h"
#include "../Hazelnupp/Hazelnupp.h"
#include "../Hazelnupp/CmdArgsInterface.h"
#include "../Hazelnupp/HazelnuppException.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
@ -21,11 +21,11 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
Assert::AreEqual(std::string("/my/fake/path/wahoo.out"), nupp.GetExecutableName());
Assert::AreEqual(std::string("/my/fake/path/wahoo.out"), cmdArgsI.GetExecutableName());
return;
}
@ -40,11 +40,11 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
Assert::IsTrue(nupp.HasParam("--dummy"));
Assert::IsTrue(cmdArgsI.HasParam("--dummy"));
return;
}
@ -59,8 +59,8 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify (no exception)
@ -78,12 +78,12 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
Assert::IsTrue(nupp.HasParam("--dummy"), L"Failed has-param");
Assert::IsTrue(nupp["--dummy"].GetDataType() == DATA_TYPE::VOID, L"Failed type");
Assert::IsTrue(cmdArgsI.HasParam("--dummy"), L"Failed has-param");
Assert::IsTrue(cmdArgsI["--dummy"].GetDataType() == DATA_TYPE::VOID, L"Failed type");
return;
}
@ -113,16 +113,16 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
Assert::IsTrue(nupp.HasParam("--my_string"));
Assert::IsTrue(nupp.HasParam("--my_void"));
Assert::IsTrue(nupp.HasParam("--my_float"));
Assert::IsTrue(nupp.HasParam("--my_int"));
Assert::IsTrue(nupp.HasParam("--my_num_list"));
Assert::IsTrue(nupp.HasParam("--my_str_list"));
Assert::IsTrue(cmdArgsI.HasParam("--my_string"));
Assert::IsTrue(cmdArgsI.HasParam("--my_void"));
Assert::IsTrue(cmdArgsI.HasParam("--my_float"));
Assert::IsTrue(cmdArgsI.HasParam("--my_int"));
Assert::IsTrue(cmdArgsI.HasParam("--my_num_list"));
Assert::IsTrue(cmdArgsI.HasParam("--my_str_list"));
return;
}
@ -152,16 +152,16 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
Assert::IsTrue(nupp["--my_string"].GetDataType() == DATA_TYPE::STRING);
Assert::IsTrue(nupp["--my_void"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(nupp["--my_float"].GetDataType() == DATA_TYPE::FLOAT);
Assert::IsTrue(nupp["--my_int"].GetDataType() == DATA_TYPE::INT);
Assert::IsTrue(nupp["--my_num_list"].GetDataType() == DATA_TYPE::LIST);
Assert::IsTrue(nupp["--my_str_list"].GetDataType() == DATA_TYPE::LIST);
Assert::IsTrue(cmdArgsI["--my_string"].GetDataType() == DATA_TYPE::STRING);
Assert::IsTrue(cmdArgsI["--my_void"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(cmdArgsI["--my_float"].GetDataType() == DATA_TYPE::FLOAT);
Assert::IsTrue(cmdArgsI["--my_int"].GetDataType() == DATA_TYPE::INT);
Assert::IsTrue(cmdArgsI["--my_num_list"].GetDataType() == DATA_TYPE::LIST);
Assert::IsTrue(cmdArgsI["--my_str_list"].GetDataType() == DATA_TYPE::LIST);
return;
}
@ -191,20 +191,20 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
Assert::AreEqual(nupp["--my_string"].GetString(), std::string("billybob"));
Assert::AreEqual(nupp["--my_float"].GetFloat32(), -23.199);
Assert::AreEqual(nupp["--my_int"].GetInt32(), 199);
Assert::AreEqual(nupp["--my_num_list"].GetList()[0]->GetInt32(), 1);
Assert::AreEqual(nupp["--my_num_list"].GetList()[1]->GetInt32(), 2);
Assert::AreEqual(nupp["--my_num_list"].GetList()[2]->GetInt32(), 3);
Assert::AreEqual(nupp["--my_num_list"].GetList()[3]->GetInt32(), 4);
Assert::AreEqual(nupp["--my_str_list"].GetList()[0]->GetString(), std::string("apple"));
Assert::AreEqual(nupp["--my_str_list"].GetList()[1]->GetString(), std::string("banana"));
Assert::AreEqual(nupp["--my_str_list"].GetList()[2]->GetString(), std::string("pumpkin"));
Assert::AreEqual(cmdArgsI["--my_string"].GetString(), std::string("billybob"));
Assert::AreEqual(cmdArgsI["--my_float"].GetFloat32(), -23.199);
Assert::AreEqual(cmdArgsI["--my_int"].GetInt32(), 199);
Assert::AreEqual(cmdArgsI["--my_num_list"].GetList()[0]->GetInt32(), 1);
Assert::AreEqual(cmdArgsI["--my_num_list"].GetList()[1]->GetInt32(), 2);
Assert::AreEqual(cmdArgsI["--my_num_list"].GetList()[2]->GetInt32(), 3);
Assert::AreEqual(cmdArgsI["--my_num_list"].GetList()[3]->GetInt32(), 4);
Assert::AreEqual(cmdArgsI["--my_str_list"].GetList()[0]->GetString(), std::string("apple"));
Assert::AreEqual(cmdArgsI["--my_str_list"].GetList()[1]->GetString(), std::string("banana"));
Assert::AreEqual(cmdArgsI["--my_str_list"].GetList()[2]->GetString(), std::string("pumpkin"));
return;
}
@ -233,15 +233,15 @@ namespace TestHazelnupp
"pumpkin",
});
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Exercise, Verify
Assert::ExpectException<HazelnuppInvalidKeyException>(
[args]
{
Hazelnupp nupp(C_Ify(args));
nupp["--borrnana"];
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI["--borrnana"];
}
);

View File

@ -1,6 +1,6 @@
#include "CppUnitTest.h"
#include "helper.h"
#include "../Hazelnupp/Hazelnupp.h"
#include "../Hazelnupp/CmdArgsInterface.h"
#include "../Hazelnupp/HazelnuppException.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
@ -23,34 +23,34 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint("--elenor-int", ParamConstraint::Require({ "5994" }));
nupp.RegisterConstraint("--federich-float", ParamConstraint::Require({ "420.69" }));
nupp.RegisterConstraint("--siegbert-string", ParamConstraint::Require({ "banana" }));
nupp.RegisterConstraint("--lieber-liste", ParamConstraint::Require({ "banana", "apple", "59" }));
cmdArgsI.RegisterConstraint("--elenor-int", ParamConstraint::Require({ "5994" }));
cmdArgsI.RegisterConstraint("--federich-float", ParamConstraint::Require({ "420.69" }));
cmdArgsI.RegisterConstraint("--siegbert-string", ParamConstraint::Require({ "banana" }));
cmdArgsI.RegisterConstraint("--lieber-liste", ParamConstraint::Require({ "banana", "apple", "59" }));
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp.HasParam("--elenor-int"));
Assert::IsTrue(nupp["--elenor-int"].GetDataType() == DATA_TYPE::INT);
Assert::AreEqual(nupp["--elenor-int"].GetInt32(), 5994);
Assert::IsTrue(cmdArgsI.HasParam("--elenor-int"));
Assert::IsTrue(cmdArgsI["--elenor-int"].GetDataType() == DATA_TYPE::INT);
Assert::AreEqual(cmdArgsI["--elenor-int"].GetInt32(), 5994);
Assert::IsTrue(nupp.HasParam("--federich-float"));
Assert::IsTrue(nupp["--federich-float"].GetDataType() == DATA_TYPE::FLOAT);
Assert::AreEqual(nupp["--federich-float"].GetFloat32(), 420.69);
Assert::IsTrue(cmdArgsI.HasParam("--federich-float"));
Assert::IsTrue(cmdArgsI["--federich-float"].GetDataType() == DATA_TYPE::FLOAT);
Assert::AreEqual(cmdArgsI["--federich-float"].GetFloat32(), 420.69);
Assert::IsTrue(nupp.HasParam("--siegbert-string"));
Assert::IsTrue(nupp["--siegbert-string"].GetDataType() == DATA_TYPE::STRING);
Assert::AreEqual(nupp["--siegbert-string"].GetString(), std::string("banana"));
Assert::IsTrue(cmdArgsI.HasParam("--siegbert-string"));
Assert::IsTrue(cmdArgsI["--siegbert-string"].GetDataType() == DATA_TYPE::STRING);
Assert::AreEqual(cmdArgsI["--siegbert-string"].GetString(), std::string("banana"));
Assert::IsTrue(nupp.HasParam("--lieber-liste"));
Assert::IsTrue(nupp["--lieber-liste"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(nupp["--lieber-liste"].GetList()[0]->GetString(), std::string("banana"));
Assert::AreEqual(nupp["--lieber-liste"].GetList()[1]->GetString(), std::string("apple"));
Assert::AreEqual(nupp["--lieber-liste"].GetList()[2]->GetInt32(), 59);
Assert::IsTrue(cmdArgsI.HasParam("--lieber-liste"));
Assert::IsTrue(cmdArgsI["--lieber-liste"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(cmdArgsI["--lieber-liste"].GetList()[0]->GetString(), std::string("banana"));
Assert::AreEqual(cmdArgsI["--lieber-liste"].GetList()[1]->GetString(), std::string("apple"));
Assert::AreEqual(cmdArgsI["--lieber-liste"].GetList()[2]->GetInt32(), 59);
return;
}
@ -75,34 +75,34 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint("--elenor-int", ParamConstraint::Require({ "6871" }));
nupp.RegisterConstraint("--federich-float", ParamConstraint::Require({ "-199.44" }));
nupp.RegisterConstraint("--siegbert-string", ParamConstraint::Require({ "bornana" }));
nupp.RegisterConstraint("--lieber-liste", ParamConstraint::Require({ "bornana", "ollpe", "5" }));
cmdArgsI.RegisterConstraint("--elenor-int", ParamConstraint::Require({ "6871" }));
cmdArgsI.RegisterConstraint("--federich-float", ParamConstraint::Require({ "-199.44" }));
cmdArgsI.RegisterConstraint("--siegbert-string", ParamConstraint::Require({ "bornana" }));
cmdArgsI.RegisterConstraint("--lieber-liste", ParamConstraint::Require({ "bornana", "ollpe", "5" }));
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp.HasParam("--elenor-int"));
Assert::IsTrue(nupp["--elenor-int"].GetDataType() == DATA_TYPE::INT);
Assert::AreEqual(nupp["--elenor-int"].GetInt32(), 5994);
Assert::IsTrue(cmdArgsI.HasParam("--elenor-int"));
Assert::IsTrue(cmdArgsI["--elenor-int"].GetDataType() == DATA_TYPE::INT);
Assert::AreEqual(cmdArgsI["--elenor-int"].GetInt32(), 5994);
Assert::IsTrue(nupp.HasParam("--federich-float"));
Assert::IsTrue(nupp["--federich-float"].GetDataType() == DATA_TYPE::FLOAT);
Assert::AreEqual(nupp["--federich-float"].GetFloat32(), 420.69);
Assert::IsTrue(cmdArgsI.HasParam("--federich-float"));
Assert::IsTrue(cmdArgsI["--federich-float"].GetDataType() == DATA_TYPE::FLOAT);
Assert::AreEqual(cmdArgsI["--federich-float"].GetFloat32(), 420.69);
Assert::IsTrue(nupp.HasParam("--siegbert-string"));
Assert::IsTrue(nupp["--siegbert-string"].GetDataType() == DATA_TYPE::STRING);
Assert::AreEqual(nupp["--siegbert-string"].GetString(), std::string("banana"));
Assert::IsTrue(cmdArgsI.HasParam("--siegbert-string"));
Assert::IsTrue(cmdArgsI["--siegbert-string"].GetDataType() == DATA_TYPE::STRING);
Assert::AreEqual(cmdArgsI["--siegbert-string"].GetString(), std::string("banana"));
Assert::IsTrue(nupp.HasParam("--lieber-liste"));
Assert::IsTrue(nupp["--lieber-liste"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(nupp["--lieber-liste"].GetList()[0]->GetString(), std::string("banana"));
Assert::AreEqual(nupp["--lieber-liste"].GetList()[1]->GetString(), std::string("apple"));
Assert::AreEqual(nupp["--lieber-liste"].GetList()[2]->GetInt32(), 59);
Assert::IsTrue(cmdArgsI.HasParam("--lieber-liste"));
Assert::IsTrue(cmdArgsI["--lieber-liste"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(cmdArgsI["--lieber-liste"].GetList()[0]->GetString(), std::string("banana"));
Assert::AreEqual(cmdArgsI["--lieber-liste"].GetList()[1]->GetString(), std::string("apple"));
Assert::AreEqual(cmdArgsI["--lieber-liste"].GetList()[2]->GetInt32(), 59);
return;
}
@ -129,41 +129,41 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint("--num-apples", ParamConstraint::TypeSafety(DATA_TYPE::INT));
nupp.RegisterConstraint("--table-height", ParamConstraint::TypeSafety(DATA_TYPE::FLOAT));
nupp.RegisterConstraint("--license-plate", ParamConstraint::TypeSafety(DATA_TYPE::STRING));
nupp.RegisterConstraint("--fav-fruits", ParamConstraint::TypeSafety(DATA_TYPE::LIST));
nupp.RegisterConstraint("--indices", ParamConstraint::TypeSafety(DATA_TYPE::LIST));
nupp.RegisterConstraint("--force", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
cmdArgsI.RegisterConstraint("--num-apples", ParamConstraint::TypeSafety(DATA_TYPE::INT));
cmdArgsI.RegisterConstraint("--table-height", ParamConstraint::TypeSafety(DATA_TYPE::FLOAT));
cmdArgsI.RegisterConstraint("--license-plate", ParamConstraint::TypeSafety(DATA_TYPE::STRING));
cmdArgsI.RegisterConstraint("--fav-fruits", ParamConstraint::TypeSafety(DATA_TYPE::LIST));
cmdArgsI.RegisterConstraint("--indices", ParamConstraint::TypeSafety(DATA_TYPE::LIST));
cmdArgsI.RegisterConstraint("--force", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp.HasParam("--num-apples"));
Assert::IsTrue(nupp["--num-apples"].GetDataType() == DATA_TYPE::INT);
Assert::AreEqual(nupp["--num-apples"].GetInt32(), 39);
Assert::IsTrue(cmdArgsI.HasParam("--num-apples"));
Assert::IsTrue(cmdArgsI["--num-apples"].GetDataType() == DATA_TYPE::INT);
Assert::AreEqual(cmdArgsI["--num-apples"].GetInt32(), 39);
Assert::IsTrue(nupp.HasParam("--table-height"));
Assert::IsTrue(nupp["--table-height"].GetDataType() == DATA_TYPE::FLOAT);
Assert::AreEqual(nupp["--table-height"].GetFloat32(), 400.0);
Assert::IsTrue(cmdArgsI.HasParam("--table-height"));
Assert::IsTrue(cmdArgsI["--table-height"].GetDataType() == DATA_TYPE::FLOAT);
Assert::AreEqual(cmdArgsI["--table-height"].GetFloat32(), 400.0);
Assert::IsTrue(nupp.HasParam("--license-plate"));
Assert::IsTrue(nupp["--license-plate"].GetDataType() == DATA_TYPE::STRING);
Assert::AreEqual(nupp["--license-plate"].GetString(), std::string("193273"));
Assert::IsTrue(cmdArgsI.HasParam("--license-plate"));
Assert::IsTrue(cmdArgsI["--license-plate"].GetDataType() == DATA_TYPE::STRING);
Assert::AreEqual(cmdArgsI["--license-plate"].GetString(), std::string("193273"));
Assert::IsTrue(nupp.HasParam("--fav-fruits"));
Assert::IsTrue(nupp["--fav-fruits"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(nupp["--fav-fruits"].GetList()[0]->GetString(), std::string("apple"));
Assert::IsTrue(cmdArgsI.HasParam("--fav-fruits"));
Assert::IsTrue(cmdArgsI["--fav-fruits"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(cmdArgsI["--fav-fruits"].GetList()[0]->GetString(), std::string("apple"));
Assert::IsTrue(nupp.HasParam("--indices"));
Assert::IsTrue(nupp["--indices"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(nupp["--indices"].GetList()[0]->GetInt32(), 9);
Assert::IsTrue(cmdArgsI.HasParam("--indices"));
Assert::IsTrue(cmdArgsI["--indices"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(cmdArgsI["--indices"].GetList()[0]->GetInt32(), 9);
Assert::IsTrue(nupp.HasParam("--force"));
Assert::IsTrue(nupp["--force"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(cmdArgsI.HasParam("--force"));
Assert::IsTrue(cmdArgsI["--force"].GetDataType() == DATA_TYPE::VOID);
return;
}
@ -189,15 +189,15 @@ namespace TestHazelnupp
Assert::ExpectException<HazelnuppConstraintMissingValue>(
[args]
{
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--elenor-int",
ParamConstraint::Require()
);
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
}
);
@ -227,15 +227,15 @@ namespace TestHazelnupp
Assert::ExpectException<HazelnuppConstraintTypeMissmatch>(
[args]
{
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--elenor-int",
ParamConstraint::TypeSafety(DATA_TYPE::INT)
);
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
}
);
@ -261,25 +261,25 @@ namespace TestHazelnupp
"baz"
});
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint("--void1", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
nupp.RegisterConstraint("--void2", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
nupp.RegisterConstraint("--void3", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
nupp.RegisterConstraint("--void4", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
nupp.RegisterConstraint("--void5", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
cmdArgsI.RegisterConstraint("--void1", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
cmdArgsI.RegisterConstraint("--void2", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
cmdArgsI.RegisterConstraint("--void3", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
cmdArgsI.RegisterConstraint("--void4", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
cmdArgsI.RegisterConstraint("--void5", ParamConstraint::TypeSafety(DATA_TYPE::VOID));
// Exercise
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp["--void1"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(nupp["--void2"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(nupp["--void3"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(nupp["--void4"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(nupp["--void5"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(cmdArgsI["--void1"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(cmdArgsI["--void2"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(cmdArgsI["--void3"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(cmdArgsI["--void4"].GetDataType() == DATA_TYPE::VOID);
Assert::IsTrue(cmdArgsI["--void5"].GetDataType() == DATA_TYPE::VOID);
return;
}
@ -294,21 +294,21 @@ namespace TestHazelnupp
"--empty-list",
});
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--empty-list",
ParamConstraint::TypeSafety(DATA_TYPE::LIST)
);
// Exercise
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp["--empty-list"].GetDataType() == DATA_TYPE::LIST, L"Wrong datatype");
Assert::AreEqual(std::size_t(0), nupp["--empty-list"].GetList().size(), L"Wrong size");
Assert::IsTrue(cmdArgsI["--empty-list"].GetDataType() == DATA_TYPE::LIST, L"Wrong datatype");
Assert::AreEqual(std::size_t(0), cmdArgsI["--empty-list"].GetList().size(), L"Wrong size");
return;
}
@ -323,21 +323,21 @@ namespace TestHazelnupp
"--empty-string",
});
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--empty-string",
ParamConstraint::TypeSafety(DATA_TYPE::STRING)
);
// Exercise
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp["--empty-string"].GetDataType() == DATA_TYPE::STRING, L"Wrong datatype");
Assert::AreEqual(std::size_t(0), nupp["--empty-string"].GetString().length(), L"Wrong size");
Assert::IsTrue(cmdArgsI["--empty-string"].GetDataType() == DATA_TYPE::STRING, L"Wrong datatype");
Assert::AreEqual(std::size_t(0), cmdArgsI["--empty-string"].GetString().length(), L"Wrong size");
return;
}
@ -354,16 +354,16 @@ namespace TestHazelnupp
// Test section: INT
Assert::ExpectException<HazelnuppConstraintTypeMissmatch>([args]
{
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--thisisvoid",
ParamConstraint::TypeSafety(DATA_TYPE::INT)
);
// Exercise
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
}, L"Failed with int");
@ -382,16 +382,16 @@ namespace TestHazelnupp
// Test section: FLOAT
Assert::ExpectException<HazelnuppConstraintTypeMissmatch>([args]
{
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--thisisvoid",
ParamConstraint::TypeSafety(DATA_TYPE::FLOAT)
);
// Exercise
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
}, L"Failed with float");
@ -408,30 +408,30 @@ namespace TestHazelnupp
"--empty-list",
});
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--default-val",
ParamConstraint::Require({ "32" }, true)
);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--not-there",
ParamConstraint::Require({}, true)
);
// Exercise
nupp.ClearConstraint("--not-there");
cmdArgsI.ClearConstraint("--not-there");
// Verify
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
// Also verifies that parse does not throw an exception for --not-there
Assert::IsTrue(nupp.HasParam("--default-val"), L"Default value is missing");
Assert::AreEqual(32, nupp["--default-val"].GetInt32(), L"Default value has wrong value");
Assert::IsTrue(cmdArgsI.HasParam("--default-val"), L"Default value is missing");
Assert::AreEqual(32, cmdArgsI["--default-val"].GetInt32(), L"Default value has wrong value");
return;
}
@ -446,19 +446,19 @@ namespace TestHazelnupp
"--empty-list",
});
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--not-there",
ParamConstraint::Require({}, true)
);
// Exercise
nupp.ClearConstraints();
cmdArgsI.ClearConstraints();
// Verify
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
return;
}
@ -473,22 +473,22 @@ namespace TestHazelnupp
"--empty-list",
});
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--not-there",
ParamConstraint::Require({}, true)
);
//Exercise
nupp.RegisterConstraint(
cmdArgsI.RegisterConstraint(
"--not-there",
ParamConstraint::Require({}, false)
);
// Verify
nupp.Parse(C_Ify(args));
cmdArgsI.Parse(C_Ify(args));
return;
}
@ -503,18 +503,18 @@ namespace TestHazelnupp
"--empty-list",
});
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
ParamConstraint dftvalConst_expected =
ParamConstraint::Require({ "32" }, true);
nupp.RegisterConstraint("--default-val", dftvalConst_expected);
nupp.RegisterConstraint("--not-there", ParamConstraint::Require({}, true));
nupp.RegisterConstraint("--another-one", ParamConstraint::Require({ "bites" }, true));
cmdArgsI.RegisterConstraint("--default-val", dftvalConst_expected);
cmdArgsI.RegisterConstraint("--not-there", ParamConstraint::Require({}, true));
cmdArgsI.RegisterConstraint("--another-one", ParamConstraint::Require({ "bites" }, true));
// Exercise
ParamConstraint dftvalConst = nupp.GetConstraint("--default-val");
ParamConstraint dftvalConst = cmdArgsI.GetConstraint("--default-val");
// Verify
Assert::IsTrue(dftvalConst_expected.required == dftvalConst.required, L"required");

View File

@ -1,6 +1,6 @@
#include "CppUnitTest.h"
#include "helper.h"
#include "../Hazelnupp/Hazelnupp.h"
#include "../Hazelnupp/CmdArgsInterface.h"
#include "../Hazelnupp/HazelnuppException.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
@ -23,44 +23,44 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
const Hazelnupp* ptnupp = &nupp;
const CmdArgsInterface* ptcmdArgsI = &cmdArgsI;
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetInt64();
(*ptcmdArgsI)["--pud"].GetInt64();
}
, L"Int64");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetInt32();
(*ptcmdArgsI)["--pud"].GetInt32();
}
, L"Int32");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetFloat64();
(*ptcmdArgsI)["--pud"].GetFloat64();
}
, L"Float64");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetFloat32();
(*ptcmdArgsI)["--pud"].GetFloat32();
}
, L"Float32");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetList();
(*ptcmdArgsI)["--pud"].GetList();
}
, L"List");
@ -78,45 +78,45 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
const Hazelnupp* ptnupp = &nupp;
const CmdArgsInterface* ptcmdArgsI = &cmdArgsI;
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetInt64();
(*ptcmdArgsI)["--pud"].GetInt64();
}
, L"Int64");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetInt32();
(*ptcmdArgsI)["--pud"].GetInt32();
}
, L"Int32");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetFloat64();
(*ptcmdArgsI)["--pud"].GetFloat64();
}
, L"Float64");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetFloat32();
(*ptcmdArgsI)["--pud"].GetFloat32();
}
, L"Float32");
// Expect empty string
Assert::AreEqual(std::string(), nupp["--pud"].GetString(), L"String");
Assert::AreEqual(std::string(), cmdArgsI["--pud"].GetString(), L"String");
// Expect empty list
Assert::AreEqual(std::size_t(0), nupp["--pud"].GetList().size(), L"List");
Assert::AreEqual(std::size_t(0), cmdArgsI["--pud"].GetList().size(), L"List");
return;
}
@ -132,22 +132,22 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
const Hazelnupp* ptnupp = &nupp;
const CmdArgsInterface* ptcmdArgsI = &cmdArgsI;
Assert::AreEqual(39ll, nupp["--pud"].GetInt64(), L"Int64");
Assert::AreEqual(39, nupp["--pud"].GetInt32(), L"Int32");
Assert::IsTrue(39.0l == nupp["--pud"].GetFloat64(), L"Float64");
Assert::AreEqual(39.0, nupp["--pud"].GetFloat32(), L"Float32");
Assert::AreEqual(std::string("39"), nupp["--pud"].GetString(), L"String");
Assert::AreEqual(39ll, cmdArgsI["--pud"].GetInt64(), L"Int64");
Assert::AreEqual(39, cmdArgsI["--pud"].GetInt32(), L"Int32");
Assert::IsTrue(39.0l == cmdArgsI["--pud"].GetFloat64(), L"Float64");
Assert::AreEqual(39.0, cmdArgsI["--pud"].GetFloat32(), L"Float32");
Assert::AreEqual(std::string("39"), cmdArgsI["--pud"].GetString(), L"String");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetList();
(*ptcmdArgsI)["--pud"].GetList();
}
, L"List");
@ -166,22 +166,22 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
const Hazelnupp* ptnupp = &nupp;
const CmdArgsInterface* ptcmdArgsI = &cmdArgsI;
Assert::AreEqual(39ll, nupp["--pud"].GetInt64(), L"Int64");
Assert::AreEqual(39, nupp["--pud"].GetInt32(), L"Int32");
Assert::IsTrue(39.5l == nupp["--pud"].GetFloat64(), L"Float64");
Assert::AreEqual(39.5, nupp["--pud"].GetFloat32(), L"Float32");
Assert::AreEqual(std::string("39.5"), nupp["--pud"].GetString(), L"String");
Assert::AreEqual(39ll, cmdArgsI["--pud"].GetInt64(), L"Int64");
Assert::AreEqual(39, cmdArgsI["--pud"].GetInt32(), L"Int32");
Assert::IsTrue(39.5l == cmdArgsI["--pud"].GetFloat64(), L"Float64");
Assert::AreEqual(39.5, cmdArgsI["--pud"].GetFloat32(), L"Float32");
Assert::AreEqual(std::string("39.5"), cmdArgsI["--pud"].GetString(), L"String");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetList();
(*ptcmdArgsI)["--pud"].GetList();
}
, L"List");
@ -203,44 +203,44 @@ namespace TestHazelnupp
});
// Exercise
Hazelnupp nupp(C_Ify(args));
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI(C_Ify(args));
cmdArgsI.SetCrashOnFail(false);
// Verify
const Hazelnupp* ptnupp = &nupp;
const CmdArgsInterface* ptcmdArgsI = &cmdArgsI;
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetInt64();
(*ptcmdArgsI)["--pud"].GetInt64();
}
, L"Int64");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetInt32();
(*ptcmdArgsI)["--pud"].GetInt32();
}
, L"Int32");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetFloat64();
(*ptcmdArgsI)["--pud"].GetFloat64();
}
, L"Float64");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetFloat32();
(*ptcmdArgsI)["--pud"].GetFloat32();
}
, L"Float32");
Assert::ExpectException<HazelnuppValueNotConvertibleException>(
[ptnupp]
[ptcmdArgsI]
{
(*ptnupp)["--pud"].GetString();
(*ptcmdArgsI)["--pud"].GetString();
}
, L"String");

View File

@ -1,6 +1,6 @@
#include "CppUnitTest.h"
#include "helper.h"
#include "../Hazelnupp/Hazelnupp.h"
#include "../Hazelnupp/CmdArgsInterface.h"
#include "../Hazelnupp/HazelnuppException.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
@ -16,16 +16,16 @@ namespace TestHazelnupp
TEST_METHOD(Set_Get_Application_Brief)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
std::string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in quam tincidunt sapien euismod egestas eget vel dolor. Duis non turpis porttitor, convallis velit at.";
// Exercise
nupp.SetBriefDescription(text);
cmdArgsI.SetBriefDescription(text);
// Verify
Assert::AreEqual(text, nupp.GetBriefDescription());
Assert::AreEqual(text, cmdArgsI.GetBriefDescription());
return;
}
@ -34,18 +34,18 @@ namespace TestHazelnupp
TEST_METHOD(Can_Set_Parameter_Description)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
// Exercise
nupp.RegisterDescription("--force", "Just force it");
nupp.RegisterDescription("--lose", "Just lose it");
nupp.RegisterDescription("--crazy", "Go crazy");
cmdArgsI.RegisterDescription("--force", "Just force it");
cmdArgsI.RegisterDescription("--lose", "Just lose it");
cmdArgsI.RegisterDescription("--crazy", "Go crazy");
// Verify
Assert::AreEqual(std::string("Just force it"), nupp.GetDescription("--force"));
Assert::AreEqual(std::string("Go crazy"), nupp.GetDescription("--crazy"));
Assert::AreEqual(std::string("Just lose it"), nupp.GetDescription("--lose"));
Assert::AreEqual(std::string("Just force it"), cmdArgsI.GetDescription("--force"));
Assert::AreEqual(std::string("Go crazy"), cmdArgsI.GetDescription("--crazy"));
Assert::AreEqual(std::string("Just lose it"), cmdArgsI.GetDescription("--lose"));
return;
}
@ -54,17 +54,17 @@ namespace TestHazelnupp
TEST_METHOD(Has_Description)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
// Exercise, verify
Assert::IsFalse(nupp.HasDescription("--force"));
Assert::IsFalse(nupp.HasDescription("--main"));
Assert::IsFalse(cmdArgsI.HasDescription("--force"));
Assert::IsFalse(cmdArgsI.HasDescription("--main"));
nupp.RegisterDescription("--force", "Just force it");
cmdArgsI.RegisterDescription("--force", "Just force it");
Assert::IsTrue(nupp.HasDescription("--force"));
Assert::IsFalse(nupp.HasDescription("--main"));
Assert::IsTrue(cmdArgsI.HasDescription("--force"));
Assert::IsFalse(cmdArgsI.HasDescription("--main"));
return;
}
@ -73,16 +73,16 @@ namespace TestHazelnupp
TEST_METHOD(No_Description_Is_Empty_String)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
// Exercise
nupp.RegisterDescription("--force", "Just force it");
nupp.RegisterDescription("--lose", "Just lose it");
nupp.RegisterDescription("--crazy", "Go crazy");
cmdArgsI.RegisterDescription("--force", "Just force it");
cmdArgsI.RegisterDescription("--lose", "Just lose it");
cmdArgsI.RegisterDescription("--crazy", "Go crazy");
// Verify
Assert::AreEqual(std::string(), nupp.GetDescription("--man"));
Assert::AreEqual(std::string(), cmdArgsI.GetDescription("--man"));
return;
}
@ -91,23 +91,23 @@ namespace TestHazelnupp
TEST_METHOD(ClearDescription)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
// Exercise
nupp.RegisterDescription("--force", "Just force it");
nupp.RegisterDescription("--lose", "Just lose it");
nupp.RegisterDescription("--crazy", "Go crazy");
cmdArgsI.RegisterDescription("--force", "Just force it");
cmdArgsI.RegisterDescription("--lose", "Just lose it");
cmdArgsI.RegisterDescription("--crazy", "Go crazy");
nupp.ClearDescription("--lose");
cmdArgsI.ClearDescription("--lose");
// Verify
// These two should still work
Assert::AreEqual(std::string("Just force it"), nupp.GetDescription("--force"));
Assert::AreEqual(std::string("Go crazy"), nupp.GetDescription("--crazy"));
Assert::AreEqual(std::string("Just force it"), cmdArgsI.GetDescription("--force"));
Assert::AreEqual(std::string("Go crazy"), cmdArgsI.GetDescription("--crazy"));
Assert::IsFalse(nupp.HasDescription("--lose"));
Assert::IsFalse(cmdArgsI.HasDescription("--lose"));
return;
}
@ -116,22 +116,22 @@ namespace TestHazelnupp
TEST_METHOD(ClearDescriptions)
{
// Setup
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
CmdArgsInterface cmdArgsI;
cmdArgsI.SetCrashOnFail(false);
// Exercise
nupp.RegisterDescription("--force", "Just force it");
nupp.RegisterDescription("--lose", "Just lose it");
nupp.RegisterDescription("--crazy", "Go crazy");
cmdArgsI.RegisterDescription("--force", "Just force it");
cmdArgsI.RegisterDescription("--lose", "Just lose it");
cmdArgsI.RegisterDescription("--crazy", "Go crazy");
nupp.ClearDescriptions();
cmdArgsI.ClearDescriptions();
// Verify
// These two should still work
Assert::IsFalse(nupp.HasDescription("--force"));
Assert::IsFalse(nupp.HasDescription("--crazy"));
Assert::IsFalse(nupp.HasDescription("--lose"));
Assert::IsFalse(cmdArgsI.HasDescription("--force"));
Assert::IsFalse(cmdArgsI.HasDescription("--crazy"));
Assert::IsFalse(cmdArgsI.HasDescription("--lose"));
return;
}