From e606ce9e7511c2ba8be1d0eb3f5eef68369b5e72 Mon Sep 17 00:00:00 2001 From: Matt Stephanson Date: Wed, 16 Jun 2021 23:37:11 -0700 Subject: [PATCH 1/4] Estimate width of aligned chronat strings --- stl/inc/chrono | 6 ++++-- .../P0355R7_calendars_and_time_zones_formatting/test.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/stl/inc/chrono b/stl/inc/chrono index db51955928..3906e3b48e 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -5966,8 +5966,10 @@ namespace chrono { } } - return _Write_aligned(_STD move(_FormatCtx.out()), static_cast(_Stream.view().size()), _Specs, - _Fmt_align::_Left, [&](auto _Out) { return _Fmt_write(_STD move(_Out), _Stream.view()); }); + int _Estimated_width = -1; + (void) _Measure_string_prefix(_Stream.view(), _Estimated_width); + return _Write_aligned(_STD move(_FormatCtx.out()), _Estimated_width, _Specs, _Fmt_align::_Left, + [&](auto _Out) { return _Fmt_write(_STD move(_Out), _Stream.view()); }); } // This echoes the functionality of put_time, but is able to handle invalid dates (when !ok()) since the diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp index b16ef15005..2c2148ae45 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -884,6 +885,11 @@ void test_zoned_time_formatter() { assert(format(STR("{:%g %G %U %V %W}"), zt) == STR("21 2021 16 16 16")); } +void test_locale() { + assert(format(locale{"zh-CN"}, L"{:^22%Y %B %d %A}", 2021y / June / 16d) + == L" 2021 \u516D\u6708 16 \u661F\u671F\u4E09 "); +} + void test() { test_parse_conversion_spec(); test_parse_conversion_spec(); @@ -955,6 +961,8 @@ void test() { test_zoned_time_formatter(); test_zoned_time_formatter(); + + test_locale(); } int main() { From fac1b8f42f82dfb4bc1cb71b14b142afd653f005 Mon Sep 17 00:00:00 2001 From: Matt Stephanson Date: Wed, 16 Jun 2021 23:52:53 -0700 Subject: [PATCH 2/4] guard against IDL mismatch --- .../P0355R7_calendars_and_time_zones_formatting/test.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp index 2c2148ae45..ce710a8ad9 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp @@ -30,6 +30,13 @@ template #define STR(Literal) (choose_literal(Literal, L##Literal)) +// Test against IDL mismatch between the DLL which stores the locale and the code which uses it. +#ifdef _DEBUG +#define DEFAULT_IDL_SETTING 2 +#else +#define DEFAULT_IDL_SETTING 0 +#endif + template struct testing_callbacks { _Fmt_align expected_alignment = _Fmt_align::_None; @@ -962,7 +969,9 @@ void test() { test_zoned_time_formatter(); test_zoned_time_formatter(); +#if !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING test_locale(); +#endif // !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING } int main() { From 2f04e4b11962f48a255456d9aab365e18638afaf Mon Sep 17 00:00:00 2001 From: Matt Stephanson Date: Thu, 17 Jun 2021 12:30:42 -0700 Subject: [PATCH 3/4] Generalize test for UTF-8. --- .../env.lst | 2 ++ .../test.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/env.lst b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/env.lst index 18e2d7c71e..4ca6faed47 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/env.lst +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/env.lst @@ -2,3 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception RUNALL_INCLUDE ..\concepts_latest_matrix.lst +RUNALL_CROSSLIST +PM_CL="/utf-8" diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp index ce710a8ad9..08cae1c768 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp @@ -892,9 +892,10 @@ void test_zoned_time_formatter() { assert(format(STR("{:%g %G %U %V %W}"), zt) == STR("21 2021 16 16 16")); } +template void test_locale() { - assert(format(locale{"zh-CN"}, L"{:^22%Y %B %d %A}", 2021y / June / 16d) - == L" 2021 \u516D\u6708 16 \u661F\u671F\u4E09 "); + assert(format(locale{"zh-CN"}, STR("{:^22%Y %B %d %A}"), 2021y / June / 16d) + == STR(" 2021 \u516D\u6708 16 \u661F\u671F\u4E09 ")); } void test() { @@ -970,7 +971,11 @@ void test() { test_zoned_time_formatter(); #if !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING - test_locale(); + test_locale(); +#ifndef MSVC_INTERNAL_TESTING // TRANSITION, the Windows version on Contest VMs doesn't always understand ".UTF-8" + setlocale(LC_ALL, ".UTF-8"); + test_locale(); +#endif // MSVC_INTERNAL_TESTING #endif // !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING } From f7ef4264ef5ac5a2c9e0404015a5e664c83b5ec3 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 21 Jun 2021 18:56:16 -0700 Subject: [PATCH 4/4] Code review feedback. --- .../tests/P0355R7_calendars_and_time_zones_formatting/test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp index 08cae1c768..bafd52b032 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -973,7 +974,7 @@ void test() { #if !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING test_locale(); #ifndef MSVC_INTERNAL_TESTING // TRANSITION, the Windows version on Contest VMs doesn't always understand ".UTF-8" - setlocale(LC_ALL, ".UTF-8"); + assert(setlocale(LC_ALL, ".UTF-8") != nullptr); test_locale(); #endif // MSVC_INTERNAL_TESTING #endif // !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING