Skip to content

Commit

Permalink
test: enhance code coverage of format helper module by adding additio…
Browse files Browse the repository at this point in the history
…nal testcases (#802)

* add missing testcases for word.cpp for improving coverage

* add missing testcases for format_helper module to improve coverage
  • Loading branch information
pixelcaliber authored Jul 15, 2024
1 parent ef1cfae commit 540cea8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/common/format_helper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,32 @@ TEST_F(FormatHelperTest, shouldFormat)
EXPECT_EQ(format("{} {}", "Hello", "World"), "Hello World");
EXPECT_EQ(format("{0} {1}", "Hello", "World"), "Hello World");
}

TEST_F(FormatHelperTest, ThrowsExceptionForMissingTokenGenerator)
{
const auto format = "{existing} {missing}";
const auto dataGeneratorsMapping = std::unordered_map<std::string, std::function<std::string()>>{
{"existing", []() { return "value"; }}
};

try {
fillTokenValues(format, dataGeneratorsMapping);
FAIL() << "Expected std::runtime_error";
}
catch (const std::runtime_error& e) {
EXPECT_STREQ(e.what(), "Generator not found for token missing.");
}
}

TEST_F(FormatHelperTest, PrecisionFormat)
{
EXPECT_EQ(precisionFormat(Precision::ZeroDp, 3.14159), "3");
EXPECT_EQ(precisionFormat(Precision::OneDp, 3.14159), "3.1");
EXPECT_EQ(precisionFormat(Precision::FiveDp, 3.14159), "3.14159");
EXPECT_EQ(precisionFormat(Precision::SevenDp, 3.14159), "3.1415900");
}

TEST_F(FormatHelperTest, ThrowsForInvalidPrecision)
{
EXPECT_THROW(precisionFormat(static_cast<Precision>(999), 3.14159), std::invalid_argument);
}

0 comments on commit 540cea8

Please sign in to comment.