2020-12-24 14:40:46 +00:00
|
|
|
// Formatting library for C++ - formatting library tests
|
|
|
|
//
|
|
|
|
// Copyright (c) 2012 - present, Victor Zverovich
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// For the license information refer to format.h.
|
|
|
|
|
|
|
|
#include <iterator>
|
2021-04-30 21:21:49 +00:00
|
|
|
#include <vector>
|
2020-12-24 14:40:46 +00:00
|
|
|
|
|
|
|
#include "fmt/chrono.h"
|
|
|
|
#include "fmt/color.h"
|
|
|
|
#include "fmt/format.h"
|
|
|
|
#include "fmt/ostream.h"
|
|
|
|
#include "fmt/ranges.h"
|
2021-05-29 16:37:17 +00:00
|
|
|
#include "fmt/xchar.h"
|
2020-12-24 14:40:46 +00:00
|
|
|
|
|
|
|
// Exercise the API to verify that everything we expect to can compile.
|
|
|
|
void test_format_api() {
|
2021-11-24 22:09:41 +00:00
|
|
|
(void)fmt::format(FMT_STRING("{}"), 42);
|
|
|
|
(void)fmt::format(FMT_STRING(L"{}"), 42);
|
|
|
|
(void)fmt::format(FMT_STRING("noop"));
|
2020-12-24 14:40:46 +00:00
|
|
|
|
2021-11-24 22:09:41 +00:00
|
|
|
(void)fmt::to_string(42);
|
|
|
|
(void)fmt::to_wstring(42);
|
2020-12-24 14:40:46 +00:00
|
|
|
|
2021-04-30 21:21:49 +00:00
|
|
|
std::vector<char> out;
|
2020-12-24 14:40:46 +00:00
|
|
|
fmt::format_to(std::back_inserter(out), FMT_STRING("{}"), 42);
|
|
|
|
|
|
|
|
char buffer[4];
|
|
|
|
fmt::format_to_n(buffer, 3, FMT_STRING("{}"), 12345);
|
|
|
|
|
|
|
|
wchar_t wbuffer[4];
|
|
|
|
fmt::format_to_n(wbuffer, 3, FMT_STRING(L"{}"), 12345);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_chrono() {
|
2021-11-24 22:09:41 +00:00
|
|
|
(void)fmt::format(FMT_STRING("{}"), std::chrono::seconds(42));
|
|
|
|
(void)fmt::format(FMT_STRING(L"{}"), std::chrono::seconds(42));
|
2020-12-24 14:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_text_style() {
|
|
|
|
fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
|
2021-11-24 22:09:41 +00:00
|
|
|
(void)fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
|
2020-12-24 14:40:46 +00:00
|
|
|
|
|
|
|
fmt::text_style ts = fg(fmt::rgb(255, 20, 30));
|
|
|
|
std::string out;
|
|
|
|
fmt::format_to(std::back_inserter(out), ts,
|
|
|
|
FMT_STRING("rgb(255,20,30){}{}{}"), 1, 2, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_range() {
|
2021-04-30 21:21:49 +00:00
|
|
|
std::vector<char> hello = {'h', 'e', 'l', 'l', 'o'};
|
2021-11-24 22:09:41 +00:00
|
|
|
(void)fmt::format(FMT_STRING("{}"), hello);
|
2020-12-24 14:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
test_format_api();
|
|
|
|
test_chrono();
|
|
|
|
test_text_style();
|
|
|
|
test_range();
|
|
|
|
}
|