Changed parsing-conversion behaviour of the void value. It is now less strict.

This commit is contained in:
Leonetienne 2021-06-05 12:37:24 +02:00
parent d6145ea5a9
commit c18c7b1c74
4 changed files with 41 additions and 2 deletions

View File

@ -180,6 +180,12 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
(constraint->wantedType == DATA_TYPE::LIST))
return new ListValue();
// Is a string forced via a constraint? If yes, return an empty string
if ((constrainType) &&
(constraint->wantedType == DATA_TYPE::STRING))
return new StringValue("");
// Else, just return the void type
return new VoidValue;
}

View File

@ -159,6 +159,7 @@
<ClInclude Include="ParamConstraint.h" />
<ClInclude Include="Parameter.h" />
<ClInclude Include="DataType.h" />
<ClInclude Include="Placeholders.h" />
<ClInclude Include="StringTools.h" />
<ClInclude Include="StringValue.h" />
<ClInclude Include="Value.h" />

View File

@ -83,5 +83,8 @@
<ClInclude Include="HazelnuppException.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="Placeholders.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -307,8 +307,37 @@ namespace TestHazelnupp
nupp.Parse(C_Ify(args));
// Verify
Assert::IsTrue(nupp["--empty-list"].GetDataType() == DATA_TYPE::LIST);
Assert::AreEqual(std::size_t(0), nupp["--empty-list"].GetList().size());
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");
return;
}
// Tests that a void can be converted to an empty string
TEST_METHOD(Weird_Load_Conversions_VoidToEmptyString)
{
// Setup
ArgList args({
"/my/fake/path/wahoo.out",
"--dummy",
"--empty-string",
});
Hazelnupp nupp;
nupp.SetCrashOnFail(false);
nupp.RegisterConstraint(
"--empty-string",
ParamConstraint::TypeSafety(DATA_TYPE::STRING)
);
// Exercise
nupp.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");
return;
}