Skip to content

Commit

Permalink
Add tests for exceptionWhenDuplicateField option
Browse files Browse the repository at this point in the history
  • Loading branch information
amelsmajic committed Jan 10, 2024
1 parent 0ce7c7f commit a652744
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/test_inifile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ TEST_CASE("parse section with duplicate field", "IniFile")
REQUIRE(inif["Foo"]["bar"].as<std::string>() == "world");
}

TEST_CASE("parse section with duplicate field and exceptionWhenDuplicateField_ set to disabled", "IniFile")
{
ini::IniFile inif;
inif.setExceptionWhenDuplicateField(false);
inif.decode("[Foo]\nbar=hello\nbar=world");

REQUIRE(inif.size() == 1);
REQUIRE(inif["Foo"].size() == 1);
REQUIRE(inif["Foo"]["bar"].as<std::string>() == "world");
}

TEST_CASE("parse field as bool", "IniFile")
{
std::istringstream ss("[Foo]\nbar1=true\nbar2=false\nbar3=tRuE");
Expand Down Expand Up @@ -865,3 +876,10 @@ TEST_CASE("spaces are not taken into account in sections", "IniFile")

REQUIRE(inif.find("Foo") != inif.end());
}

TEST_CASE("parse section with duplicate field and exceptionWhenDuplicateField_ set to enabled", "IniFile")
{
ini::IniFile inif;
inif.setExceptionWhenDuplicateField(true);
REQUIRE_THROWS(inif.decode("[Foo]\nbar=hello\nbar=world"));
}

0 comments on commit a652744

Please sign in to comment.