[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / string.conversions / to_string.pass.cpp
blob3de0232e796ed835129519580dcc3c4f7c42f032
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 // <string>
11 // string to_string(int val);
12 // string to_string(unsigned val);
13 // string to_string(long val);
14 // string to_string(unsigned long val);
15 // string to_string(long long val);
16 // string to_string(unsigned long long val);
17 // string to_string(float val);
18 // string to_string(double val);
19 // string to_string(long double val);
21 #include <string>
22 #include <cassert>
23 #include <limits>
25 #include "parse_integer.h"
26 #include "test_macros.h"
28 template <class T>
29 void
30 test_signed()
33 std::string s = std::to_string(T(0));
34 assert(s.size() == 1);
35 assert(s[s.size()] == 0);
36 assert(s == "0");
39 std::string s = std::to_string(T(12345));
40 assert(s.size() == 5);
41 assert(s[s.size()] == 0);
42 assert(s == "12345");
45 std::string s = std::to_string(T(-12345));
46 assert(s.size() == 6);
47 assert(s[s.size()] == 0);
48 assert(s == "-12345");
51 std::string s = std::to_string(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::string s = std::to_string(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
65 test_unsigned()
68 std::string s = std::to_string(T(0));
69 assert(s.size() == 1);
70 assert(s[s.size()] == 0);
71 assert(s == "0");
74 std::string s = std::to_string(T(12345));
75 assert(s.size() == 5);
76 assert(s[s.size()] == 0);
77 assert(s == "12345");
80 std::string s = std::to_string(std::numeric_limits<T>::max());
81 assert(s.size() == std::numeric_limits<T>::digits10 + 1);
82 T t = parse_integer<T>(s);
83 assert(t == std::numeric_limits<T>::max());
87 template <class T>
88 void
89 test_float()
92 std::string s = std::to_string(T(0));
93 assert(s.size() == 8);
94 assert(s[s.size()] == 0);
95 assert(s == "0.000000");
98 std::string s = std::to_string(T(12345));
99 assert(s.size() == 12);
100 assert(s[s.size()] == 0);
101 assert(s == "12345.000000");
104 std::string s = std::to_string(T(-12345));
105 assert(s.size() == 13);
106 assert(s[s.size()] == 0);
107 assert(s == "-12345.000000");
111 int main(int, char**)
113 test_signed<int>();
114 test_signed<long>();
115 test_signed<long long>();
116 test_unsigned<unsigned>();
117 test_unsigned<unsigned long>();
118 test_unsigned<unsigned long long>();
119 test_float<float>();
120 test_float<double>();
121 test_float<long double>();
123 return 0;