Sfoglia il codice sorgente

Add setValue method for SectionPairRow class

Patrick-Christopher Mattulat 2 anni fa
parent
commit
5e60a068f7

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

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-11
+* Changed:         2023-02-12
 *
 * */
 
@@ -30,6 +30,7 @@ namespace ls::std::io
       [[nodiscard]] ::std::shared_ptr<ls::std::io::SectionPairRowValue> getValue();
       [[nodiscard]] bool isList();
       [[nodiscard]] bool isSingleValue();
+      void setKey(const ls::std::io::section_pair_identifier &_key);
 
     private:
 

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

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-11
+* Changed:         2023-02-12
 *
 * */
 
@@ -42,6 +42,11 @@ bool ls::std::io::SectionPairRow::isSingleValue()
   return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE;
 }
 
+void ls::std::io::SectionPairRow::setKey(const ls::std::io::section_pair_identifier &_key)
+{
+  this->_setKey(_key);
+}
+
 void ls::std::io::SectionPairRow::_initValue(const ls::std::io::SectionPairRowEnumType &_type)
 {
   switch (_type)

+ 9 - 1
test/cases/io/section-pair/model/SectionPairRowTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-11
+* Changed:         2023-02-12
 *
 * */
 
@@ -94,4 +94,12 @@ namespace
   {
     ASSERT_FALSE(SectionPairRow("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE).isList());
   }
+
+  TEST_F(SectionPairRowTest, setKey)
+  {
+    SectionPairRow row("hobbies", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
+    row.setKey("colors");
+
+    ASSERT_STREQ("colors", row.getKey().c_str());
+  }
 }