Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / strings / string.conversions / stoull.pass.cpp
blob0a91f332c83d44ab9a6bf665ea9c8bb376355b37
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 // unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10);
12 // unsigned long long stoull(const wstring& str, size_t *idx = 0, int base = 10);
14 #include <string>
15 #include <cassert>
16 #include <stdexcept>
18 #include "test_macros.h"
20 int main(int, char**) {
21 assert(std::stoull("0") == 0);
22 assert(std::stoull("-0") == 0);
23 assert(std::stoull(" 10") == 10);
25 std::size_t idx = 0;
26 assert(std::stoull("10g", &idx, 16) == 16);
27 assert(idx == 2);
29 #ifndef TEST_HAS_NO_EXCEPTIONS
31 std::size_t idx = 0;
32 try {
33 (void)std::stoull("", &idx);
34 assert(false);
35 } catch (const std::invalid_argument&) {
36 assert(idx == 0);
40 std::size_t idx = 0;
41 try {
42 (void)std::stoull(" - 8", &idx);
43 assert(false);
44 } catch (const std::invalid_argument&) {
45 assert(idx == 0);
49 std::size_t idx = 0;
50 try {
51 (void)std::stoull("a1", &idx);
52 assert(false);
53 } catch (const std::invalid_argument&) {
54 assert(idx == 0);
58 std::size_t idx = 0;
59 try {
60 // LWG#2009 and PR14919
61 (void)std::stoull("9999999999999999999999999999999999999999999999999", &idx);
62 assert(false);
63 } catch (const std::out_of_range&) {
64 assert(idx == 0);
67 #endif // TEST_HAS_NO_EXCEPTIONS
69 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
70 assert(std::stoull(L"0") == 0);
71 assert(std::stoull(L"-0") == 0);
72 assert(std::stoull(L" 10") == 10);
74 std::size_t idx = 0;
75 assert(std::stoull(L"10g", &idx, 16) == 16);
76 assert(idx == 2);
78 # ifndef TEST_HAS_NO_EXCEPTIONS
80 std::size_t idx = 0;
81 try {
82 (void)std::stoull(L"", &idx);
83 assert(false);
84 } catch (const std::invalid_argument&) {
85 assert(idx == 0);
89 std::size_t idx = 0;
90 try {
91 (void)std::stoull(L" - 8", &idx);
92 assert(false);
93 } catch (const std::invalid_argument&) {
94 assert(idx == 0);
98 std::size_t idx = 0;
99 try {
100 (void)std::stoull(L"a1", &idx);
101 assert(false);
102 } catch (const std::invalid_argument&) {
103 assert(idx == 0);
107 std::size_t idx = 0;
108 try {
109 // LWG#2009 and PR14919
110 (void)std::stoull(L"9999999999999999999999999999999999999999999999999", &idx);
111 assert(false);
112 } catch (const std::out_of_range&) {
113 assert(idx == 0);
116 # endif // TEST_HAS_NO_EXCEPTIONS
117 #endif // TEST_HAS_NO_WIDE_CHARACTERS
119 return 0;