Browse Source

Provide fuzzy test for localtime/timezone.

Sam Jaffe 5 years ago
parent
commit
61b5734c23
1 changed files with 14 additions and 0 deletions
  1. 14 0
      test/pattern_layout_test.cxx

+ 14 - 0
test/pattern_layout_test.cxx

@@ -103,6 +103,20 @@ TEST(PatternLayoutTest, FormatsCustomMilliseconds) {
   EXPECT_THAT(DoFormat("%d{%_ms}", {{NOW,123000}}), Eq("123"));
 }
 
+MATCHER(IsTimeZoneOffsetLike, "") {
+  if (arg[0] != '+' && arg[0] != '-') {
+    (*result_listener) << "A timezone should be +/- hhmm";
+    return false;
+  }
+  int const hours = std::stoi(arg.substr(1, 2));
+  int const minutes = std::stoi(arg.substr(3, 2));
+  return hours <= 12 && minutes < 60;
+}
+
+TEST(PatternLayoutTest, FormatsTimeZone) {
+  EXPECT_THAT(DoFormat("%d{%z}", {{NOW,0}}), IsTimeZoneOffsetLike());
+}
+
 TEST(PatternLayoutTest, SupportsISO8601Format) {
   using testing::Eq;
   EXPECT_THAT(DoFormat("%d{ISO8601}", {{NOW,0}}),