blob: 18ddf203b3e046988e827aa74da80b0773f082ad [file] [log] [blame]
Zhihao Yuand2748962018-08-01 02:38:30 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Yuand2748962018-08-01 02:38:30 +00006//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++98, c++03, c++11
Volodymyr Sapsai0b8efae2018-08-10 17:03:47 +000010
Louis Dionnea5e2b082018-12-14 20:22:44 +000011// XFAIL: with_system_cxx_lib=macosx10.14
Volodymyr Sapsai0b8efae2018-08-10 17:03:47 +000012// 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 Yuand2748962018-08-01 02:38:30 +000020// <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
27template <typename T>
28struct 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
57template <typename T>
58struct 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 Bastien2f4df4c2019-01-09 22:56:45 +000084int main()
Zhihao Yuand2748962018-08-01 02:38:30 +000085{
86 run<test_basics>(integrals);
87 run<test_signed>(all_signed);
88}