Browse Source

Add SectionPairRowValueArgumentEvaluator class

This evaluator will throw an IllegalArgumentException in case a section pair value is invalid.
Patrick-Christopher Mattulat 2 years ago
parent
commit
3d69e4b8d0

+ 2 - 0
CMakeLists.txt

@@ -174,6 +174,7 @@ set(SOURCE_FILES_IO
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairIdentifierArgumentEvaluator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairIdentifierValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRow.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRowValueValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/xml/XmlAttribute.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/xml/XmlDeclaration.cpp
@@ -259,6 +260,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairIdentifierArgumentEvaluatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairIdentifierValidatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowValueArgumentEvaluatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowValueValidatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlAttributeTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlDeclarationTest.cpp

+ 34 - 0
include/ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp

@@ -0,0 +1,34 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-10
+* Changed:         2023-02-10
+*
+* */
+
+#ifndef LS_STD_SECTION_PAIR_ROW_VALUE_ARGUMENT_EVALUATOR_HPP
+#define LS_STD_SECTION_PAIR_ROW_VALUE_ARGUMENT_EVALUATOR_HPP
+
+#include <ls-std/core/interface/IEvaluator.hpp>
+#include <string>
+
+namespace ls::std::io
+{
+  class SectionPairRowValueArgumentEvaluator : public ls::std::core::interface_type::IEvaluator
+  {
+    public:
+
+      explicit SectionPairRowValueArgumentEvaluator(::std::string _value, ::std::string _message);
+      ~SectionPairRowValueArgumentEvaluator() override;
+
+      void evaluate() override;
+
+    private:
+
+      ::std::string message{};
+      ::std::string value{};
+  };
+}
+
+#endif

+ 2 - 1
include/ls-std/ls-std-io.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-14
- * Changed:         2023-02-09
+ * Changed:         2023-02-10
  *
  * */
 
@@ -24,6 +24,7 @@
 #include <ls-std/io/section-pair/SectionPairIdentifierValidator.hpp>
 #include <ls-std/io/section-pair/SectionPairRow.hpp>
 #include <ls-std/io/section-pair/SectionPairRowEnumType.hpp>
+#include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>
 #include <ls-std/io/section-pair/SectionPairRowValueValidator.hpp>
 
 #include <ls-std/io/xml/XmlAttribute.hpp>

+ 25 - 0
source/ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.cpp

@@ -0,0 +1,25 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-10
+* Changed:         2023-02-10
+*
+* */
+
+#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>
+#include <ls-std/io/section-pair/SectionPairRowValueValidator.hpp>
+
+ls::std::io::SectionPairRowValueArgumentEvaluator::SectionPairRowValueArgumentEvaluator(::std::string _value, ::std::string _message) : value(::std::move(_value)) , message(::std::move(_message))
+{}
+
+ls::std::io::SectionPairRowValueArgumentEvaluator::~SectionPairRowValueArgumentEvaluator() = default;
+
+void ls::std::io::SectionPairRowValueArgumentEvaluator::evaluate()
+{
+  if (!ls::std::io::SectionPairRowValueValidator(this->value).isValid())
+  {
+    throw ls::std::core::IllegalArgumentException{this->message};
+  }
+}

+ 2 - 2
test/cases/io/section-pair/SectionPairIdentifierArgumentEvaluatorTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-09
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
@@ -49,4 +49,4 @@ namespace
         },
         IllegalArgumentException);
   }
-}
+}

+ 52 - 0
test/cases/io/section-pair/SectionPairRowValueArgumentEvaluatorTest.cpp

@@ -0,0 +1,52 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-10
+* Changed:         2023-02-10
+*
+* */
+
+#include <gtest/gtest.h>
+#include <ls-std/ls-std-core.hpp>
+#include <ls-std/ls-std-io.hpp>
+#include <string>
+
+using namespace ls::std::core;
+using namespace ls::std::io;
+using namespace ::std;
+
+namespace
+{
+  class SectionPairRowValueArgumentEvaluatorTest : public ::testing::Test
+  {
+    protected:
+
+      SectionPairRowValueArgumentEvaluatorTest() = default;
+      ~SectionPairRowValueArgumentEvaluatorTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(SectionPairRowValueArgumentEvaluatorTest, evaluate)
+  {
+    EXPECT_THROW(
+        {
+          try
+          {
+            SectionPairRowValueArgumentEvaluator("=33", "section pair value contains invalid characters!").evaluate();
+          }
+          catch (const IllegalArgumentException &_exception)
+          {
+            ::std::string message = _exception.what();
+            ASSERT_STREQ("IllegalArgumentException thrown - section pair value contains invalid characters!", message.c_str());
+            throw;
+          }
+        },
+        IllegalArgumentException);
+  }
+}