| Zhihao Yuan | d274896 | 2018-08-01 02:38:30 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame^] | 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 |
| Zhihao Yuan | d274896 | 2018-08-01 02:38:30 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++98, c++03, c++11 |
| Volodymyr Sapsai | 0b8efae | 2018-08-10 17:03:47 +0000 | [diff] [blame] | 10 | |
| Louis Dionne | a5e2b08 | 2018-12-14 20:22:44 +0000 | [diff] [blame] | 11 | // XFAIL: with_system_cxx_lib=macosx10.14 |
| Volodymyr Sapsai | 0b8efae | 2018-08-10 17:03:47 +0000 | [diff] [blame] | 12 | // XFAIL: with_system_cxx_lib=macosx10.13 |
| 13 | // XFAIL: with_system_cxx_lib=macosx10.12 |
| 14 | // XFAIL: with_system_cxx_lib=macosx10.11 |
| 15 | // XFAIL: with_system_cxx_lib=macosx10.10 |
| 16 | // XFAIL: with_system_cxx_lib=macosx10.9 |
| 17 | // XFAIL: with_system_cxx_lib=macosx10.8 |
| 18 | // XFAIL: with_system_cxx_lib=macosx10.7 |
| 19 | |
| Zhihao Yuan | d274896 | 2018-08-01 02:38:30 +0000 | [diff] [blame] | 20 | // <charconv> |
| 21 | |
| 22 | // to_chars_result to_chars(char* first, char* last, Integral value, |
| 23 | // int base = 10) |
| 24 | |
| 25 | #include "charconv_test_helpers.h" |
| 26 | |
| 27 | template <typename T> |
| 28 | struct test_basics : to_chars_test_base<T> |
| 29 | { |
| 30 | using to_chars_test_base<T>::test; |
| 31 | using to_chars_test_base<T>::test_value; |
| 32 | |
| 33 | void operator()() |
| 34 | { |
| 35 | test(0, "0"); |
| 36 | test(42, "42"); |
| 37 | test(32768, "32768"); |
| 38 | test(0, "0", 10); |
| 39 | test(42, "42", 10); |
| 40 | test(32768, "32768", 10); |
| 41 | test(0xf, "f", 16); |
| 42 | test(0xdeadbeaf, "deadbeaf", 16); |
| 43 | test(0755, "755", 8); |
| 44 | |
| 45 | for (int b = 2; b < 37; ++b) |
| 46 | { |
| 47 | using xl = std::numeric_limits<T>; |
| 48 | |
| 49 | test_value(1, b); |
| 50 | test_value(xl::lowest(), b); |
| 51 | test_value((xl::max)(), b); |
| 52 | test_value((xl::max)() / 2, b); |
| 53 | } |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | template <typename T> |
| 58 | struct test_signed : to_chars_test_base<T> |
| 59 | { |
| 60 | using to_chars_test_base<T>::test; |
| 61 | using to_chars_test_base<T>::test_value; |
| 62 | |
| 63 | void operator()() |
| 64 | { |
| 65 | test(-1, "-1"); |
| 66 | test(-12, "-12"); |
| 67 | test(-1, "-1", 10); |
| 68 | test(-12, "-12", 10); |
| 69 | test(-21734634, "-21734634", 10); |
| 70 | test(-2647, "-101001010111", 2); |
| 71 | test(-0xcc1, "-cc1", 16); |
| 72 | |
| 73 | for (int b = 2; b < 37; ++b) |
| 74 | { |
| 75 | using xl = std::numeric_limits<T>; |
| 76 | |
| 77 | test_value(0, b); |
| 78 | test_value(xl::lowest(), b); |
| 79 | test_value((xl::max)(), b); |
| 80 | } |
| 81 | } |
| 82 | }; |
| 83 | |
| JF Bastien | 2f4df4c | 2019-01-09 22:56:45 +0000 | [diff] [blame] | 84 | int main() |
| Zhihao Yuan | d274896 | 2018-08-01 02:38:30 +0000 | [diff] [blame] | 85 | { |
| 86 | run<test_basics>(integrals); |
| 87 | run<test_signed>(all_signed); |
| 88 | } |