| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 9 | |
| 10 | // <chrono> |
| 11 | // class year_month_weekday_last; |
| 12 | |
| 13 | // constexpr bool ok() const noexcept; |
| 14 | // Returns: y_.ok() && m_.ok() && wdl_.ok(). |
| 15 | |
| 16 | #include <chrono> |
| 17 | #include <cassert> |
| 18 | #include <type_traits> |
| 19 | #include <utility> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | int main(int, char**) |
| 24 | { |
| 25 | using year = std::chrono::year; |
| 26 | using month = std::chrono::month; |
| 27 | using weekday = std::chrono::weekday; |
| 28 | using weekday_last = std::chrono::weekday_last; |
| 29 | using year_month_weekday_last = std::chrono::year_month_weekday_last; |
| 30 | |
| 31 | constexpr month January = std::chrono::January; |
| 32 | constexpr weekday Tuesday = std::chrono::Tuesday; |
| 33 | |
| 34 | ASSERT_NOEXCEPT( std::declval<const year_month_weekday_last>().ok()); |
| 35 | ASSERT_SAME_TYPE(bool, decltype(std::declval<const year_month_weekday_last>().ok())); |
| 36 | |
| 37 | static_assert(!year_month_weekday_last{year{-32768}, month{}, weekday_last{weekday{}}}.ok(), "" ); // All three bad |
| 38 | |
| 39 | static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{Tuesday}}.ok(), "" ); // Bad year |
| 40 | static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{Tuesday}}.ok(), "" ); // Bad month |
| 41 | static_assert(!year_month_weekday_last{year{2019}, January, weekday_last{weekday{8}}}.ok(), "" ); // Bad day |
| 42 | |
| 43 | static_assert(!year_month_weekday_last{year{-32768}, month{}, weekday_last{Tuesday}}.ok(), "" ); // Bad year & month |
| 44 | static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{weekday{8}}}.ok(), "" ); // Bad month & day |
| 45 | static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{weekday{8}}}.ok(), "" ); // Bad year & day |
| 46 | |
| 47 | static_assert( year_month_weekday_last{year{2019}, January, weekday_last{Tuesday}}.ok(), "" ); // All OK |
| 48 | |
| 49 | for (unsigned i = 0; i <= 50; ++i) |
| 50 | { |
| 51 | year_month_weekday_last ym{year{2019}, January, weekday_last{Tuesday}}; |
| 52 | assert((ym.ok() == weekday_last{Tuesday}.ok())); |
| 53 | } |
| 54 | |
| 55 | for (unsigned i = 0; i <= 50; ++i) |
| 56 | { |
| 57 | year_month_weekday_last ym{year{2019}, January, weekday_last{weekday{i}}}; |
| 58 | assert((ym.ok() == weekday_last{weekday{i}}.ok())); |
| 59 | } |
| 60 | |
| 61 | for (unsigned i = 0; i <= 50; ++i) |
| 62 | { |
| 63 | year_month_weekday_last ym{year{2019}, month{i}, weekday_last{Tuesday}}; |
| 64 | assert((ym.ok() == month{i}.ok())); |
| 65 | } |
| 66 | |
| 67 | const int ymax = static_cast<int>(year::max()); |
| 68 | for (int i = ymax - 100; i <= ymax + 100; ++i) |
| 69 | { |
| 70 | year_month_weekday_last ym{year{i}, January, weekday_last{Tuesday}}; |
| 71 | assert((ym.ok() == year{i}.ok())); |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |