mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-22 10:30:05 +00:00
Test examples.
This commit is contained in:
parent
a4f836e325
commit
5d4ef3387f
@ -774,6 +774,14 @@ TEST(FormatterTest, FormatDouble) {
|
||||
sprintf(buffer, "%E", 392.65);
|
||||
EXPECT_EQ(buffer, str(Format("{0:E}") << 392.65));
|
||||
EXPECT_EQ("+0000392.6", str(Format("{0:+010.4g}") << 392.65));
|
||||
double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
EXPECT_EQ("nan", str(Format("{}") << nan));
|
||||
EXPECT_EQ("-nan", str(Format("{}") << -nan));
|
||||
EXPECT_EQ("NAN", str(Format("{:F}") << nan));
|
||||
double inf = std::numeric_limits<double>::infinity();
|
||||
EXPECT_EQ("inf", str(Format("{}") << inf));
|
||||
EXPECT_EQ("-inf", str(Format("{}") << -inf));
|
||||
EXPECT_EQ("INF", str(Format("{:F}") << inf));
|
||||
}
|
||||
|
||||
TEST(FormatterTest, FormatLongDouble) {
|
||||
@ -995,7 +1003,43 @@ fmt::TempFormatter<PrintError> ReportError(const char *format) {
|
||||
return fmt::TempFormatter<PrintError>(format);
|
||||
}
|
||||
|
||||
TEST(TempFormatterTest, Example) {
|
||||
TEST(TempFormatterTest, Examples) {
|
||||
EXPECT_EQ("First, thou shalt count to three",
|
||||
str(Format("First, thou shalt count to {0}") << "three"));
|
||||
EXPECT_EQ("Bring me a shrubbery",
|
||||
str(Format("Bring me a {}") << "shrubbery"));
|
||||
EXPECT_EQ("From 1 to 3", str(Format("From {} to {}") << 1 << 3));
|
||||
|
||||
char buffer[256];
|
||||
sprintf(buffer, "%03.2f", -1.2);
|
||||
EXPECT_EQ(buffer, str(Format("{:03.2f}") << -1.2));
|
||||
|
||||
EXPECT_EQ("a, b, c", str(Format("{0}, {1}, {2}") << 'a' << 'b' << 'c'));
|
||||
EXPECT_EQ("a, b, c", str(Format("{}, {}, {}") << 'a' << 'b' << 'c'));
|
||||
EXPECT_EQ("c, b, a", str(Format("{2}, {1}, {0}") << 'a' << 'b' << 'c'));
|
||||
EXPECT_EQ("abracadabra", str(Format("{0}{1}{0}") << "abra" << "cad"));
|
||||
|
||||
EXPECT_EQ("left aligned ",
|
||||
str(Format("{:<30}") << "left aligned"));
|
||||
EXPECT_EQ(" right aligned",
|
||||
str(Format("{:>30}") << "right aligned"));
|
||||
EXPECT_EQ(" centered ",
|
||||
str(Format("{:^30}") << "centered"));
|
||||
EXPECT_EQ("***********centered***********",
|
||||
str(Format("{:*^30}") << "centered"));
|
||||
|
||||
EXPECT_EQ("+3.140000; -3.140000",
|
||||
str(Format("{:+f}; {:+f}") << 3.14 << -3.14));
|
||||
EXPECT_EQ(" 3.140000; -3.140000",
|
||||
str(Format("{: f}; {: f}") << 3.14 << -3.14));
|
||||
EXPECT_EQ("3.140000; -3.140000",
|
||||
str(Format("{:-f}; {:-f}") << 3.14 << -3.14));
|
||||
|
||||
EXPECT_EQ("int: 42; hex: 2a; oct: 52",
|
||||
str(Format("int: {0:d}; hex: {0:x}; oct: {0:o}") << 42));
|
||||
EXPECT_EQ("int: 42; hex: 0x2a; oct: 052",
|
||||
str(Format("int: {0:d}; hex: {0:#x}; oct: {0:#o}") << 42));
|
||||
|
||||
std::string path = "somefile";
|
||||
ReportError("File not found: {0}") << path;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user