diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/fmt/test/enforce-checks-test.cc | |
parent | Initial commit. (diff) | |
download | ceph-b26c4052f3542036551aa9dec9caa4226e456195.tar.xz ceph-b26c4052f3542036551aa9dec9caa4226e456195.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/fmt/test/enforce-checks-test.cc')
-rw-r--r-- | src/fmt/test/enforce-checks-test.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/fmt/test/enforce-checks-test.cc b/src/fmt/test/enforce-checks-test.cc new file mode 100644 index 000000000..c77cb142f --- /dev/null +++ b/src/fmt/test/enforce-checks-test.cc @@ -0,0 +1,63 @@ +// 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> +#include <vector> + +#include "fmt/chrono.h" +#include "fmt/color.h" +#include "fmt/format.h" +#include "fmt/ostream.h" +#include "fmt/ranges.h" +#include "fmt/xchar.h" + +// Exercise the API to verify that everything we expect to can compile. +void test_format_api() { + (void)fmt::format(FMT_STRING("{}"), 42); + (void)fmt::format(FMT_STRING(L"{}"), 42); + (void)fmt::format(FMT_STRING("noop")); + + (void)fmt::to_string(42); + (void)fmt::to_wstring(42); + + std::vector<char> out; + 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() { + (void)fmt::format(FMT_STRING("{}"), std::chrono::seconds(42)); + (void)fmt::format(FMT_STRING(L"{}"), std::chrono::seconds(42)); +} + +void test_text_style() { + fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)"); + (void)fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), + "rgb(255,20,30)"); + + 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() { + std::vector<char> hello = {'h', 'e', 'l', 'l', 'o'}; + (void)fmt::format(FMT_STRING("{}"), hello); +} + +int main() { + test_format_api(); + test_chrono(); + test_text_style(); + test_range(); +} |