Skip to content

Commit

Permalink
test: date module testcase
Browse files Browse the repository at this point in the history
* testcase added to date module for codecov

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 committed Aug 16, 2024
1 parent 222c890 commit 6db2b54
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/faker-cxx/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace faker::date
Timestamp,
};

std::string betweenDate(const auto& from, const auto& to, DateFormat dateFormat);

/**
* @brief Generates a random date in the past.
*
Expand Down
23 changes: 23 additions & 0 deletions tests/modules/date_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ class DateTest : public Test
}
};



TEST_F(DateTest, shouldThrowRuntimeError)
{
const auto startDate = std::chrono::system_clock::now() + std::chrono::hours{1};

const auto endDate = startDate + std::chrono::hours{24 * 365 * 2};

EXPECT_THROW({
try {
betweenDate(endDate, startDate, DateFormat::ISO);
}
catch (const runtimeError& err) {
EXPECT_STREQ( common::format("Start date is greater than end date. {{from: {}, to: {}}}",
serializeTimePoint(endDate, DateFormat::ISO),
serializeTimePoint(startDate, DateFormat::ISO)),
err.what());
throw;
}
}, runtimeError );
}


TEST_F(DateTest, shouldGeneratePastDateISO)
{
const auto currentDate = std::chrono::system_clock::now();
Expand Down

0 comments on commit 6db2b54

Please sign in to comment.