• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //===----------------------------------------------------------------------===//
9 
10 // <string>
11 
12 // unsigned long stoul(const string& str, size_t *idx = 0, int base = 10);
13 // unsigned long stoul(const wstring& str, size_t *idx = 0, int base = 10);
14 
15 #include <string>
16 #include <cassert>
17 
main()18 int main()
19 {
20     assert(std::stoul("0") == 0);
21     assert(std::stoul(L"0") == 0);
22     assert(std::stoul("-0") == 0);
23     assert(std::stoul(L"-0") == 0);
24     assert(std::stoul(" 10") == 10);
25     assert(std::stoul(L" 10") == 10);
26     size_t idx = 0;
27     assert(std::stoul("10g", &idx, 16) == 16);
28     assert(idx == 2);
29     idx = 0;
30     assert(std::stoul(L"10g", &idx, 16) == 16);
31     assert(idx == 2);
32     idx = 0;
33     try
34     {
35         std::stoul("", &idx);
36         assert(false);
37     }
38     catch (const std::invalid_argument&)
39     {
40         assert(idx == 0);
41     }
42     try
43     {
44         std::stoul(L"", &idx);
45         assert(false);
46     }
47     catch (const std::invalid_argument&)
48     {
49         assert(idx == 0);
50     }
51     try
52     {
53         std::stoul("  - 8", &idx);
54         assert(false);
55     }
56     catch (const std::invalid_argument&)
57     {
58         assert(idx == 0);
59     }
60     try
61     {
62         std::stoul(L"  - 8", &idx);
63         assert(false);
64     }
65     catch (const std::invalid_argument&)
66     {
67         assert(idx == 0);
68     }
69     try
70     {
71         std::stoul("a1", &idx);
72         assert(false);
73     }
74     catch (const std::invalid_argument&)
75     {
76         assert(idx == 0);
77     }
78     try
79     {
80         std::stoul(L"a1", &idx);
81         assert(false);
82     }
83     catch (const std::invalid_argument&)
84     {
85         assert(idx == 0);
86     }
87 }
88