Browse Source

Add value evaluator to SectionPairRow method

Patrick-Christopher Mattulat 2 years ago
parent
commit
fc2c4b1ef1

+ 2 - 1
source/ls-std/io/section-pair/SectionPairRow.cpp

@@ -10,6 +10,7 @@
 #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
 #include <ls-std/io/section-pair/SectionPairIdentifierArgumentEvaluator.hpp>
 #include <ls-std/io/section-pair/SectionPairRow.hpp>
+#include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>
 
 ls::std::io::SectionPairRow::SectionPairRow(const ls::std::io::section_pair_identifier &_key) : ls::std::core::Class("SectionPairRow")
 {
@@ -43,7 +44,7 @@ bool ls::std::io::SectionPairRow::isList()
 void ls::std::io::SectionPairRow::setValue(const ls::std::io::section_pair_row_value &_value)
 {
   ls::std::core::EmptyStringArgumentEvaluator{_value, "passed value for section pair row is empty!"}.evaluate();
-  //TODO: add SectionPairRowValueArgumentEvaluator
+  ls::std::io::SectionPairRowValueArgumentEvaluator{_value, "passed value for section pair row \"" + _value + "\" contains invalid characters!"}.evaluate();
   this->_setType(ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_KEY_VALUE);
   this->_setValue(_value);
 }

+ 18 - 0
test/cases/io/section-pair/SectionPairRowTest.cpp

@@ -117,4 +117,22 @@ namespace
         },
         IllegalArgumentException);
   }
+
+  TEST_F(SectionPairRowTest, setValue_key_value_invalid_value)
+  {
+    SectionPairRow row{"color"};
+
+    EXPECT_THROW(
+        {
+          try
+          {
+            row.setValue("=33");
+          }
+          catch (const IllegalArgumentException &_exception)
+          {
+            throw;
+          }
+        },
+        IllegalArgumentException);
+  }
 }