1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // XFAIL: no-wide-characters
13 // wstring to_wstring(int val);
14 // wstring to_wstring(unsigned val);
15 // wstring to_wstring(long val);
16 // wstring to_wstring(unsigned long val);
17 // wstring to_wstring(long long val);
18 // wstring to_wstring(unsigned long long val);
19 // wstring to_wstring(float val);
20 // wstring to_wstring(double val);
21 // wstring to_wstring(long double val);
27 #include "parse_integer.h"
28 #include "test_macros.h"
33 std::wstring s
= std::to_wstring(T(0));
34 assert(s
.size() == 1);
35 assert(s
[s
.size()] == 0);
39 std::wstring s
= std::to_wstring(T(12345));
40 assert(s
.size() == 5);
41 assert(s
[s
.size()] == 0);
42 assert(s
== L
"12345");
45 std::wstring s
= std::to_wstring(T(-12345));
46 assert(s
.size() == 6);
47 assert(s
[s
.size()] == 0);
48 assert(s
== L
"-12345");
51 std::wstring s
= std::to_wstring(std::numeric_limits
<T
>::max());
52 assert(s
.size() == std::numeric_limits
<T
>::digits10
+ 1);
53 T t
= parse_integer
<T
>(s
);
54 assert(t
== std::numeric_limits
<T
>::max());
57 std::wstring s
= std::to_wstring(std::numeric_limits
<T
>::min());
58 T t
= parse_integer
<T
>(s
);
59 assert(t
== std::numeric_limits
<T
>::min());
64 void test_unsigned() {
66 std::wstring s
= std::to_wstring(T(0));
67 assert(s
.size() == 1);
68 assert(s
[s
.size()] == 0);
72 std::wstring s
= std::to_wstring(T(12345));
73 assert(s
.size() == 5);
74 assert(s
[s
.size()] == 0);
75 assert(s
== L
"12345");
78 std::wstring s
= std::to_wstring(std::numeric_limits
<T
>::max());
79 assert(s
.size() == std::numeric_limits
<T
>::digits10
+ 1);
80 T t
= parse_integer
<T
>(s
);
81 assert(t
== std::numeric_limits
<T
>::max());
88 std::wstring s
= std::to_wstring(T(0));
89 assert(s
.size() == 8);
90 assert(s
[s
.size()] == 0);
91 assert(s
== L
"0.000000");
94 std::wstring s
= std::to_wstring(T(12345));
95 assert(s
.size() == 12);
96 assert(s
[s
.size()] == 0);
97 assert(s
== L
"12345.000000");
100 std::wstring s
= std::to_wstring(T(-12345));
101 assert(s
.size() == 13);
102 assert(s
[s
.size()] == 0);
103 assert(s
== L
"-12345.000000");
107 int main(int, char**) {
110 test_signed
<long long>();
111 test_unsigned
<unsigned>();
112 test_unsigned
<unsigned long>();
113 test_unsigned
<unsigned long long>();
115 test_float
<double>();
116 test_float
<long double>();