File: time-test.cc

package info (click to toggle)
cppformat 3.0.1%2Bds-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 844 kB
  • sloc: cpp: 8,205; python: 77; sh: 12; makefile: 8; ansic: 4
file content (33 lines) | stat: -rw-r--r-- 670 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 Time formatting tests

 Copyright (c) 2012 - 2016, Victor Zverovich
 All rights reserved.

 For the license information refer to format.h.
 */

#include "gmock/gmock.h"
#include "fmt/time.h"

TEST(TimeTest, Format) {
  std::tm tm = std::tm();
  tm.tm_year = 116;
  tm.tm_mon  = 3;
  tm.tm_mday = 25;
  EXPECT_EQ("The date is 2016-04-25.",
            fmt::format("The date is {:%Y-%m-%d}.", tm));
}

TEST(TimeTest, GrowBuffer) {
  std::string s = "{:";
  for (int i = 0; i < 30; ++i)
    s += "%c";
  s += "}\n";
  std::time_t t = std::time(0);
  fmt::format(s, *std::localtime(&t));
}

TEST(TimeTest, EmptyResult) {
  EXPECT_EQ("", fmt::format("{}", std::tm()));
}