From 2a89d53b9c8176817aedd8742d6315c78c24ea11 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 15:35:54 +0100 Subject: [PATCH 1/4] Add unit tests for File::get method --- tests/FileTest.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/FileTest.cpp b/tests/FileTest.cpp index dcc1bb6..7dba79a 100644 --- a/tests/FileTest.cpp +++ b/tests/FileTest.cpp @@ -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("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("Section1", "Entry2"), int()); +} + TEST_CASE("Create a section") { auto f = File{fileName}; From f31357b678b37d3f3b73845be7b120834cbcde3c Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 15:41:25 +0100 Subject: [PATCH 2/4] Check fqKey and key are equal for entries without parent --- tests/EntryTest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/EntryTest.cpp b/tests/EntryTest.cpp index 4290a7d..7291e74 100644 --- a/tests/EntryTest.cpp +++ b/tests/EntryTest.cpp @@ -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(), 42); const int a = 69; From d7843dc47355e276e50ce311b4f846fc7ad6a425 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 15:43:03 +0100 Subject: [PATCH 3/4] Test that non-existing sections are nullptr --- tests/FileTest.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/FileTest.cpp b/tests/FileTest.cpp index 7dba79a..0084fb5 100644 --- a/tests/FileTest.cpp +++ b/tests/FileTest.cpp @@ -116,6 +116,13 @@ TEST_CASE("Call findSection to get an existing Section") CHECK_EQ(section->findEntry("Entry1")->value(), "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("Equality operator") { const auto f = File{fileName}; From 90461f93ce7bb3eaa8472dc27f72aea4acd2799a Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 15:47:59 +0100 Subject: [PATCH 4/4] Add explicit unit tests for File::findEntry method --- tests/FileTest.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/FileTest.cpp b/tests/FileTest.cpp index 0084fb5..966b1bc 100644 --- a/tests/FileTest.cpp +++ b/tests/FileTest.cpp @@ -123,6 +123,21 @@ TEST_CASE("Call findSection to get a non-existing Section") 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(), "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};