From 9393fe26f6768e60aea75243d4ce50b0dd08a5a7 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 25 Jul 2019 19:01:21 +0300 Subject: [PATCH] prepare -> compile --- CMakeLists.txt | 5 +- include/fmt/{prepare.h => compile.h} | 22 +++--- test/CMakeLists.txt | 8 +- .../CMakeLists.txt | 0 test/{prepare-test.cc => compile-test.cc} | 74 +++++++++---------- 5 files changed, 55 insertions(+), 54 deletions(-) rename include/fmt/{prepare.h => compile.h} (98%) rename test/{compile-test => compile-error-test}/CMakeLists.txt (100%) rename test/{prepare-test.cc => compile-test.cc} (91%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2aaed4de..6e08aa5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,8 +151,9 @@ function(add_headers VAR) endfunction() # Define the fmt library, its includes and the needed defines. -add_headers(FMT_HEADERS chrono.h color.h core.h format.h format-inl.h locale.h - ostream.h prepare.h printf.h ranges.h safe-duration-cast.h) +add_headers(FMT_HEADERS chrono.h color.h compile.h core.h format.h format-inl.h + locale.h ostream.h printf.h ranges.h + safe-duration-cast.h) set(FMT_SOURCES src/format.cc) if (HAVE_OPEN) add_headers(FMT_HEADERS posix.h) diff --git a/include/fmt/prepare.h b/include/fmt/compile.h similarity index 98% rename from include/fmt/prepare.h rename to include/fmt/compile.h index 7e144116..56b486f5 100644 --- a/include/fmt/prepare.h +++ b/include/fmt/compile.h @@ -5,8 +5,8 @@ // // For the license information refer to format.h. -#ifndef FMT_PREPARE_H_ -#define FMT_PREPARE_H_ +#ifndef FMT_COMPILE_H_ +#define FMT_COMPILE_H_ #ifndef FMT_HAS_CONSTRUCTIBLE_TRAITS # define FMT_HAS_CONSTRUCTIBLE_TRAITS \ @@ -728,41 +728,41 @@ using wprepared_format_t = #if FMT_USE_CONSTEXPR template -FMT_CONSTEXPR auto prepare(Format format) { +FMT_CONSTEXPR auto compile(Format format) { return internal::do_prepare( typename internal::format_tag::type{}, std::move(format)); } #else template -auto prepare(Format format) -> +auto compile(Format format) -> typename internal::preparator::prepared_format_type { return internal::preparator::prepare(std::move(format)); } #endif template -auto prepare(const Char* format) -> +auto compile(const Char* format) -> typename internal::preparator, Args...>::prepared_format_type { - return prepare(internal::to_runtime_format(format)); + return compile(internal::to_runtime_format(format)); } template -auto prepare(const Char(format)[N]) -> +auto compile(const Char(format)[N]) -> typename internal::preparator, Args...>::prepared_format_type { const auto view = basic_string_view(format, N); - return prepare(internal::to_runtime_format(view)); + return compile(internal::to_runtime_format(view)); } template -auto prepare(basic_string_view format) -> +auto compile(basic_string_view format) -> typename internal::preparator, Args...>::prepared_format_type { - return prepare(internal::to_runtime_format(format)); + return compile(internal::to_runtime_format(format)); } FMT_END_NAMESPACE -#endif // FMT_PREPARE_H_ +#endif // FMT_COMPILE_H_ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f2ee8098..e399096f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -101,7 +101,7 @@ if (NOT (MSVC AND BUILD_SHARED_LIBS)) endif () add_fmt_test(locale-test) add_fmt_test(ostream-test) -add_fmt_test(prepare-test) +add_fmt_test(compile-test) add_fmt_test(printf-test) add_fmt_test(custom-formatter-test) add_fmt_test(ranges-test) @@ -180,10 +180,10 @@ if (FMT_PEDANTIC) target_include_directories(no-windows-h-test SYSTEM PUBLIC gtest gmock) endif () - add_test(compile-test ${CMAKE_CTEST_COMMAND} + add_test(compile-error-test ${CMAKE_CTEST_COMMAND} --build-and-test - "${CMAKE_CURRENT_SOURCE_DIR}/compile-test" - "${CMAKE_CURRENT_BINARY_DIR}/compile-test" + "${CMAKE_CURRENT_SOURCE_DIR}/compile-error-test" + "${CMAKE_CURRENT_BINARY_DIR}/compile-error-test" --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options diff --git a/test/compile-test/CMakeLists.txt b/test/compile-error-test/CMakeLists.txt similarity index 100% rename from test/compile-test/CMakeLists.txt rename to test/compile-error-test/CMakeLists.txt diff --git a/test/prepare-test.cc b/test/compile-test.cc similarity index 91% rename from test/prepare-test.cc rename to test/compile-test.cc index 1839807e..e3fdec09 100644 --- a/test/prepare-test.cc +++ b/test/compile-test.cc @@ -3,7 +3,7 @@ // Copyright (c) 2012 - present, Victor Zverovich // All rights reserved. // -// For the license information refer to prepare.h. +// For the license information refer to format.h. #include #include @@ -16,12 +16,12 @@ #include #include -// Check if fmt/prepare.h compiles with windows.h included before it. +// Check if fmt/compile.h compiles with windows.h included before it. #ifdef _WIN32 # include #endif -#include "fmt/prepare.h" +#include "fmt/compile.h" #include "gmock.h" #include "gtest-extra.h" #include "mock-allocator.h" @@ -434,11 +434,11 @@ TEST(PrepareTest, CompileTimePreparedPartsTypeProvider) { // Use the struct instead of a function to workaround GCC 4.4's 'sorry, // unimplemented: mangling template_id_expr' issue. template struct copied_prepared_format_creator { - static decltype(fmt::prepare(std::declval())) make( + static decltype(fmt::compile(std::declval())) make( std::string format_str) { - auto prepared_format = fmt::prepare(std::move(format_str)); + auto prepared_format = fmt::compile(std::move(format_str)); auto copied_prepared_format = prepared_format; - prepared_format = fmt::prepare(""); + prepared_format = fmt::compile(""); return copied_prepared_format; } @@ -478,9 +478,9 @@ TEST(PrepareTest, CopyPreparedFormat_InternalStringViewsAreNotInvalidated) { TEST(PrepareTest, ReusedPreparedFormatType) { typedef fmt::prepared_format::type prepared_format; - prepared_format prepared = fmt::prepare("The {} is {}."); + prepared_format prepared = fmt::compile("The {} is {}."); EXPECT_EQ("The answer is 42.", prepared.format("answer", 42)); - prepared = fmt::prepare("40 {} 2 = {}"); + prepared = fmt::compile("40 {} 2 = {}"); EXPECT_EQ("40 + 2 = 42", prepared.format("+", 42)); } @@ -491,9 +491,9 @@ TEST(PrepareTest, UserProvidedPartsContainerUnderlyingContainer) { typedef fmt::basic_prepared_format::type prepared_format; - prepared_format prepared = fmt::prepare("The {} is {}."); + prepared_format prepared = fmt::compile("The {} is {}."); EXPECT_EQ("The answer is 42.", prepared.format("answer", 42)); - prepared = fmt::prepare("40 {} 2 = {}"); + prepared = fmt::compile("40 {} 2 = {}"); EXPECT_EQ("40 + 2 = 42", prepared.format("+", 42)); } @@ -535,67 +535,67 @@ TEST(PrepareTest, UserProvidedPartsContainer) { typedef fmt::basic_prepared_format::type prepared_format; - prepared_format prepared = fmt::prepare("The {} is {}."); + prepared_format prepared = fmt::compile("The {} is {}."); EXPECT_EQ("The answer is 42.", prepared.format("answer", 42)); - prepared = fmt::prepare("40 {} 2 = {}"); + prepared = fmt::compile("40 {} 2 = {}"); EXPECT_EQ("40 + 2 = 42", prepared.format("+", 42)); } TEST(PrepareTest, PassConstCharPointerFormat) { const char* c_format = "test {}"; - const auto prepared = fmt::prepare(c_format); + const auto prepared = fmt::compile(c_format); EXPECT_EQ("test 42", prepared.format(42)); const wchar_t* wc_format = L"test {}"; - const auto wprepared = fmt::prepare(wc_format); + const auto wprepared = fmt::compile(wc_format); EXPECT_EQ(L"test 42", wprepared.format(42)); } TEST(PrepareTest, PassCharArrayFormat) { char c_format[] = "test {}"; - const auto prepared = fmt::prepare(c_format); + const auto prepared = fmt::compile(c_format); EXPECT_EQ("test 42", prepared.format(42)); wchar_t wc_format[] = L"test {}"; - const auto wprepared = fmt::prepare(wc_format); + const auto wprepared = fmt::compile(wc_format); EXPECT_EQ(L"test 42", wprepared.format(42)); } TEST(PrepareTest, PassConstCharArrayFormat) { const char c_format[] = "test {}"; - const auto prepared = fmt::prepare(c_format); + const auto prepared = fmt::compile(c_format); EXPECT_EQ("test 42", prepared.format(42)); const wchar_t wc_format[] = L"test {}"; - const auto wprepared = fmt::prepare(wc_format); + const auto wprepared = fmt::compile(wc_format); EXPECT_EQ(L"test 42", wprepared.format(42)); } TEST(PrepareTest, PassStringLiteralFormat) { - const auto prepared = fmt::prepare("test {}"); + const auto prepared = fmt::compile("test {}"); EXPECT_EQ("test 42", prepared.format(42)); - const auto wprepared = fmt::prepare(L"test {}"); + const auto wprepared = fmt::compile(L"test {}"); EXPECT_EQ(L"test 42", wprepared.format(42)); } TEST(PrepareTest, PassStringViewFormat) { const auto prepared = - fmt::prepare(fmt::basic_string_view("test {}")); + fmt::compile(fmt::basic_string_view("test {}")); EXPECT_EQ("test 42", prepared.format(42)); const auto wprepared = - fmt::prepare(fmt::basic_string_view(L"test {}")); + fmt::compile(fmt::basic_string_view(L"test {}")); EXPECT_EQ(L"test 42", wprepared.format(42)); } TEST(PrepareTest, PassBasicStringFormat) { - const auto prepared = fmt::prepare(std::string("test {}")); + const auto prepared = fmt::compile(std::string("test {}")); EXPECT_EQ("test 42", prepared.format(42)); - const auto wprepared = fmt::prepare(std::wstring(L"test {}")); + const auto wprepared = fmt::compile(std::wstring(L"test {}")); EXPECT_EQ(L"test 42", wprepared.format(42)); } #if FMT_USE_CONSTEXPR TEST(PrepareTest, PassCompileString) { - const auto prepared = fmt::prepare(FMT_STRING("test {}")); + const auto prepared = fmt::compile(FMT_STRING("test {}")); EXPECT_EQ("test 42", prepared.format(42)); - const auto wprepared = fmt::prepare(FMT_STRING(L"test {}")); + const auto wprepared = fmt::compile(FMT_STRING(L"test {}")); EXPECT_EQ(L"test 42", wprepared.format(42)); } #endif @@ -634,61 +634,61 @@ template struct user_allocator { TEST(PrepareTest, PassUserTypeFormat) { typedef std::basic_string, user_allocator> user_format; - const auto prepared = fmt::prepare(user_format("test {}")); + const auto prepared = fmt::compile(user_format("test {}")); EXPECT_EQ("test 42", prepared.format(42)); } TEST(PrepareTest, FormatToArrayOfChars) { char buffer[32] = {0}; - const auto prepared = fmt::prepare("4{}"); + const auto prepared = fmt::compile("4{}"); prepared.format_to(buffer, 2); EXPECT_EQ(std::string("42"), buffer); wchar_t wbuffer[32] = {0}; - const auto wprepared = fmt::prepare(L"4{}"); + const auto wprepared = fmt::compile(L"4{}"); wprepared.format_to(wbuffer, 2); EXPECT_EQ(std::wstring(L"42"), wbuffer); } TEST(PrepareTest, FormatToIterator) { std::string s(2, ' '); - const auto prepared = fmt::prepare("4{}"); + const auto prepared = fmt::compile("4{}"); prepared.format_to(s.begin(), 2); EXPECT_EQ("42", s); std::wstring ws(2, L' '); - const auto wprepared = fmt::prepare(L"4{}"); + const auto wprepared = fmt::compile(L"4{}"); wprepared.format_to(ws.begin(), 2); EXPECT_EQ(L"42", ws); } TEST(PrepareTest, FormatToBackInserter) { std::string s; - const auto prepared = fmt::prepare("4{}"); + const auto prepared = fmt::compile("4{}"); prepared.format_to(std::back_inserter(s), 2); EXPECT_EQ("42", s); std::wstring ws; - const auto wprepared = fmt::prepare(L"4{}"); + const auto wprepared = fmt::compile(L"4{}"); wprepared.format_to(std::back_inserter(ws), 2); EXPECT_EQ(L"42", ws); } TEST(PrepareTest, FormatToBasicMemoryBuffer) { fmt::basic_memory_buffer buffer; - const auto prepared = fmt::prepare("4{}"); + const auto prepared = fmt::compile("4{}"); prepared.format_to(buffer, 2); EXPECT_EQ("42", to_string(buffer)); fmt::basic_memory_buffer wbuffer; - const auto wprepared = fmt::prepare(L"4{}"); + const auto wprepared = fmt::compile(L"4{}"); wprepared.format_to(wbuffer, 2); EXPECT_EQ(L"42", to_string(wbuffer)); } TEST(PrepareTest, FormatToMemoryBuffer) { fmt::memory_buffer buffer; - const auto prepared = fmt::prepare("4{}"); + const auto prepared = fmt::compile("4{}"); prepared.format_to(buffer, 2); EXPECT_EQ("42", to_string(buffer)); fmt::wmemory_buffer wbuffer; - const auto wprepared = fmt::prepare(L"4{}"); + const auto wprepared = fmt::compile(L"4{}"); wprepared.format_to(wbuffer, 2); EXPECT_EQ(L"42", to_string(wbuffer)); }