blob: b823ab7426262f3015a7c845fa4af42b789a2d7c [file] [log] [blame]
Howard Hinnantcbbf6332010-06-02 18:20:39 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantcbbf6332010-06-02 18:20:39 +00007//
8//===----------------------------------------------------------------------===//
Daniel Dunbar5ce9a532013-02-05 22:10:27 +00009//
Mehdi Aminif8764e302017-03-15 00:59:54 +000010// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7
11// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8
Howard Hinnantcbbf6332010-06-02 18:20:39 +000012
13// <string>
14
15// long long stoll(const string& str, size_t *idx = 0, int base = 10);
16// long long stoll(const wstring& str, size_t *idx = 0, int base = 10);
17
18#include <string>
19#include <cassert>
20
Roger Ferrer Ibanez84c152a2016-11-14 10:44:26 +000021#include "test_macros.h"
22
Howard Hinnantcbbf6332010-06-02 18:20:39 +000023int main()
24{
25 assert(std::stoll("0") == 0);
26 assert(std::stoll(L"0") == 0);
27 assert(std::stoll("-0") == 0);
28 assert(std::stoll(L"-0") == 0);
29 assert(std::stoll("-10") == -10);
30 assert(std::stoll(L"-10") == -10);
31 assert(std::stoll(" 10") == 10);
32 assert(std::stoll(L" 10") == 10);
33 size_t idx = 0;
34 assert(std::stoll("10g", &idx, 16) == 16);
35 assert(idx == 2);
36 idx = 0;
37 assert(std::stoll(L"10g", &idx, 16) == 16);
38 assert(idx == 2);
Roger Ferrer Ibanez84c152a2016-11-14 10:44:26 +000039#ifndef TEST_HAS_NO_EXCEPTIONS
Howard Hinnantcbbf6332010-06-02 18:20:39 +000040 idx = 0;
41 try
42 {
43 std::stoll("", &idx);
44 assert(false);
45 }
46 catch (const std::invalid_argument&)
47 {
48 assert(idx == 0);
49 }
50 try
51 {
52 std::stoll(L"", &idx);
53 assert(false);
54 }
55 catch (const std::invalid_argument&)
56 {
57 assert(idx == 0);
58 }
59 try
60 {
61 std::stoll(" - 8", &idx);
62 assert(false);
63 }
64 catch (const std::invalid_argument&)
65 {
66 assert(idx == 0);
67 }
68 try
69 {
70 std::stoll(L" - 8", &idx);
71 assert(false);
72 }
73 catch (const std::invalid_argument&)
74 {
75 assert(idx == 0);
76 }
77 try
78 {
79 std::stoll("a1", &idx);
80 assert(false);
81 }
82 catch (const std::invalid_argument&)
83 {
84 assert(idx == 0);
85 }
86 try
87 {
88 std::stoll(L"a1", &idx);
89 assert(false);
90 }
91 catch (const std::invalid_argument&)
92 {
93 assert(idx == 0);
94 }
Howard Hinnant1afbaba2013-01-14 18:59:43 +000095 try
96 {
97 std::stoll("99999999999999999999999999", &idx);
98 assert(false);
99 }
100 catch (const std::out_of_range&)
101 {
102 assert(idx == 0);
103 }
Marshall Clow914993d2013-08-13 15:52:51 +0000104 try
105 {
106 std::stoll(L"99999999999999999999999999", &idx);
107 assert(false);
108 }
109 catch (const std::out_of_range&)
110 {
111 assert(idx == 0);
112 }
Roger Ferrer Ibanez84c152a2016-11-14 10:44:26 +0000113#endif
Howard Hinnantcbbf6332010-06-02 18:20:39 +0000114}