From c18c7b1c744befc3855b938958a98e4bd4199fdd Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Sat, 5 Jun 2021 12:37:24 +0200 Subject: [PATCH] Changed parsing-conversion behaviour of the void value. It is now less strict. --- Hazelnupp/Hazelnupp.cpp | 6 ++++++ Hazelnupp/Hazelnupp.vcxproj | 1 + Hazelnupp/Hazelnupp.vcxproj.filters | 3 +++ Test_Hazelnupp/Constraints.cpp | 33 +++++++++++++++++++++++++++-- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Hazelnupp/Hazelnupp.cpp b/Hazelnupp/Hazelnupp.cpp index 09e849f..40bd221 100644 --- a/Hazelnupp/Hazelnupp.cpp +++ b/Hazelnupp/Hazelnupp.cpp @@ -180,6 +180,12 @@ Value* Hazelnupp::ParseValue(const std::vector& 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; } diff --git a/Hazelnupp/Hazelnupp.vcxproj b/Hazelnupp/Hazelnupp.vcxproj index 2cb5ad0..a22ab04 100644 --- a/Hazelnupp/Hazelnupp.vcxproj +++ b/Hazelnupp/Hazelnupp.vcxproj @@ -159,6 +159,7 @@ + diff --git a/Hazelnupp/Hazelnupp.vcxproj.filters b/Hazelnupp/Hazelnupp.vcxproj.filters index fb7afa6..f64c1da 100644 --- a/Hazelnupp/Hazelnupp.vcxproj.filters +++ b/Hazelnupp/Hazelnupp.vcxproj.filters @@ -83,5 +83,8 @@ Headerdateien + + Headerdateien + \ No newline at end of file diff --git a/Test_Hazelnupp/Constraints.cpp b/Test_Hazelnupp/Constraints.cpp index 982d734..cb96907 100644 --- a/Test_Hazelnupp/Constraints.cpp +++ b/Test_Hazelnupp/Constraints.cpp @@ -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; }