Skip to content

Commit

Permalink
Add unit tests for non-covered lines (#7)
Browse files Browse the repository at this point in the history
These are trivial test cases (or extensions of existing ones) that
should lead to 100% line coverage in this version.
  • Loading branch information
Master92 authored Dec 5, 2023
2 parents 70967af + 90461f9 commit ff46174
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/EntryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TEST_CASE("Entry construction")

Entry meaningful("Blubb", 42);
CHECK_EQ(meaningful.key(), "Blubb");
CHECK_EQ(meaningful.key(), meaningful.fqKey());
CHECK_EQ(meaningful.value<int>(), 42);

const int a = 69;
Expand Down
34 changes: 34 additions & 0 deletions tests/FileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ TEST_CASE("Open file from static method")
CHECK_EQ(f, f2);
}

TEST_CASE("Get the value of an entry")
{
const auto f = File{fileName};
CHECK_EQ(f.get<std::string_view>("Section1", "Entry1"), "Value1"sv);
}

TEST_CASE("Get the value of an entry that doesn't exist")
{
const auto f = File{fileName};
CHECK_EQ(f.get<int>("Section1", "Entry2"), int());
}

TEST_CASE("Create a section")
{
auto f = File{fileName};
Expand Down Expand Up @@ -104,6 +116,28 @@ TEST_CASE("Call findSection to get an existing Section")
CHECK_EQ(section->findEntry("Entry1")->value<std::string_view>(), "Value1"sv);
}

TEST_CASE("Call findSection to get a non-existing Section")
{
const auto f = File{fileName};
const auto section = f.findSection("Section2");
CHECK_EQ(section, nullptr);
}

TEST_CASE("Call findEntry to get an existing Entry")
{
const auto f = File{fileName};
const auto entry = f.findEntry("Section1.Entry1");
REQUIRE(entry);
CHECK_EQ(entry->value<std::string_view>(), "Value1"sv);
}

TEST_CASE("Call findEntry with a non-existing section")
{
const auto f = File{fileName};
const auto entry = f.findEntry("Section2.Entry1");
CHECK_EQ(entry, nullptr);
}

TEST_CASE("Equality operator")
{
const auto f = File{fileName};
Expand Down

0 comments on commit ff46174

Please sign in to comment.