summaryrefslogtreecommitdiff
path: root/test/std/strings/string.conversions/stoul.pass.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
commit61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch)
treeec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/strings/string.conversions/stoul.pass.cpp
parentf857581820d15e410e9945d2fcd5f7163be25a96 (diff)
Notes
Diffstat (limited to 'test/std/strings/string.conversions/stoul.pass.cpp')
-rw-r--r--test/std/strings/string.conversions/stoul.pass.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/test/std/strings/string.conversions/stoul.pass.cpp b/test/std/strings/string.conversions/stoul.pass.cpp
new file mode 100644
index 0000000000000..37d33c4a9091f
--- /dev/null
+++ b/test/std/strings/string.conversions/stoul.pass.cpp
@@ -0,0 +1,109 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11
+// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12
+
+// <string>
+
+// unsigned long stoul(const string& str, size_t *idx = 0, int base = 10);
+// unsigned long stoul(const wstring& str, size_t *idx = 0, int base = 10);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+ assert(std::stoul("0") == 0);
+ assert(std::stoul(L"0") == 0);
+ assert(std::stoul("-0") == 0);
+ assert(std::stoul(L"-0") == 0);
+ assert(std::stoul(" 10") == 10);
+ assert(std::stoul(L" 10") == 10);
+ size_t idx = 0;
+ assert(std::stoul("10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ assert(std::stoul(L"10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ try
+ {
+ std::stoul("", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoul(L"", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoul(" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoul(L" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoul("a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoul(L"a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+// LWG issue #2009
+ try
+ {
+ std::stoul("9999999999999999999999999999999999999999999999999", &idx);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoul(L"9999999999999999999999999999999999999999999999999", &idx);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(idx == 0);
+ }
+}