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

View File

@ -8,13 +8,13 @@ namespace Hazelnp
{ {
/** The main class to interface with /** The main class to interface with
*/ */
class Hazelnupp class CmdArgsInterface
{ {
public: public:
Hazelnupp(); CmdArgsInterface();
Hazelnupp(const int argc, const char* const* argv); CmdArgsInterface(const int argc, const char* const* argv);
~Hazelnupp(); ~CmdArgsInterface();
//! Will parse command line arguments //! Will parse command line arguments
void Parse(const int argc, const char* const* argv); 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. //! Gets whether the application crashes on an exception whilst parsing, and prints to stderr.
bool GetCrashOnFail() const; 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); 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; bool GetCatchHelp() const;
//! Sets a brief description of the application to be automatically added to the documentation. //! 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. //! A brief description of the application to be added to the generated documentation. Optional.
std::string briefDescription; 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; 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; bool crashOnFail = true;
}; };
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
#include "CppUnitTest.h" #include "CppUnitTest.h"
#include "helper.h" #include "helper.h"
#include "../Hazelnupp/Hazelnupp.h" #include "../Hazelnupp/CmdArgsInterface.h"
#include "../Hazelnupp/HazelnuppException.h" #include "../Hazelnupp/HazelnuppException.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
@ -16,16 +16,16 @@ namespace TestHazelnupp
TEST_METHOD(Set_Get_Application_Brief) TEST_METHOD(Set_Get_Application_Brief)
{ {
// Setup // Setup
Hazelnupp nupp; CmdArgsInterface cmdArgsI;
nupp.SetCrashOnFail(false); 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."; 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 // Exercise
nupp.SetBriefDescription(text); cmdArgsI.SetBriefDescription(text);
// Verify // Verify
Assert::AreEqual(text, nupp.GetBriefDescription()); Assert::AreEqual(text, cmdArgsI.GetBriefDescription());
return; return;
} }
@ -34,18 +34,18 @@ namespace TestHazelnupp
TEST_METHOD(Can_Set_Parameter_Description) TEST_METHOD(Can_Set_Parameter_Description)
{ {
// Setup // Setup
Hazelnupp nupp; CmdArgsInterface cmdArgsI;
nupp.SetCrashOnFail(false); cmdArgsI.SetCrashOnFail(false);
// Exercise // Exercise
nupp.RegisterDescription("--force", "Just force it"); cmdArgsI.RegisterDescription("--force", "Just force it");
nupp.RegisterDescription("--lose", "Just lose it"); cmdArgsI.RegisterDescription("--lose", "Just lose it");
nupp.RegisterDescription("--crazy", "Go crazy"); cmdArgsI.RegisterDescription("--crazy", "Go crazy");
// Verify // Verify
Assert::AreEqual(std::string("Just force it"), nupp.GetDescription("--force")); Assert::AreEqual(std::string("Just force it"), cmdArgsI.GetDescription("--force"));
Assert::AreEqual(std::string("Go crazy"), nupp.GetDescription("--crazy")); Assert::AreEqual(std::string("Go crazy"), cmdArgsI.GetDescription("--crazy"));
Assert::AreEqual(std::string("Just lose it"), nupp.GetDescription("--lose")); Assert::AreEqual(std::string("Just lose it"), cmdArgsI.GetDescription("--lose"));
return; return;
} }
@ -54,17 +54,17 @@ namespace TestHazelnupp
TEST_METHOD(Has_Description) TEST_METHOD(Has_Description)
{ {
// Setup // Setup
Hazelnupp nupp; CmdArgsInterface cmdArgsI;
nupp.SetCrashOnFail(false); cmdArgsI.SetCrashOnFail(false);
// Exercise, verify // Exercise, verify
Assert::IsFalse(nupp.HasDescription("--force")); Assert::IsFalse(cmdArgsI.HasDescription("--force"));
Assert::IsFalse(nupp.HasDescription("--main")); Assert::IsFalse(cmdArgsI.HasDescription("--main"));
nupp.RegisterDescription("--force", "Just force it"); cmdArgsI.RegisterDescription("--force", "Just force it");
Assert::IsTrue(nupp.HasDescription("--force")); Assert::IsTrue(cmdArgsI.HasDescription("--force"));
Assert::IsFalse(nupp.HasDescription("--main")); Assert::IsFalse(cmdArgsI.HasDescription("--main"));
return; return;
} }
@ -73,16 +73,16 @@ namespace TestHazelnupp
TEST_METHOD(No_Description_Is_Empty_String) TEST_METHOD(No_Description_Is_Empty_String)
{ {
// Setup // Setup
Hazelnupp nupp; CmdArgsInterface cmdArgsI;
nupp.SetCrashOnFail(false); cmdArgsI.SetCrashOnFail(false);
// Exercise // Exercise
nupp.RegisterDescription("--force", "Just force it"); cmdArgsI.RegisterDescription("--force", "Just force it");
nupp.RegisterDescription("--lose", "Just lose it"); cmdArgsI.RegisterDescription("--lose", "Just lose it");
nupp.RegisterDescription("--crazy", "Go crazy"); cmdArgsI.RegisterDescription("--crazy", "Go crazy");
// Verify // Verify
Assert::AreEqual(std::string(), nupp.GetDescription("--man")); Assert::AreEqual(std::string(), cmdArgsI.GetDescription("--man"));
return; return;
} }
@ -91,23 +91,23 @@ namespace TestHazelnupp
TEST_METHOD(ClearDescription) TEST_METHOD(ClearDescription)
{ {
// Setup // Setup
Hazelnupp nupp; CmdArgsInterface cmdArgsI;
nupp.SetCrashOnFail(false); cmdArgsI.SetCrashOnFail(false);
// Exercise // Exercise
nupp.RegisterDescription("--force", "Just force it"); cmdArgsI.RegisterDescription("--force", "Just force it");
nupp.RegisterDescription("--lose", "Just lose it"); cmdArgsI.RegisterDescription("--lose", "Just lose it");
nupp.RegisterDescription("--crazy", "Go crazy"); cmdArgsI.RegisterDescription("--crazy", "Go crazy");
nupp.ClearDescription("--lose"); cmdArgsI.ClearDescription("--lose");
// Verify // Verify
// These two should still work // These two should still work
Assert::AreEqual(std::string("Just force it"), nupp.GetDescription("--force")); Assert::AreEqual(std::string("Just force it"), cmdArgsI.GetDescription("--force"));
Assert::AreEqual(std::string("Go crazy"), nupp.GetDescription("--crazy")); Assert::AreEqual(std::string("Go crazy"), cmdArgsI.GetDescription("--crazy"));
Assert::IsFalse(nupp.HasDescription("--lose")); Assert::IsFalse(cmdArgsI.HasDescription("--lose"));
return; return;
} }
@ -116,22 +116,22 @@ namespace TestHazelnupp
TEST_METHOD(ClearDescriptions) TEST_METHOD(ClearDescriptions)
{ {
// Setup // Setup
Hazelnupp nupp; CmdArgsInterface cmdArgsI;
nupp.SetCrashOnFail(false); cmdArgsI.SetCrashOnFail(false);
// Exercise // Exercise
nupp.RegisterDescription("--force", "Just force it"); cmdArgsI.RegisterDescription("--force", "Just force it");
nupp.RegisterDescription("--lose", "Just lose it"); cmdArgsI.RegisterDescription("--lose", "Just lose it");
nupp.RegisterDescription("--crazy", "Go crazy"); cmdArgsI.RegisterDescription("--crazy", "Go crazy");
nupp.ClearDescriptions(); cmdArgsI.ClearDescriptions();
// Verify // Verify
// These two should still work // These two should still work
Assert::IsFalse(nupp.HasDescription("--force")); Assert::IsFalse(cmdArgsI.HasDescription("--force"));
Assert::IsFalse(nupp.HasDescription("--crazy")); Assert::IsFalse(cmdArgsI.HasDescription("--crazy"));
Assert::IsFalse(nupp.HasDescription("--lose")); Assert::IsFalse(cmdArgsI.HasDescription("--lose"));
return; return;
} }