summaryrefslogtreecommitdiffstats
path: root/libcxx/test/strings/string.conversions
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2010-06-02 18:20:39 +0000
committerHoward Hinnant <hhinnant@apple.com>2010-06-02 18:20:39 +0000
commitcbbf633edb3d7751cd313bca1839ade9f23d84f2 (patch)
tree2e0628169521f1b96ee5ed55ec8f94dce86190c5 /libcxx/test/strings/string.conversions
parent94801a47f80c1ff383d14b84f7e68affb4542b3f (diff)
downloadbcm5719-llvm-cbbf633edb3d7751cd313bca1839ade9f23d84f2.tar.gz
bcm5719-llvm-cbbf633edb3d7751cd313bca1839ade9f23d84f2.zip
[string.conversions]
llvm-svn: 105336
Diffstat (limited to 'libcxx/test/strings/string.conversions')
-rw-r--r--libcxx/test/strings/string.conversions/stod.pass.cpp166
-rw-r--r--libcxx/test/strings/string.conversions/stof.pass.cpp166
-rw-r--r--libcxx/test/strings/string.conversions/stoi.pass.cpp108
-rw-r--r--libcxx/test/strings/string.conversions/stol.pass.cpp89
-rw-r--r--libcxx/test/strings/string.conversions/stold.pass.cpp168
-rw-r--r--libcxx/test/strings/string.conversions/stoll.pass.cpp89
-rw-r--r--libcxx/test/strings/string.conversions/stoul.pass.cpp87
-rw-r--r--libcxx/test/strings/string.conversions/stoull.pass.cpp88
-rw-r--r--libcxx/test/strings/string.conversions/to_string.pass.cpp126
-rw-r--r--libcxx/test/strings/string.conversions/to_wstring.pass.cpp126
10 files changed, 1213 insertions, 0 deletions
diff --git a/libcxx/test/strings/string.conversions/stod.pass.cpp b/libcxx/test/strings/string.conversions/stod.pass.cpp
new file mode 100644
index 00000000000..4c75f0a3746
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/stod.pass.cpp
@@ -0,0 +1,166 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// double stod(const string& str, size_t *idx = 0);
+// double stod(const wstring& str, size_t *idx = 0);
+
+#include <string>
+#include <cmath>
+#include <cassert>
+
+int main()
+{
+ assert(std::stod("0") == 0);
+ assert(std::stod(L"0") == 0);
+ assert(std::stod("-0") == 0);
+ assert(std::stod(L"-0") == 0);
+ assert(std::stod("-10") == -10);
+ assert(std::stod(L"-10.5") == -10.5);
+ assert(std::stod(" 10") == 10);
+ assert(std::stod(L" 10") == 10);
+ size_t idx = 0;
+ assert(std::stod("10g", &idx) == 10);
+ assert(idx == 2);
+ idx = 0;
+ assert(std::stod(L"10g", &idx) == 10);
+ assert(idx == 2);
+ try
+ {
+ assert(std::stod("1.e60", &idx) == 1.e60);
+ assert(idx == 5);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ try
+ {
+ assert(std::stod(L"1.e60", &idx) == 1.e60);
+ assert(idx == 5);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::stod("1.e360", &idx) == INFINITY);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ assert(std::stod(L"1.e360", &idx) == INFINITY);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ assert(std::stod("INF", &idx) == INFINITY);
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::stod(L"INF", &idx) == INFINITY);
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::isnan(std::stod("NAN", &idx)));
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::isnan(std::stod(L"NAN", &idx)));
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ std::stod("", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stod(L"", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stod(" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stod(L" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stod("a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stod(L"a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+}
diff --git a/libcxx/test/strings/string.conversions/stof.pass.cpp b/libcxx/test/strings/string.conversions/stof.pass.cpp
new file mode 100644
index 00000000000..14a5bd03623
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/stof.pass.cpp
@@ -0,0 +1,166 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// float stof(const string& str, size_t *idx = 0);
+// float stof(const wstring& str, size_t *idx = 0);
+
+#include <string>
+#include <cmath>
+#include <cassert>
+
+int main()
+{
+ assert(std::stof("0") == 0);
+ assert(std::stof(L"0") == 0);
+ assert(std::stof("-0") == 0);
+ assert(std::stof(L"-0") == 0);
+ assert(std::stof("-10") == -10);
+ assert(std::stof(L"-10.5") == -10.5);
+ assert(std::stof(" 10") == 10);
+ assert(std::stof(L" 10") == 10);
+ size_t idx = 0;
+ assert(std::stof("10g", &idx) == 10);
+ assert(idx == 2);
+ idx = 0;
+ assert(std::stof(L"10g", &idx) == 10);
+ assert(idx == 2);
+ try
+ {
+ assert(std::stof("1.e60", &idx) == INFINITY);
+ assert(idx == 5);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ try
+ {
+ assert(std::stof(L"1.e60", &idx) == INFINITY);
+ assert(idx == 5);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::stof("1.e360", &idx) == INFINITY);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ assert(std::stof(L"1.e360", &idx) == INFINITY);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ assert(std::stof("INF", &idx) == INFINITY);
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::stof(L"INF", &idx) == INFINITY);
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::isnan(std::stof("NAN", &idx)));
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::isnan(std::stof(L"NAN", &idx)));
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ std::stof("", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stof(L"", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stof(" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stof(L" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stof("a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stof(L"a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+}
diff --git a/libcxx/test/strings/string.conversions/stoi.pass.cpp b/libcxx/test/strings/string.conversions/stoi.pass.cpp
new file mode 100644
index 00000000000..684518069bb
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/stoi.pass.cpp
@@ -0,0 +1,108 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// int stoi(const string& str, size_t *idx = 0, int base = 10);
+// int stoi(const wstring& str, size_t *idx = 0, int base = 10);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+ assert(std::stoi("0") == 0);
+ assert(std::stoi(L"0") == 0);
+ assert(std::stoi("-0") == 0);
+ assert(std::stoi(L"-0") == 0);
+ assert(std::stoi("-10") == -10);
+ assert(std::stoi(L"-10") == -10);
+ assert(std::stoi(" 10") == 10);
+ assert(std::stoi(L" 10") == 10);
+ size_t idx = 0;
+ assert(std::stoi("10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ assert(std::stoi(L"10g", &idx, 16) == 16);
+ assert(idx == 2);
+ if (std::numeric_limits<long>::max() > std::numeric_limits<int>::max())
+ {
+ try
+ {
+ std::stoi("0x100000000", &idx, 16);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ }
+ try
+ {
+ std::stoi(L"0x100000000", &idx, 16);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ }
+ }
+ idx = 0;
+ try
+ {
+ std::stoi("", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoi(L"", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoi(" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoi(L" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoi("a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoi(L"a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+}
diff --git a/libcxx/test/strings/string.conversions/stol.pass.cpp b/libcxx/test/strings/string.conversions/stol.pass.cpp
new file mode 100644
index 00000000000..f31326310d1
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/stol.pass.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// long stol(const string& str, size_t *idx = 0, int base = 10);
+// long stol(const wstring& str, size_t *idx = 0, int base = 10);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+ assert(std::stol("0") == 0);
+ assert(std::stol(L"0") == 0);
+ assert(std::stol("-0") == 0);
+ assert(std::stol(L"-0") == 0);
+ assert(std::stol("-10") == -10);
+ assert(std::stol(L"-10") == -10);
+ assert(std::stol(" 10") == 10);
+ assert(std::stol(L" 10") == 10);
+ size_t idx = 0;
+ assert(std::stol("10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ assert(std::stol(L"10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ try
+ {
+ std::stol("", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stol(L"", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stol(" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stol(L" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stol("a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stol(L"a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+}
diff --git a/libcxx/test/strings/string.conversions/stold.pass.cpp b/libcxx/test/strings/string.conversions/stold.pass.cpp
new file mode 100644
index 00000000000..86666d80380
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/stold.pass.cpp
@@ -0,0 +1,168 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// long double stold(const string& str, size_t *idx = 0);
+// long double stold(const wstring& str, size_t *idx = 0);
+
+#include <iostream>
+
+#include <string>
+#include <cmath>
+#include <cassert>
+
+int main()
+{
+ assert(std::stold("0") == 0);
+ assert(std::stold(L"0") == 0);
+ assert(std::stold("-0") == 0);
+ assert(std::stold(L"-0") == 0);
+ assert(std::stold("-10") == -10);
+ assert(std::stold(L"-10.5") == -10.5);
+ assert(std::stold(" 10") == 10);
+ assert(std::stold(L" 10") == 10);
+ size_t idx = 0;
+ assert(std::stold("10g", &idx) == 10);
+ assert(idx == 2);
+ idx = 0;
+ assert(std::stold(L"10g", &idx) == 10);
+ assert(idx == 2);
+ try
+ {
+ assert(std::stold("1.e60", &idx) == 1.e60L);
+ assert(idx == 5);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ try
+ {
+ assert(std::stold(L"1.e60", &idx) == 1.e60L);
+ assert(idx == 5);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::stold("1.e6000", &idx) == INFINITY);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ assert(std::stold(L"1.e6000", &idx) == INFINITY);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ assert(std::stold("INF", &idx) == INFINITY);
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::stold(L"INF", &idx) == INFINITY);
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::isnan(std::stold("NAN", &idx)));
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ assert(std::isnan(std::stold(L"NAN", &idx)));
+ assert(idx == 3);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(false);
+ }
+ idx = 0;
+ try
+ {
+ std::stold("", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stold(L"", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stold(" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stold(L" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stold("a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stold(L"a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+}
diff --git a/libcxx/test/strings/string.conversions/stoll.pass.cpp b/libcxx/test/strings/string.conversions/stoll.pass.cpp
new file mode 100644
index 00000000000..8e904037055
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/stoll.pass.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// long long stoll(const string& str, size_t *idx = 0, int base = 10);
+// long long stoll(const wstring& str, size_t *idx = 0, int base = 10);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+ assert(std::stoll("0") == 0);
+ assert(std::stoll(L"0") == 0);
+ assert(std::stoll("-0") == 0);
+ assert(std::stoll(L"-0") == 0);
+ assert(std::stoll("-10") == -10);
+ assert(std::stoll(L"-10") == -10);
+ assert(std::stoll(" 10") == 10);
+ assert(std::stoll(L" 10") == 10);
+ size_t idx = 0;
+ assert(std::stoll("10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ assert(std::stoll(L"10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ try
+ {
+ std::stoll("", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoll(L"", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoll(" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoll(L" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoll("a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoll(L"a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+}
diff --git a/libcxx/test/strings/string.conversions/stoul.pass.cpp b/libcxx/test/strings/string.conversions/stoul.pass.cpp
new file mode 100644
index 00000000000..c31b2cc2c3f
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/stoul.pass.cpp
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+ }
+}
diff --git a/libcxx/test/strings/string.conversions/stoull.pass.cpp b/libcxx/test/strings/string.conversions/stoull.pass.cpp
new file mode 100644
index 00000000000..9432750b6fb
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/stoull.pass.cpp
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10);
+// unsigned long long stoull(const wstring& str, size_t *idx = 0, int base = 10);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+ assert(std::stoull("0") == 0);
+ assert(std::stoull(L"0") == 0);
+ assert(std::stoull("-0") == 0);
+ assert(std::stoull(L"-0") == 0);
+ assert(std::stoull(" 10") == 10);
+ assert(std::stoull(L" 10") == 10);
+ size_t idx = 0;
+ assert(std::stoull("10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ assert(std::stoull(L"10g", &idx, 16) == 16);
+ assert(idx == 2);
+ idx = 0;
+ try
+ {
+ std::stoull("", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ idx = 0;
+ try
+ {
+ std::stoull(L"", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoull(" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoull(L" - 8", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoull("a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+ try
+ {
+ std::stoull(L"a1", &idx);
+ assert(false);
+ }
+ catch (const std::invalid_argument&)
+ {
+ assert(idx == 0);
+ }
+}
diff --git a/libcxx/test/strings/string.conversions/to_string.pass.cpp b/libcxx/test/strings/string.conversions/to_string.pass.cpp
new file mode 100644
index 00000000000..86e2b6b4c74
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/to_string.pass.cpp
@@ -0,0 +1,126 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// string to_string(int val);
+// string to_string(unsigned val);
+// string to_string(long val);
+// string to_string(unsigned long val);
+// string to_string(long long val);
+// string to_string(unsigned long long val);
+// string to_string(float val);
+// string to_string(double val);
+// string to_string(long double val);
+
+#include <string>
+#include <cassert>
+#include <sstream>
+
+template <class T>
+void
+test_signed()
+{
+ {
+ std::string s = std::to_string(T(0));
+ assert(s.size() == 1);
+ assert(s[s.size()] == 0);
+ assert(s == "0");
+ }
+ {
+ std::string s = std::to_string(T(12345));
+ assert(s.size() == 5);
+ assert(s[s.size()] == 0);
+ assert(s == "12345");
+ }
+ {
+ std::string s = std::to_string(T(-12345));
+ assert(s.size() == 6);
+ assert(s[s.size()] == 0);
+ assert(s == "-12345");
+ }
+ {
+ std::string s = std::to_string(std::numeric_limits<T>::max());
+ assert(s.size() == std::numeric_limits<T>::digits10 + 1);
+ std::istringstream is(s);
+ T t(0);
+ is >> t;
+ assert(t == std::numeric_limits<T>::max());
+ }
+ {
+ std::string s = std::to_string(std::numeric_limits<T>::min());
+ std::istringstream is(s);
+ T t(0);
+ is >> t;
+ assert(t == std::numeric_limits<T>::min());
+ }
+}
+
+template <class T>
+void
+test_unsigned()
+{
+ {
+ std::string s = std::to_string(T(0));
+ assert(s.size() == 1);
+ assert(s[s.size()] == 0);
+ assert(s == "0");
+ }
+ {
+ std::string s = std::to_string(T(12345));
+ assert(s.size() == 5);
+ assert(s[s.size()] == 0);
+ assert(s == "12345");
+ }
+ {
+ std::string s = std::to_string(std::numeric_limits<T>::max());
+ assert(s.size() == std::numeric_limits<T>::digits10 + 1);
+ std::istringstream is(s);
+ T t(0);
+ is >> t;
+ assert(t == std::numeric_limits<T>::max());
+ }
+}
+
+template <class T>
+void
+test_float()
+{
+ {
+ std::string s = std::to_string(T(0));
+ assert(s.size() == 8);
+ assert(s[s.size()] == 0);
+ assert(s == "0.000000");
+ }
+ {
+ std::string s = std::to_string(T(12345));
+ assert(s.size() == 12);
+ assert(s[s.size()] == 0);
+ assert(s == "12345.000000");
+ }
+ {
+ std::string s = std::to_string(T(-12345));
+ assert(s.size() == 13);
+ assert(s[s.size()] == 0);
+ assert(s == "-12345.000000");
+ }
+}
+
+int main()
+{
+ test_signed<int>();
+ test_signed<long>();
+ test_signed<long long>();
+ test_unsigned<unsigned>();
+ test_unsigned<unsigned long>();
+ test_unsigned<unsigned long long>();
+ test_float<float>();
+ test_float<double>();
+ test_float<long double>();
+}
diff --git a/libcxx/test/strings/string.conversions/to_wstring.pass.cpp b/libcxx/test/strings/string.conversions/to_wstring.pass.cpp
new file mode 100644
index 00000000000..a96abf2e705
--- /dev/null
+++ b/libcxx/test/strings/string.conversions/to_wstring.pass.cpp
@@ -0,0 +1,126 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// wstring to_wstring(int val);
+// wstring to_wstring(unsigned val);
+// wstring to_wstring(long val);
+// wstring to_wstring(unsigned long val);
+// wstring to_wstring(long long val);
+// wstring to_wstring(unsigned long long val);
+// wstring to_wstring(float val);
+// wstring to_wstring(double val);
+// wstring to_wstring(long double val);
+
+#include <string>
+#include <cassert>
+#include <sstream>
+
+template <class T>
+void
+test_signed()
+{
+ {
+ std::wstring s = std::to_wstring(T(0));
+ assert(s.size() == 1);
+ assert(s[s.size()] == 0);
+ assert(s == L"0");
+ }
+ {
+ std::wstring s = std::to_wstring(T(12345));
+ assert(s.size() == 5);
+ assert(s[s.size()] == 0);
+ assert(s == L"12345");
+ }
+ {
+ std::wstring s = std::to_wstring(T(-12345));
+ assert(s.size() == 6);
+ assert(s[s.size()] == 0);
+ assert(s == L"-12345");
+ }
+ {
+ std::wstring s = std::to_wstring(std::numeric_limits<T>::max());
+ assert(s.size() == std::numeric_limits<T>::digits10 + 1);
+ std::wistringstream is(s);
+ T t(0);
+ is >> t;
+ assert(t == std::numeric_limits<T>::max());
+ }
+ {
+ std::wstring s = std::to_wstring(std::numeric_limits<T>::min());
+ std::wistringstream is(s);
+ T t(0);
+ is >> t;
+ assert(t == std::numeric_limits<T>::min());
+ }
+}
+
+template <class T>
+void
+test_unsigned()
+{
+ {
+ std::wstring s = std::to_wstring(T(0));
+ assert(s.size() == 1);
+ assert(s[s.size()] == 0);
+ assert(s == L"0");
+ }
+ {
+ std::wstring s = std::to_wstring(T(12345));
+ assert(s.size() == 5);
+ assert(s[s.size()] == 0);
+ assert(s == L"12345");
+ }
+ {
+ std::wstring s = std::to_wstring(std::numeric_limits<T>::max());
+ assert(s.size() == std::numeric_limits<T>::digits10 + 1);
+ std::wistringstream is(s);
+ T t(0);
+ is >> t;
+ assert(t == std::numeric_limits<T>::max());
+ }
+}
+
+template <class T>
+void
+test_float()
+{
+ {
+ std::wstring s = std::to_wstring(T(0));
+ assert(s.size() == 8);
+ assert(s[s.size()] == 0);
+ assert(s == L"0.000000");
+ }
+ {
+ std::wstring s = std::to_wstring(T(12345));
+ assert(s.size() == 12);
+ assert(s[s.size()] == 0);
+ assert(s == L"12345.000000");
+ }
+ {
+ std::wstring s = std::to_wstring(T(-12345));
+ assert(s.size() == 13);
+ assert(s[s.size()] == 0);
+ assert(s == L"-12345.000000");
+ }
+}
+
+int main()
+{
+ test_signed<int>();
+ test_signed<long>();
+ test_signed<long long>();
+ test_unsigned<unsigned>();
+ test_unsigned<unsigned long>();
+ test_unsigned<unsigned long long>();
+ test_float<float>();
+ test_float<double>();
+ test_float<long double>();
+}
OpenPOWER on IntegriCloud