diff options
author | Pavel Labath <labath@google.com> | 2017-02-07 18:11:33 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2017-02-07 18:11:33 +0000 |
commit | 24cb6548e5fbf22841128db4cdcbaef2bf64f1b8 (patch) | |
tree | 0e9d941d4a1c9398b855f4bc73ca85c5b2e60f31 /llvm/unittests/Support | |
parent | 8c99ca3df086ad4c4d1682dc28439639d24950ad (diff) | |
download | bcm5719-llvm-24cb6548e5fbf22841128db4cdcbaef2bf64f1b8.tar.gz bcm5719-llvm-24cb6548e5fbf22841128db4cdcbaef2bf64f1b8.zip |
[Support] Add FormatVariadic support for chrono types
Summary:
The formatter has three knobs:
- the user can choose which time unit to use for formatting (default: whatever is the unit of the input)
- he can choose whether the unit gets displayed (default: yes)
- he can affect the way the number itself is formatted via standard number formatting options (default:default)
Reviewers: zturner, inglorion
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D29481
llvm-svn: 294326
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r-- | llvm/unittests/Support/Chrono.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Chrono.cpp b/llvm/unittests/Support/Chrono.cpp index 3d578780756..1410baf848b 100644 --- a/llvm/unittests/Support/Chrono.cpp +++ b/llvm/unittests/Support/Chrono.cpp @@ -9,6 +9,7 @@ #include "llvm/Support/Chrono.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/FormatVariadic.h" #include "gtest/gtest.h" using namespace llvm; @@ -76,4 +77,34 @@ TEST(Chrono, ImplicitConversions) { EXPECT_EQ(TimeT, toTimeT(Nano)); } +TEST(Chrono, DurationFormat) { + EXPECT_EQ("1 h", formatv("{0}", hours(1)).str()); + EXPECT_EQ("1 m", formatv("{0}", minutes(1)).str()); + EXPECT_EQ("1 s", formatv("{0}", seconds(1)).str()); + EXPECT_EQ("1 ms", formatv("{0}", milliseconds(1)).str()); + EXPECT_EQ("1 us", formatv("{0}", microseconds(1)).str()); + EXPECT_EQ("1 ns", formatv("{0}", nanoseconds(1)).str()); + + EXPECT_EQ("1 s", formatv("{0:+}", seconds(1)).str()); + EXPECT_EQ("1", formatv("{0:-}", seconds(1)).str()); + + EXPECT_EQ("1000 ms", formatv("{0:ms}", seconds(1)).str()); + EXPECT_EQ("1000000 us", formatv("{0:us}", seconds(1)).str()); + EXPECT_EQ("1000", formatv("{0:ms-}", seconds(1)).str()); + + EXPECT_EQ("1,000 ms", formatv("{0:+n}", milliseconds(1000)).str()); + EXPECT_EQ("0x3e8", formatv("{0:-x}", milliseconds(1000)).str()); + EXPECT_EQ("010", formatv("{0:-3}", milliseconds(10)).str()); + EXPECT_EQ("10,000", formatv("{0:ms-n}", seconds(10)).str()); + + EXPECT_EQ("1.00 s", formatv("{0}", duration<float>(1)).str()); + EXPECT_EQ("0.123 s", formatv("{0:+3}", duration<float>(0.123f)).str()); + EXPECT_EQ("1.230e-01 s", formatv("{0:+e3}", duration<float>(0.123f)).str()); + + typedef duration<float, std::ratio<60 * 60 * 24 * 14, 1000000>> + microfortnights; + EXPECT_EQ("1.00", formatv("{0:-}", microfortnights(1)).str()); + EXPECT_EQ("1209.60 ms", formatv("{0:ms}", microfortnights(1)).str()); +} + } // anonymous namespace |