Changed parsing-conversion behaviour of the void value. It is now less strict.
This commit is contained in:
parent
d6145ea5a9
commit
c18c7b1c74
@ -180,6 +180,12 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
(constraint->wantedType == DATA_TYPE::LIST))
|
(constraint->wantedType == DATA_TYPE::LIST))
|
||||||
return new ListValue();
|
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;
|
return new VoidValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +159,7 @@
|
|||||||
<ClInclude Include="ParamConstraint.h" />
|
<ClInclude Include="ParamConstraint.h" />
|
||||||
<ClInclude Include="Parameter.h" />
|
<ClInclude Include="Parameter.h" />
|
||||||
<ClInclude Include="DataType.h" />
|
<ClInclude Include="DataType.h" />
|
||||||
|
<ClInclude Include="Placeholders.h" />
|
||||||
<ClInclude Include="StringTools.h" />
|
<ClInclude Include="StringTools.h" />
|
||||||
<ClInclude Include="StringValue.h" />
|
<ClInclude Include="StringValue.h" />
|
||||||
<ClInclude Include="Value.h" />
|
<ClInclude Include="Value.h" />
|
||||||
|
@ -83,5 +83,8 @@
|
|||||||
<ClInclude Include="HazelnuppException.h">
|
<ClInclude Include="HazelnuppException.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Placeholders.h">
|
||||||
|
<Filter>Headerdateien</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -307,8 +307,37 @@ namespace TestHazelnupp
|
|||||||
nupp.Parse(C_Ify(args));
|
nupp.Parse(C_Ify(args));
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
Assert::IsTrue(nupp["--empty-list"].GetDataType() == DATA_TYPE::LIST);
|
Assert::IsTrue(nupp["--empty-list"].GetDataType() == DATA_TYPE::LIST, L"Wrong datatype");
|
||||||
Assert::AreEqual(std::size_t(0), nupp["--empty-list"].GetList().size());
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user