Remove building with NOCRYPTO option
[minix.git] / external / bsd / libc++ / dist / libcxx / test / strings / string.conversions / stoi.pass.cpp
blobc2fc2103579da1df30b461b665930ca7e155f295
1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 // <string>
12 // int stoi(const string& str, size_t *idx = 0, int base = 10);
13 // int stoi(const wstring& str, size_t *idx = 0, int base = 10);
15 #include <string>
16 #include <cassert>
18 int main()
20 assert(std::stoi("0") == 0);
21 assert(std::stoi(L"0") == 0);
22 assert(std::stoi("-0") == 0);
23 assert(std::stoi(L"-0") == 0);
24 assert(std::stoi("-10") == -10);
25 assert(std::stoi(L"-10") == -10);
26 assert(std::stoi(" 10") == 10);
27 assert(std::stoi(L" 10") == 10);
28 size_t idx = 0;
29 assert(std::stoi("10g", &idx, 16) == 16);
30 assert(idx == 2);
31 idx = 0;
32 assert(std::stoi(L"10g", &idx, 16) == 16);
33 assert(idx == 2);
34 if (std::numeric_limits<long>::max() > std::numeric_limits<int>::max())
36 try
38 std::stoi("0x100000000", &idx, 16);
39 assert(false);
41 catch (const std::out_of_range&)
44 try
46 std::stoi(L"0x100000000", &idx, 16);
47 assert(false);
49 catch (const std::out_of_range&)
53 idx = 0;
54 try
56 std::stoi("", &idx);
57 assert(false);
59 catch (const std::invalid_argument&)
61 assert(idx == 0);
63 try
65 std::stoi(L"", &idx);
66 assert(false);
68 catch (const std::invalid_argument&)
70 assert(idx == 0);
72 try
74 std::stoi(" - 8", &idx);
75 assert(false);
77 catch (const std::invalid_argument&)
79 assert(idx == 0);
81 try
83 std::stoi(L" - 8", &idx);
84 assert(false);
86 catch (const std::invalid_argument&)
88 assert(idx == 0);
90 try
92 std::stoi("a1", &idx);
93 assert(false);
95 catch (const std::invalid_argument&)
97 assert(idx == 0);
99 try
101 std::stoi(L"a1", &idx);
102 assert(false);
104 catch (const std::invalid_argument&)
106 assert(idx == 0);