فهرست منبع

Reduce complexity of SectionPairRow class

Patrick-Christopher Mattulat 2 سال پیش
والد
کامیت
c45993caca

+ 1 - 7
include/ls-std/io/section-pair/SectionPairRow.hpp

@@ -26,19 +26,13 @@ namespace ls::std::io
       ~SectionPairRow() override;
 
       [[nodiscard]] ls::std::io::section_pair_identifier getKey();
-      [[nodiscard]] ls::std::io::section_pair_row_value getValue();
-      [[nodiscard]] bool isKeyValue();
       [[nodiscard]] bool isList();
-      void setValue(const ls::std::io::section_pair_row_value &_value);
+      [[nodiscard]] bool isSingleValue();
 
     private:
 
       ls::std::io::section_pair_identifier key{};
       ls::std::io::SectionPairRowEnumType type{};
-      ::std::list<ls::std::io::section_pair_row_value> values{};
-
-      void _setType(const ls::std::io::SectionPairRowEnumType &_type);
-      void _setValue(const ls::std::io::section_pair_row_value &_value);
   };
 }
 

+ 2 - 2
include/ls-std/io/section-pair/SectionPairRowEnumType.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-08
+* Changed:         2023-02-10
 *
 * */
 
@@ -16,7 +16,7 @@ namespace ls::std::io
   {
     SECTION_PAIR_ROW_NOT_IMPLEMENTED = 0,
     SECTION_PAIR_ROW_LIST,
-    SECTION_PAIR_ROW_KEY_VALUE
+    SECTION_PAIR_ROW_SINGLE_VALUE
   };
 }
 

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

@@ -10,7 +10,6 @@
 #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")
 {
@@ -26,43 +25,12 @@ ls::std::io::section_pair_row_value ls::std::io::SectionPairRow::getKey()
   return this->key;
 }
 
-::std::string ls::std::io::SectionPairRow::getValue()
-{
-  return this->values.empty() ? "" : this->values.front();
-}
-
-bool ls::std::io::SectionPairRow::isKeyValue()
-{
-  return this->type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_KEY_VALUE;
-}
-
 bool ls::std::io::SectionPairRow::isList()
 {
   return this->type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST;
 }
 
-void ls::std::io::SectionPairRow::setValue(const ls::std::io::section_pair_row_value &_value)
+bool ls::std::io::SectionPairRow::isSingleValue()
 {
-  ls::std::core::EmptyStringArgumentEvaluator{_value, "passed value for section pair row is empty!"}.evaluate();
-  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);
-}
-
-void ls::std::io::SectionPairRow::_setType(const ls::std::io::SectionPairRowEnumType &_type)
-{
-  if (_type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_NOT_IMPLEMENTED)
-  {
-    this->type = _type;
-  }
-}
-
-void ls::std::io::SectionPairRow::_setValue(const ls::std::io::section_pair_row_value &_value)
-{
-  if (!this->values.empty())
-  {
-    this->values.pop_front();
-  }
-
-  this->values.push_back(_value);
+  return this->type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE;
 }

+ 2 - 52
test/cases/io/section-pair/SectionPairRowTest.cpp

@@ -76,63 +76,13 @@ namespace
     ASSERT_STREQ(key.c_str(), row.getKey().c_str());
   }
 
-  TEST_F(SectionPairRowTest, getValue)
+  TEST_F(SectionPairRowTest, isSingleValue)
   {
-    SectionPairRow row{"tmp-key"};
-    ASSERT_TRUE(row.getValue().empty());
-  }
-
-  TEST_F(SectionPairRowTest, isKeyValue)
-  {
-    ASSERT_FALSE(SectionPairRow{"tmp-key"}.isKeyValue());
+    ASSERT_FALSE(SectionPairRow{"tmp-key"}.isSingleValue());
   }
 
   TEST_F(SectionPairRowTest, isList)
   {
     ASSERT_FALSE(SectionPairRow{"tmp-key"}.isList());
   }
-
-  TEST_F(SectionPairRowTest, setValue_key_value)
-  {
-    SectionPairRow row{"color"};
-    row.setValue("blue");
-
-    ASSERT_STREQ("blue", row.getValue().c_str());
-  }
-
-  TEST_F(SectionPairRowTest, setValue_key_value_empty_value)
-  {
-    SectionPairRow row{"color"};
-
-    EXPECT_THROW(
-        {
-          try
-          {
-            row.setValue("");
-          }
-          catch (const IllegalArgumentException &_exception)
-          {
-            throw;
-          }
-        },
-        IllegalArgumentException);
-  }
-
-  TEST_F(SectionPairRowTest, setValue_key_value_invalid_value)
-  {
-    SectionPairRow row{"color"};
-
-    EXPECT_THROW(
-        {
-          try
-          {
-            row.setValue("=33");
-          }
-          catch (const IllegalArgumentException &_exception)
-          {
-            throw;
-          }
-        },
-        IllegalArgumentException);
-  }
 }