| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // format_test.cxx
- // logger_test
- //
- // Created by Sam Jaffe on 4/4/19.
- //
- #include <gmock/gmock.h>
- #include "logger/exception.h"
- #include "logger/format.h"
- using namespace logging;
- TEST(FormatTest, EmptyFormatterCanParse) {
- EXPECT_NO_THROW(format::parse_format_string(""));
- }
- TEST(FormatTest, ThrowsForEndOfStringAfterPct) {
- EXPECT_THROW(format::parse_format_string("%"),
- format_parsing_exception);
- }
- TEST(FormatTest, RawStringFmtReturnsSelf) {
- using testing::Eq;
- auto fmt = format::parse_format_string("TEST STRING");
- EXPECT_THAT(fmt.process({}), Eq("TEST STRING"));
- }
- TEST(FormatTest, NCharReturnsNewLine) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%n");
- EXPECT_THAT(fmt.process({}), Eq("\n"));
- }
- TEST(FormatTest, DoublePctIsLiteral) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%%");
- EXPECT_THAT(fmt.process({}), Eq("%"));
- }
- TEST(FormatTest, CatchesRawContentBeforeFmt) {
- using testing::Eq;
- auto fmt = format::parse_format_string("TEST%%");
- EXPECT_THAT(fmt.process({}), Eq("TEST%"));
- }
- TEST(FormatTest, CatchesRawContentAfterFmt) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%%TEST");
- EXPECT_THAT(fmt.process({}), Eq("%TEST"));
- }
- // Thursday, April 4, 2019 6:17:20 PM GMT
- constexpr const int NOW = 1554401840;
- TEST(FormatTest, HandlesDateFormatter) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%d");
- EXPECT_THAT(fmt.process({{NOW,0}}), Eq("2019-04-04 18:17:20,000"));
- }
- TEST(FormatTest, FormatsMilliseconds) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%d");
- EXPECT_THAT(fmt.process({{NOW,123000}}), Eq("2019-04-04 18:17:20,123"));
- }
- TEST(FormatTest, ThrowsIfCustomFmtUnterminated) {
- using testing::Eq;
- EXPECT_THROW(format::parse_format_string("%d{%"),
- format_parsing_exception);
- }
- TEST(FormatTest, SupportsCustomFormatWithBrace) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%d{%Y}");
- EXPECT_THAT(fmt.process({{NOW,0}}), Eq("2019"));
- }
- TEST(FormatTest, FormatsCustomMilliseconds) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%d{%_ms}");
- EXPECT_THAT(fmt.process({{NOW,123000}}), Eq("123"));
- }
- TEST(FormatTest, SupportsISO8601Format) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%d{ISO8601}");
- EXPECT_THAT(fmt.process({{NOW,0}}), Eq("2019-04-04T18:17:20.000Z"));
- }
- TEST(FormatTest, SupportsSingleDayFormat) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%d{ABSOLUTE}");
- EXPECT_THAT(fmt.process({{NOW,0}}), Eq("18:17:20,000"));
- }
- TEST(FormatTest, SupportsHumanDateFormat) {
- using testing::Eq;
- auto fmt = format::parse_format_string("%d{DATE}");
- EXPECT_THAT(fmt.process({{NOW,0}}), Eq("04 Apr 2019 18:17:20,000"));
- }
|