Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for non-covered lines #7

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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