[clang][test] Fix SemaCXX/msvc-pragma-function-no-builtin-attr.cpp for x86 (#119986)
[llvm-project.git] / libcxx / test / std / strings / string.conversions / to_wstring.pass.cpp
blobfff5ede848b57a19df1d198e784a83727cf843e8
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 //===----------------------------------------------------------------------===//
9 // XFAIL: no-wide-characters
11 // <string>
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);
23 #include <string>
24 #include <cassert>
25 #include <limits>
27 #include "parse_integer.h"
28 #include "test_macros.h"
30 template <class T>
31 void test_signed() {
33 std::wstring s = std::to_wstring(T(0));
34 assert(s.size() == 1);
35 assert(s[s.size()] == 0);
36 assert(s == L"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());
63 template <class T>
64 void test_unsigned() {
66 std::wstring s = std::to_wstring(T(0));
67 assert(s.size() == 1);
68 assert(s[s.size()] == 0);
69 assert(s == L"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());
85 template <class T>
86 void test_float() {
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**) {
108 test_signed<int>();
109 test_signed<long>();
110 test_signed<long long>();
111 test_unsigned<unsigned>();
112 test_unsigned<unsigned long>();
113 test_unsigned<unsigned long long>();
114 test_float<float>();
115 test_float<double>();
116 test_float<long double>();
118 return 0;