diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/fmt/test/compile-test.cc | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/fmt/test/compile-test.cc')
-rw-r--r-- | contrib/libs/fmt/test/compile-test.cc | 194 |
1 files changed, 97 insertions, 97 deletions
diff --git a/contrib/libs/fmt/test/compile-test.cc b/contrib/libs/fmt/test/compile-test.cc index 9bb9bb7d9e..ad23980e62 100644 --- a/contrib/libs/fmt/test/compile-test.cc +++ b/contrib/libs/fmt/test/compile-test.cc @@ -1,122 +1,122 @@ -// 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 <string> +// 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 <string> #include <type_traits> - + // Check that fmt/compile.h compiles with windows.h included before it. -#ifdef _WIN32 -# include <windows.h> -#endif - -#include "fmt/compile.h" -#include <gmock/gmock.h> -#include "gtest-extra.h" -#include "util.h" - -// compiletime_prepared_parts_type_provider is useful only with relaxed -// constexpr. -#if FMT_USE_CONSTEXPR -template <unsigned EXPECTED_PARTS_COUNT, typename Format> -void check_prepared_parts_type(Format format) { +#ifdef _WIN32 +# include <windows.h> +#endif + +#include "fmt/compile.h" +#include <gmock/gmock.h> +#include "gtest-extra.h" +#include "util.h" + +// compiletime_prepared_parts_type_provider is useful only with relaxed +// constexpr. +#if FMT_USE_CONSTEXPR +template <unsigned EXPECTED_PARTS_COUNT, typename Format> +void check_prepared_parts_type(Format format) { typedef fmt::detail::compiled_format_base<decltype(format)> provider; typedef fmt::detail::format_part<char> - expected_parts_type[EXPECTED_PARTS_COUNT]; - static_assert(std::is_same<typename provider::parts_container, - expected_parts_type>::value, - "CompileTimePreparedPartsTypeProvider test failed"); -} - -TEST(CompileTest, CompileTimePreparedPartsTypeProvider) { - check_prepared_parts_type<1u>(FMT_STRING("text")); - check_prepared_parts_type<1u>(FMT_STRING("{}")); - check_prepared_parts_type<2u>(FMT_STRING("text{}")); - check_prepared_parts_type<2u>(FMT_STRING("{}text")); - check_prepared_parts_type<3u>(FMT_STRING("text{}text")); - check_prepared_parts_type<3u>(FMT_STRING("{:{}.{}} {:{}}")); - - check_prepared_parts_type<3u>(FMT_STRING("{{{}}}")); // '{', 'argument', '}' - check_prepared_parts_type<2u>(FMT_STRING("text{{")); // 'text', '{' - check_prepared_parts_type<3u>(FMT_STRING("text{{ ")); // 'text', '{', ' ' - check_prepared_parts_type<2u>(FMT_STRING("}}text")); // '}', text - check_prepared_parts_type<2u>(FMT_STRING("text}}text")); // 'text}', 'text' - check_prepared_parts_type<4u>( - FMT_STRING("text{{}}text")); // 'text', '{', '}', 'text' -} -#endif - -TEST(CompileTest, PassStringLiteralFormat) { + expected_parts_type[EXPECTED_PARTS_COUNT]; + static_assert(std::is_same<typename provider::parts_container, + expected_parts_type>::value, + "CompileTimePreparedPartsTypeProvider test failed"); +} + +TEST(CompileTest, CompileTimePreparedPartsTypeProvider) { + check_prepared_parts_type<1u>(FMT_STRING("text")); + check_prepared_parts_type<1u>(FMT_STRING("{}")); + check_prepared_parts_type<2u>(FMT_STRING("text{}")); + check_prepared_parts_type<2u>(FMT_STRING("{}text")); + check_prepared_parts_type<3u>(FMT_STRING("text{}text")); + check_prepared_parts_type<3u>(FMT_STRING("{:{}.{}} {:{}}")); + + check_prepared_parts_type<3u>(FMT_STRING("{{{}}}")); // '{', 'argument', '}' + check_prepared_parts_type<2u>(FMT_STRING("text{{")); // 'text', '{' + check_prepared_parts_type<3u>(FMT_STRING("text{{ ")); // 'text', '{', ' ' + check_prepared_parts_type<2u>(FMT_STRING("}}text")); // '}', text + check_prepared_parts_type<2u>(FMT_STRING("text}}text")); // 'text}', 'text' + check_prepared_parts_type<4u>( + FMT_STRING("text{{}}text")); // 'text', '{', '}', 'text' +} +#endif + +TEST(CompileTest, PassStringLiteralFormat) { const auto prepared = fmt::detail::compile<int>("test {}"); - EXPECT_EQ("test 42", fmt::format(prepared, 42)); + EXPECT_EQ("test 42", fmt::format(prepared, 42)); const auto wprepared = fmt::detail::compile<int>(L"test {}"); - EXPECT_EQ(L"test 42", fmt::format(wprepared, 42)); -} - -TEST(CompileTest, FormatToArrayOfChars) { - char buffer[32] = {0}; + EXPECT_EQ(L"test 42", fmt::format(wprepared, 42)); +} + +TEST(CompileTest, FormatToArrayOfChars) { + char buffer[32] = {0}; const auto prepared = fmt::detail::compile<int>("4{}"); fmt::format_to(fmt::detail::make_checked(buffer, 32), prepared, 2); - EXPECT_EQ(std::string("42"), buffer); - wchar_t wbuffer[32] = {0}; + EXPECT_EQ(std::string("42"), buffer); + wchar_t wbuffer[32] = {0}; const auto wprepared = fmt::detail::compile<int>(L"4{}"); fmt::format_to(fmt::detail::make_checked(wbuffer, 32), wprepared, 2); - EXPECT_EQ(std::wstring(L"42"), wbuffer); -} - -TEST(CompileTest, FormatToIterator) { - std::string s(2, ' '); + EXPECT_EQ(std::wstring(L"42"), wbuffer); +} + +TEST(CompileTest, FormatToIterator) { + std::string s(2, ' '); const auto prepared = fmt::detail::compile<int>("4{}"); - fmt::format_to(s.begin(), prepared, 2); - EXPECT_EQ("42", s); - std::wstring ws(2, L' '); + fmt::format_to(s.begin(), prepared, 2); + EXPECT_EQ("42", s); + std::wstring ws(2, L' '); const auto wprepared = fmt::detail::compile<int>(L"4{}"); - fmt::format_to(ws.begin(), wprepared, 2); - EXPECT_EQ(L"42", ws); -} - -TEST(CompileTest, FormatToN) { - char buf[5]; + fmt::format_to(ws.begin(), wprepared, 2); + EXPECT_EQ(L"42", ws); +} + +TEST(CompileTest, FormatToN) { + char buf[5]; auto f = fmt::detail::compile<int>("{:10}"); - auto result = fmt::format_to_n(buf, 5, f, 42); - EXPECT_EQ(result.size, 10); - EXPECT_EQ(result.out, buf + 5); - EXPECT_EQ(fmt::string_view(buf, 5), " "); -} - -TEST(CompileTest, FormattedSize) { + auto result = fmt::format_to_n(buf, 5, f, 42); + EXPECT_EQ(result.size, 10); + EXPECT_EQ(result.out, buf + 5); + EXPECT_EQ(fmt::string_view(buf, 5), " "); +} + +TEST(CompileTest, FormattedSize) { auto f = fmt::detail::compile<int>("{:10}"); - EXPECT_EQ(fmt::formatted_size(f, 42), 10); -} - -TEST(CompileTest, MultipleTypes) { + EXPECT_EQ(fmt::formatted_size(f, 42), 10); +} + +TEST(CompileTest, MultipleTypes) { auto f = fmt::detail::compile<int, int>("{} {}"); - EXPECT_EQ(fmt::format(f, 42, 42), "42 42"); -} - + EXPECT_EQ(fmt::format(f, 42, 42), "42 42"); +} + struct test_formattable {}; - -FMT_BEGIN_NAMESPACE + +FMT_BEGIN_NAMESPACE template <> struct formatter<test_formattable> : formatter<const char*> { template <typename FormatContext> auto format(test_formattable, FormatContext& ctx) -> decltype(ctx.out()) { - return formatter<const char*>::format("foo", ctx); - } -}; -FMT_END_NAMESPACE - -TEST(CompileTest, FormatUserDefinedType) { + return formatter<const char*>::format("foo", ctx); + } +}; +FMT_END_NAMESPACE + +TEST(CompileTest, FormatUserDefinedType) { auto f = fmt::detail::compile<test_formattable>("{}"); EXPECT_EQ(fmt::format(f, test_formattable()), "foo"); -} - -TEST(CompileTest, EmptyFormatString) { +} + +TEST(CompileTest, EmptyFormatString) { auto f = fmt::detail::compile<>(""); - EXPECT_EQ(fmt::format(f), ""); -} + EXPECT_EQ(fmt::format(f), ""); +} #ifdef __cpp_if_constexpr TEST(CompileTest, FormatDefault) { |