From 5a83710e371fe68a06e6e3876c6a2c8b820a8976 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 20 Dec 2014 01:40:03 +0000 Subject: Move test into test/std subdirectory. llvm-svn: 224658 --- .../std/strings/string.conversions/stoi.pass.cpp | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 libcxx/test/std/strings/string.conversions/stoi.pass.cpp (limited to 'libcxx/test/std/strings/string.conversions/stoi.pass.cpp') diff --git a/libcxx/test/std/strings/string.conversions/stoi.pass.cpp b/libcxx/test/std/strings/string.conversions/stoi.pass.cpp new file mode 100644 index 00000000000..c2fc2103579 --- /dev/null +++ b/libcxx/test/std/strings/string.conversions/stoi.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// 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 +#include + +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::max() > std::numeric_limits::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); + } +} -- cgit v1.2.3