diff options
Diffstat (limited to 'libcxx/test/std/strings/basic.string')
19 files changed, 1392 insertions, 5 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.cons/string_view.fail.cpp b/libcxx/test/std/strings/basic.string/string.cons/string_view.fail.cpp new file mode 100644 index 00000000000..70459b2dcfb --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.cons/string_view.fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// explicit basic_string(basic_string_view<CharT, traits> sv, const Allocator& a = Allocator()); + +#include <string> +#include <string_view> + +void foo ( const string &s ) {} + +int main() +{ + std::string_view sv = "ABCDE"; + foo(sv); // requires implicit conversion from string_view to string +} diff --git a/libcxx/test/std/strings/basic.string/string.cons/string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/string_view.pass.cpp new file mode 100644 index 00000000000..d0e1a1699a2 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.cons/string_view.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// explicit basic_string(basic_string_view<CharT, traits> sv, const Allocator& a = Allocator()); + +#include <string> +#include <string_view> +#include <stdexcept> +#include <algorithm> +#include <cassert> + +#include "test_macros.h" +#include "test_allocator.h" +#include "min_allocator.h" + +template <class charT> +void +test(std::basic_string_view<charT> sv) +{ + typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; + typedef typename S::traits_type T; + typedef typename S::allocator_type A; + S s2(sv); + LIBCPP_ASSERT(s2.__invariants()); + assert(s2.size() == sv.size()); + assert(T::compare(s2.data(), sv.data(), sv.size()) == 0); + assert(s2.get_allocator() == A()); + assert(s2.capacity() >= s2.size()); +} + +template <class charT, class A> +void +test(std::basic_string_view<charT> sv, const A& a) +{ + typedef std::basic_string<charT, std::char_traits<charT>, A> S; + typedef typename S::traits_type T; + S s2(sv, a); + LIBCPP_ASSERT(s2.__invariants()); + assert(s2.size() == sv.size()); + assert(T::compare(s2.data(), sv.data(), sv.size()) == 0); + assert(s2.get_allocator() == a); + assert(s2.capacity() >= s2.size()); +} + +int main() +{ + { + typedef test_allocator<char> A; + typedef std::basic_string_view<char, std::char_traits<char> > SV; + + test(SV("")); + test(SV(""), A(2)); + + test(SV("1")); + test(SV("1") ,A(2)); + + test(SV("1234567980")); + test(SV("1234567980"), A(2)); + + test(SV("123456798012345679801234567980123456798012345679801234567980")); + test(SV("123456798012345679801234567980123456798012345679801234567980"), A(2)); + } +#if TEST_STD_VER >= 11 + { + typedef min_allocator<char> A; + typedef std::basic_string_view<char, std::char_traits<char> > SV; + + test(SV("")); + test(SV(""), A()); + + test(SV("1")); + test(SV("1") ,A()); + + test(SV("1234567980")); + test(SV("1234567980"), A()); + + test(SV("123456798012345679801234567980123456798012345679801234567980")); + test(SV("123456798012345679801234567980123456798012345679801234567980"), A()); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp new file mode 100644 index 00000000000..2d85b15fa37 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string<charT,traits,Allocator>& +// append(basic_string_view<charT,traits> sv); + +#include <string> +#include <string_view> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +template <class S, class SV> +void +test(S s, SV sv, S expected) +{ + s.append(sv); + LIBCPP_ASSERT(s.__invariants()); + assert(s == expected); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(), SV(), S()); + test(S(), SV("12345"), S("12345")); + test(S(), SV("1234567890"), S("1234567890")); + test(S(), SV("12345678901234567890"), S("12345678901234567890")); + + test(S("12345"), SV(), S("12345")); + test(S("12345"), SV("12345"), S("1234512345")); + test(S("12345"), SV("1234567890"), S("123451234567890")); + test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890")); + + test(S("1234567890"), SV(), S("1234567890")); + test(S("1234567890"), SV("12345"), S("123456789012345")); + test(S("1234567890"), SV("1234567890"), S("12345678901234567890")); + test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890")); + + test(S("12345678901234567890"), SV(), S("12345678901234567890")); + test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345")); + test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890")); + test(S("12345678901234567890"), SV("12345678901234567890"), + S("1234567890123456789012345678901234567890")); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char> > SV; + test(S(), SV(), S()); + test(S(), SV("12345"), S("12345")); + test(S(), SV("1234567890"), S("1234567890")); + test(S(), SV("12345678901234567890"), S("12345678901234567890")); + + test(S("12345"), SV(), S("12345")); + test(S("12345"), SV("12345"), S("1234512345")); + test(S("12345"), SV("1234567890"), S("123451234567890")); + test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890")); + + test(S("1234567890"), SV(), S("1234567890")); + test(S("1234567890"), SV("12345"), S("123456789012345")); + test(S("1234567890"), SV("1234567890"), S("12345678901234567890")); + test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890")); + + test(S("12345678901234567890"), SV(), S("12345678901234567890")); + test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345")); + test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890")); + test(S("12345678901234567890"), SV("12345678901234567890"), + S("1234567890123456789012345678901234567890")); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view_size_size.pass.cpp new file mode 100644 index 00000000000..58585f4ae47 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view_size_size.pass.cpp @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-no-exceptions +// <string> + +// basic_string<charT,traits,Allocator>& +// append(basic_string_view<charT,traits> sv, size_type pos, size_type n = npos); +// the "= npos" was added for C++14 + +#include <string> +#include <string> +#include <stdexcept> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +template <class S, class SV> +void +test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected) +{ + try + { + s.append(sv, pos, n); + LIBCPP_ASSERT(s.__invariants()); + assert(pos <= sv.size()); + assert(s == expected); + } + catch (std::out_of_range&) + { + assert(pos > sv.size()); + } +} + +template <class S, class SV> +void +test_npos(S s, SV sv, typename S::size_type pos, S expected) +{ + try + { + s.append(sv, pos); + LIBCPP_ASSERT(s.__invariants()); + assert(pos <= sv.size()); + assert(s == expected); + } + catch (std::out_of_range&) + { + assert(pos > sv.size()); + } +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(), SV(), 0, 0, S()); + test(S(), SV(), 1, 0, S()); + test(S(), SV("12345"), 0, 3, S("123")); + test(S(), SV("12345"), 1, 4, S("2345")); + test(S(), SV("12345"), 3, 15, S("45")); + test(S(), SV("12345"), 5, 15, S("")); + test(S(), SV("12345"), 6, 15, S("not happening")); + test(S(), SV("12345678901234567890"), 0, 0, S()); + test(S(), SV("12345678901234567890"), 1, 1, S("2")); + test(S(), SV("12345678901234567890"), 2, 3, S("345")); + test(S(), SV("12345678901234567890"), 12, 13, S("34567890")); + test(S(), SV("12345678901234567890"), 21, 13, S("not happening")); + + test(S("12345"), SV(), 0, 0, S("12345")); + test(S("12345"), SV("12345"), 2, 2, S("1234534")); + test(S("12345"), SV("1234567890"), 0, 100, S("123451234567890")); + + test(S("12345678901234567890"), SV(), 0, 0, S("12345678901234567890")); + test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234")); + test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, + S("123456789012345678906789012345")); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char> > SV; + test(S(), SV(), 0, 0, S()); + test(S(), SV(), 1, 0, S()); + test(S(), SV("12345"), 0, 3, S("123")); + test(S(), SV("12345"), 1, 4, S("2345")); + test(S(), SV("12345"), 3, 15, S("45")); + test(S(), SV("12345"), 5, 15, S("")); + test(S(), SV("12345"), 6, 15, S("not happening")); + test(S(), SV("12345678901234567890"), 0, 0, S()); + test(S(), SV("12345678901234567890"), 1, 1, S("2")); + test(S(), SV("12345678901234567890"), 2, 3, S("345")); + test(S(), SV("12345678901234567890"), 12, 13, S("34567890")); + test(S(), SV("12345678901234567890"), 21, 13, S("not happening")); + + test(S("12345"), SV(), 0, 0, S("12345")); + test(S("12345"), SV("12345"), 2, 2, S("1234534")); + test(S("12345"), SV("1234567890"), 0, 100, S("123451234567890")); + + test(S("12345678901234567890"), SV(), 0, 0, S("12345678901234567890")); + test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234")); + test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, + S("123456789012345678906789012345")); + } +#endif + { + typedef std::string S; + typedef std::string_view SV; + test_npos(S(), SV(), 0, S()); + test_npos(S(), SV(), 1, S()); + test_npos(S(), SV("12345"), 0, S("12345")); + test_npos(S(), SV("12345"), 1, S("2345")); + test_npos(S(), SV("12345"), 3, S("45")); + test_npos(S(), SV("12345"), 5, S("")); + test_npos(S(), SV("12345"), 6, S("not happening")); + } +} diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view.pass.cpp new file mode 100644 index 00000000000..e56b094a36e --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string<charT,traits,Allocator>& +// assign(basic_string_view<charT,traits> sv); + +#include <string> +#include <string_view> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" +#include "test_allocator.h" + +template <class S, class SV> +void +test(S s, SV sv, S expected) +{ + s.assign(sv); + LIBCPP_ASSERT(s.__invariants()); + assert(s == expected); +} + +template <class S, class SV> +void +testAlloc(S s, SV sv, const typename S::allocator_type& a) +{ + s.assign(sv); + LIBCPP_ASSERT(s.__invariants()); + assert(s == sv); + assert(s.get_allocator() == a); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(), SV(), S()); + test(S(), SV("12345"), S("12345")); + test(S(), SV("1234567890"), S("1234567890")); + test(S(), SV("12345678901234567890"), S("12345678901234567890")); + + test(S("12345"), SV(), S()); + test(S("12345"), SV("12345"), S("12345")); + test(S("12345"), SV("1234567890"), S("1234567890")); + test(S("12345"), SV("12345678901234567890"), S("12345678901234567890")); + + test(S("1234567890"), SV(), S()); + test(S("1234567890"), SV("12345"), S("12345")); + test(S("1234567890"), SV("1234567890"), S("1234567890")); + test(S("1234567890"), SV("12345678901234567890"), S("12345678901234567890")); + + test(S("12345678901234567890"), SV(), S()); + test(S("12345678901234567890"), SV("12345"), S("12345")); + test(S("12345678901234567890"), SV("1234567890"), S("1234567890")); + test(S("12345678901234567890"), SV("12345678901234567890"), + S("12345678901234567890")); + + testAlloc(S(), SV(), std::allocator<char>()); + testAlloc(S(), SV("12345"), std::allocator<char>()); + testAlloc(S(), SV("1234567890"), std::allocator<char>()); + testAlloc(S(), SV("12345678901234567890"), std::allocator<char>()); + } + +#if TEST_STD_VER >= 11 + { + typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char> > SV; + test(S(), SV(), S()); + test(S(), SV("12345"), S("12345")); + test(S(), SV("1234567890"), S("1234567890")); + test(S(), SV("12345678901234567890"), S("12345678901234567890")); + + test(S("12345"), SV(), S()); + test(S("12345"), SV("12345"), S("12345")); + test(S("12345"), SV("1234567890"), S("1234567890")); + test(S("12345"), SV("12345678901234567890"), S("12345678901234567890")); + + test(S("1234567890"), SV(), S()); + test(S("1234567890"), SV("12345"), S("12345")); + test(S("1234567890"), SV("1234567890"), S("1234567890")); + test(S("1234567890"), SV("12345678901234567890"), S("12345678901234567890")); + + test(S("12345678901234567890"), SV(), S()); + test(S("12345678901234567890"), SV("12345"), S("12345")); + test(S("12345678901234567890"), SV("1234567890"), S("1234567890")); + test(S("12345678901234567890"), SV("12345678901234567890"), + S("12345678901234567890")); + + testAlloc(S(), SV(), min_allocator<char>()); + testAlloc(S(), SV("12345"), min_allocator<char>()); + testAlloc(S(), SV("1234567890"), min_allocator<char>()); + testAlloc(S(), SV("12345678901234567890"), min_allocator<char>()); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view_size_size.pass.cpp new file mode 100644 index 00000000000..1eb18d8bffa --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view_size_size.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-no-exceptions +// <string> + +// basic_string<charT,traits,Allocator>& +// assign(basic_string_view<charT,traits> sv, size_type pos, size_type n=npos); +// the =npos was added for C++14 + +#include <string> +#include <stdexcept> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +template <class S, class SV> +void +test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected) +{ + try + { + s.assign(sv, pos, n); + LIBCPP_ASSERT(s.__invariants()); + assert(pos <= sv.size()); + assert(s == expected); + } + catch (std::out_of_range&) + { + assert(pos > sv.size()); + } +} + +template <class S, class SV> +void +test_npos(S s, SV sv, typename S::size_type pos, S expected) +{ + try + { + s.assign(sv, pos); + LIBCPP_ASSERT(s.__invariants()); + assert(pos <= sv.size()); + assert(s == expected); + } + catch (std::out_of_range&) + { + assert(pos > sv.size()); + } +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(), SV(), 0, 0, S()); + test(S(), SV(), 1, 0, S()); + test(S(), SV("12345"), 0, 3, S("123")); + test(S(), SV("12345"), 1, 4, S("2345")); + test(S(), SV("12345"), 3, 15, S("45")); + test(S(), SV("12345"), 5, 15, S("")); + test(S(), SV("12345"), 6, 15, S("not happening")); + test(S(), SV("12345678901234567890"), 0, 0, S()); + test(S(), SV("12345678901234567890"), 1, 1, S("2")); + test(S(), SV("12345678901234567890"), 2, 3, S("345")); + test(S(), SV("12345678901234567890"), 12, 13, S("34567890")); + test(S(), SV("12345678901234567890"), 21, 13, S("not happening")); + + test(S("12345"), SV(), 0, 0, S()); + test(S("12345"), SV("12345"), 2, 2, S("34")); + test(S("12345"), SV("1234567890"), 0, 100, S("1234567890")); + + test(S("12345678901234567890"), SV(), 0, 0, S()); + test(S("12345678901234567890"), SV("12345"), 1, 3, S("234")); + test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, + S("6789012345")); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char> > SV; + test(S(), SV(), 0, 0, S()); + test(S(), SV(), 1, 0, S()); + test(S(), SV("12345"), 0, 3, S("123")); + test(S(), SV("12345"), 1, 4, S("2345")); + test(S(), SV("12345"), 3, 15, S("45")); + test(S(), SV("12345"), 5, 15, S("")); + test(S(), SV("12345"), 6, 15, S("not happening")); + test(S(), SV("12345678901234567890"), 0, 0, S()); + test(S(), SV("12345678901234567890"), 1, 1, S("2")); + test(S(), SV("12345678901234567890"), 2, 3, S("345")); + test(S(), SV("12345678901234567890"), 12, 13, S("34567890")); + test(S(), SV("12345678901234567890"), 21, 13, S("not happening")); + + test(S("12345"), SV(), 0, 0, S()); + test(S("12345"), SV("12345"), 2, 2, S("34")); + test(S("12345"), SV("1234567890"), 0, 100, S("1234567890")); + + test(S("12345678901234567890"), SV(), 0, 0, S()); + test(S("12345678901234567890"), SV("12345"), 1, 3, S("234")); + test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, + S("6789012345")); + } +#endif + { + typedef std::string S; + typedef std::string_view SV; + test_npos(S(), SV(), 0, S()); + test_npos(S(), SV(), 1, S()); + test_npos(S(), SV("12345"), 0, S("12345")); + test_npos(S(), SV("12345"), 1, S("2345")); + test_npos(S(), SV("12345"), 3, S("45")); + test_npos(S(), SV("12345"), 5, S("")); + test_npos(S(), SV("12345"), 6, S("not happening")); + } +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string_view.pass.cpp new file mode 100644 index 00000000000..65649465da2 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string_view.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& lhs, SV rhs, bool x) +{ + assert((lhs != rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string SV; + test(S(""), SV(""), false); + test(S(""), SV("abcde"), true); + test(S(""), SV("abcdefghij"), true); + test(S(""), SV("abcdefghijklmnopqrst"), true); + test(S("abcde"), SV(""), true); + test(S("abcde"), SV("abcde"), false); + test(S("abcde"), SV("abcdefghij"), true); + test(S("abcde"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghij"), SV(""), true); + test(S("abcdefghij"), SV("abcde"), true); + test(S("abcdefghij"), SV("abcdefghij"), false); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghijklmnopqrst"), SV(""), true); + test(S("abcdefghijklmnopqrst"), SV("abcde"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(S(""), SV(""), false); + test(S(""), SV("abcde"), true); + test(S(""), SV("abcdefghij"), true); + test(S(""), SV("abcdefghijklmnopqrst"), true); + test(S("abcde"), SV(""), true); + test(S("abcde"), SV("abcde"), false); + test(S("abcde"), SV("abcdefghij"), true); + test(S("abcde"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghij"), SV(""), true); + test(S("abcdefghij"), SV("abcde"), true); + test(S("abcdefghij"), SV("abcdefghij"), false); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghijklmnopqrst"), SV(""), true); + test(S("abcdefghijklmnopqrst"), SV("abcde"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp new file mode 100644 index 00000000000..88c758c7aa7 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(SV lhs, const S& rhs, bool x) +{ + assert((lhs != rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(SV(""), S(""), false); + test(SV(""), S("abcde"), true); + test(SV(""), S("abcdefghij"), true); + test(SV(""), S("abcdefghijklmnopqrst"), true); + test(SV("abcde"), S(""), true); + test(SV("abcde"), S("abcde"), false); + test(SV("abcde"), S("abcdefghij"), true); + test(SV("abcde"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghij"), S(""), true); + test(SV("abcdefghij"), S("abcde"), true); + test(SV("abcdefghij"), S("abcdefghij"), false); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghijklmnopqrst"), S(""), true); + test(SV("abcdefghijklmnopqrst"), S("abcde"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(SV(""), S(""), false); + test(SV(""), S("abcde"), true); + test(SV(""), S("abcdefghij"), true); + test(SV(""), S("abcdefghijklmnopqrst"), true); + test(SV("abcde"), S(""), true); + test(SV("abcde"), S("abcde"), false); + test(SV("abcde"), S("abcdefghij"), true); + test(SV("abcde"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghij"), S(""), true); + test(SV("abcdefghij"), S("abcde"), true); + test(SV("abcdefghij"), S("abcdefghij"), false); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghijklmnopqrst"), S(""), true); + test(SV("abcdefghijklmnopqrst"), S("abcde"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_operator==/string_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_operator==/string_string_view.pass.cpp new file mode 100644 index 00000000000..f72d1c20a45 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_operator==/string_string_view.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& lhs, SV rhs, bool x) +{ + assert((lhs == rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(""), SV(""), true); + test(S(""), SV("abcde"), false); + test(S(""), SV("abcdefghij"), false); + test(S(""), SV("abcdefghijklmnopqrst"), false); + test(S("abcde"), SV(""), false); + test(S("abcde"), SV("abcde"), true); + test(S("abcde"), SV("abcdefghij"), false); + test(S("abcde"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghij"), SV(""), false); + test(S("abcdefghij"), SV("abcde"), false); + test(S("abcdefghij"), SV("abcdefghij"), true); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghijklmnopqrst"), SV(""), false); + test(S("abcdefghijklmnopqrst"), SV("abcde"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), true); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(S(""), SV(""), true); + test(S(""), SV("abcde"), false); + test(S(""), SV("abcdefghij"), false); + test(S(""), SV("abcdefghijklmnopqrst"), false); + test(S("abcde"), SV(""), false); + test(S("abcde"), SV("abcde"), true); + test(S("abcde"), SV("abcdefghij"), false); + test(S("abcde"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghij"), SV(""), false); + test(S("abcdefghij"), SV("abcde"), false); + test(S("abcdefghij"), SV("abcdefghij"), true); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghijklmnopqrst"), SV(""), false); + test(S("abcdefghijklmnopqrst"), SV("abcde"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), true); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_operator==/string_view_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_operator==/string_view_string.pass.cpp new file mode 100644 index 00000000000..2cd80865905 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_operator==/string_view_string.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(SV lhs, const S& rhs, bool x) +{ + assert((lhs == rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(SV(""), S(""), true); + test(SV(""), S("abcde"), false); + test(SV(""), S("abcdefghij"), false); + test(SV(""), S("abcdefghijklmnopqrst"), false); + test(SV("abcde"), S(""), false); + test(SV("abcde"), S("abcde"), true); + test(SV("abcde"), S("abcdefghij"), false); + test(SV("abcde"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghij"), S(""), false); + test(SV("abcdefghij"), S("abcde"), false); + test(SV("abcdefghij"), S("abcdefghij"), true); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghijklmnopqrst"), S(""), false); + test(SV("abcdefghijklmnopqrst"), S("abcde"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(SV(""), S(""), true); + test(SV(""), S("abcde"), false); + test(SV(""), S("abcdefghij"), false); + test(SV(""), S("abcdefghijklmnopqrst"), false); + test(SV("abcde"), S(""), false); + test(SV("abcde"), S("abcde"), true); + test(SV("abcde"), S("abcdefghij"), false); + test(SV("abcde"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghij"), S(""), false); + test(SV("abcdefghij"), S("abcde"), false); + test(SV("abcdefghij"), S("abcdefghij"), true); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghijklmnopqrst"), S(""), false); + test(SV("abcdefghijklmnopqrst"), S("abcde"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt/string_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt/string_string_view.pass.cpp new file mode 100644 index 00000000000..d9f5d7106db --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt/string_string_view.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& lhs, SV rhs, bool x) +{ + assert((lhs > rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(""), SV(""), false); + test(S(""), SV("abcde"), false); + test(S(""), SV("abcdefghij"), false); + test(S(""), SV("abcdefghijklmnopqrst"), false); + test(S("abcde"), SV(""), true); + test(S("abcde"), SV("abcde"), false); + test(S("abcde"), SV("abcdefghij"), false); + test(S("abcde"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghij"), SV(""), true); + test(S("abcdefghij"), SV("abcde"), true); + test(S("abcdefghij"), SV("abcdefghij"), false); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghijklmnopqrst"), SV(""), true); + test(S("abcdefghijklmnopqrst"), SV("abcde"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(S(""), SV(""), false); + test(S(""), SV("abcde"), false); + test(S(""), SV("abcdefghij"), false); + test(S(""), SV("abcdefghijklmnopqrst"), false); + test(S("abcde"), SV(""), true); + test(S("abcde"), SV("abcde"), false); + test(S("abcde"), SV("abcdefghij"), false); + test(S("abcde"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghij"), SV(""), true); + test(S("abcdefghij"), SV("abcde"), true); + test(S("abcdefghij"), SV("abcdefghij"), false); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghijklmnopqrst"), SV(""), true); + test(S("abcdefghijklmnopqrst"), SV("abcde"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt/string_view_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt/string_view_string.pass.cpp new file mode 100644 index 00000000000..c685bab8fc1 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt/string_view_string.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(SV lhs, const S& rhs, bool x) +{ + assert((lhs > rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(SV(""), S(""), false); + test(SV(""), S("abcde"), false); + test(SV(""), S("abcdefghij"), false); + test(SV(""), S("abcdefghijklmnopqrst"), false); + test(SV("abcde"), S(""), true); + test(SV("abcde"), S("abcde"), false); + test(SV("abcde"), S("abcdefghij"), false); + test(SV("abcde"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghij"), S(""), true); + test(SV("abcdefghij"), S("abcde"), true); + test(SV("abcdefghij"), S("abcdefghij"), false); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghijklmnopqrst"), S(""), true); + test(SV("abcdefghijklmnopqrst"), S("abcde"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(SV(""), S(""), false); + test(SV(""), S("abcde"), false); + test(SV(""), S("abcdefghij"), false); + test(SV(""), S("abcdefghijklmnopqrst"), false); + test(SV("abcde"), S(""), true); + test(SV("abcde"), S("abcde"), false); + test(SV("abcde"), S("abcdefghij"), false); + test(SV("abcde"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghij"), S(""), true); + test(SV("abcdefghij"), S("abcde"), true); + test(SV("abcdefghij"), S("abcdefghij"), false); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghijklmnopqrst"), S(""), true); + test(SV("abcdefghijklmnopqrst"), S("abcde"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt=/string_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt=/string_string_view.pass.cpp new file mode 100644 index 00000000000..5b9671fca1d --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt=/string_string_view.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& lhs, SV rhs, bool x) +{ + assert((lhs >= rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(""), SV(""), true); + test(S(""), SV("abcde"), false); + test(S(""), SV("abcdefghij"), false); + test(S(""), SV("abcdefghijklmnopqrst"), false); + test(S("abcde"), SV(""), true); + test(S("abcde"), SV("abcde"), true); + test(S("abcde"), SV("abcdefghij"), false); + test(S("abcde"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghij"), SV(""), true); + test(S("abcdefghij"), SV("abcde"), true); + test(S("abcdefghij"), SV("abcdefghij"), true); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghijklmnopqrst"), SV(""), true); + test(S("abcdefghijklmnopqrst"), SV("abcde"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), true); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(S(""), SV(""), true); + test(S(""), SV("abcde"), false); + test(S(""), SV("abcdefghij"), false); + test(S(""), SV("abcdefghijklmnopqrst"), false); + test(S("abcde"), SV(""), true); + test(S("abcde"), SV("abcde"), true); + test(S("abcde"), SV("abcdefghij"), false); + test(S("abcde"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghij"), SV(""), true); + test(S("abcdefghij"), SV("abcde"), true); + test(S("abcdefghij"), SV("abcdefghij"), true); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false); + test(S("abcdefghijklmnopqrst"), SV(""), true); + test(S("abcdefghijklmnopqrst"), SV("abcde"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), true); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt=/string_view_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt=/string_view_string.pass.cpp new file mode 100644 index 00000000000..07c8282a740 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_opgt=/string_view_string.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(SV lhs, const S& rhs, bool x) +{ + assert((lhs >= rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(SV(""), S(""), true); + test(SV(""), S("abcde"), false); + test(SV(""), S("abcdefghij"), false); + test(SV(""), S("abcdefghijklmnopqrst"), false); + test(SV("abcde"), S(""), true); + test(SV("abcde"), S("abcde"), true); + test(SV("abcde"), S("abcdefghij"), false); + test(SV("abcde"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghij"), S(""), true); + test(SV("abcdefghij"), S("abcde"), true); + test(SV("abcdefghij"), S("abcdefghij"), true); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghijklmnopqrst"), S(""), true); + test(SV("abcdefghijklmnopqrst"), S("abcde"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(SV(""), S(""), true); + test(SV(""), S("abcde"), false); + test(SV(""), S("abcdefghij"), false); + test(SV(""), S("abcdefghijklmnopqrst"), false); + test(SV("abcde"), S(""), true); + test(SV("abcde"), S("abcde"), true); + test(SV("abcde"), S("abcdefghij"), false); + test(SV("abcde"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghij"), S(""), true); + test(SV("abcdefghij"), S("abcde"), true); + test(SV("abcdefghij"), S("abcdefghij"), true); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), false); + test(SV("abcdefghijklmnopqrst"), S(""), true); + test(SV("abcdefghijklmnopqrst"), S("abcde"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt/string_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt/string_string_view.pass.cpp new file mode 100644 index 00000000000..8fef8e60a96 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt/string_string_view.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& lhs, SV rhs, bool x) +{ + assert((lhs < rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(""), SV(""), false); + test(S(""), SV("abcde"), true); + test(S(""), SV("abcdefghij"), true); + test(S(""), SV("abcdefghijklmnopqrst"), true); + test(S("abcde"), SV(""), false); + test(S("abcde"), SV("abcde"), false); + test(S("abcde"), SV("abcdefghij"), true); + test(S("abcde"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghij"), SV(""), false); + test(S("abcdefghij"), SV("abcde"), false); + test(S("abcdefghij"), SV("abcdefghij"), false); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghijklmnopqrst"), SV(""), false); + test(S("abcdefghijklmnopqrst"), SV("abcde"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(S(""), SV(""), false); + test(S(""), SV("abcde"), true); + test(S(""), SV("abcdefghij"), true); + test(S(""), SV("abcdefghijklmnopqrst"), true); + test(S("abcde"), SV(""), false); + test(S("abcde"), SV("abcde"), false); + test(S("abcde"), SV("abcdefghij"), true); + test(S("abcde"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghij"), SV(""), false); + test(S("abcdefghij"), SV("abcde"), false); + test(S("abcdefghij"), SV("abcdefghij"), false); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghijklmnopqrst"), SV(""), false); + test(S("abcdefghijklmnopqrst"), SV("abcde"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt/string_view_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt/string_view_string.pass.cpp new file mode 100644 index 00000000000..80da8cd0048 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt/string_view_string.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(SV lhs, const S& rhs, bool x) +{ + assert((lhs < rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(SV(""), S(""), false); + test(SV(""), S("abcde"), true); + test(SV(""), S("abcdefghij"), true); + test(SV(""), S("abcdefghijklmnopqrst"), true); + test(SV("abcde"), S(""), false); + test(SV("abcde"), S("abcde"), false); + test(SV("abcde"), S("abcdefghij"), true); + test(SV("abcde"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghij"), S(""), false); + test(SV("abcdefghij"), S("abcde"), false); + test(SV("abcdefghij"), S("abcdefghij"), false); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghijklmnopqrst"), S(""), false); + test(SV("abcdefghijklmnopqrst"), S("abcde"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(SV(""), S(""), false); + test(SV(""), S("abcde"), true); + test(SV(""), S("abcdefghij"), true); + test(SV(""), S("abcdefghijklmnopqrst"), true); + test(SV("abcde"), S(""), false); + test(SV("abcde"), S("abcde"), false); + test(SV("abcde"), S("abcdefghij"), true); + test(SV("abcde"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghij"), S(""), false); + test(SV("abcdefghij"), S("abcde"), false); + test(SV("abcdefghij"), S("abcdefghij"), false); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghijklmnopqrst"), S(""), false); + test(SV("abcdefghijklmnopqrst"), S("abcde"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt=/string_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt=/string_string_view.pass.cpp new file mode 100644 index 00000000000..97a9d7cc717 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt=/string_string_view.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& lhs, SV rhs, bool x) +{ + assert((lhs <= rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(""), SV(""), true); + test(S(""), SV("abcde"), true); + test(S(""), SV("abcdefghij"), true); + test(S(""), SV("abcdefghijklmnopqrst"), true); + test(S("abcde"), SV(""), false); + test(S("abcde"), SV("abcde"), true); + test(S("abcde"), SV("abcdefghij"), true); + test(S("abcde"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghij"), SV(""), false); + test(S("abcdefghij"), SV("abcde"), false); + test(S("abcdefghij"), SV("abcdefghij"), true); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghijklmnopqrst"), SV(""), false); + test(S("abcdefghijklmnopqrst"), SV("abcde"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), true); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(S(""), SV(""), true); + test(S(""), SV("abcde"), true); + test(S(""), SV("abcdefghij"), true); + test(S(""), SV("abcdefghijklmnopqrst"), true); + test(S("abcde"), SV(""), false); + test(S("abcde"), SV("abcde"), true); + test(S("abcde"), SV("abcdefghij"), true); + test(S("abcde"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghij"), SV(""), false); + test(S("abcdefghij"), SV("abcde"), false); + test(S("abcdefghij"), SV("abcdefghij"), true); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true); + test(S("abcdefghijklmnopqrst"), SV(""), false); + test(S("abcdefghijklmnopqrst"), SV("abcde"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), true); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt=/string_view_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt=/string_view_string.pass.cpp new file mode 100644 index 00000000000..f19a4aa0fd5 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt=/string_view_string.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(SV lhs, const S& rhs, bool x) +{ + assert((lhs <= rhs) == x); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(SV(""), S(""), true); + test(SV(""), S("abcde"), true); + test(SV(""), S("abcdefghij"), true); + test(SV(""), S("abcdefghijklmnopqrst"), true); + test(SV("abcde"), S(""), false); + test(SV("abcde"), S("abcde"), true); + test(SV("abcde"), S("abcdefghij"), true); + test(SV("abcde"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghij"), S(""), false); + test(SV("abcdefghij"), S("abcde"), false); + test(SV("abcdefghij"), S("abcdefghij"), true); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghijklmnopqrst"), S(""), false); + test(SV("abcdefghijklmnopqrst"), S("abcde"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::basic_string_view<char, std::char_traits<char>> SV; + test(SV(""), S(""), true); + test(SV(""), S("abcde"), true); + test(SV(""), S("abcdefghij"), true); + test(SV(""), S("abcdefghijklmnopqrst"), true); + test(SV("abcde"), S(""), false); + test(SV("abcde"), S("abcde"), true); + test(SV("abcde"), S("abcdefghij"), true); + test(SV("abcde"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghij"), S(""), false); + test(SV("abcdefghij"), S("abcde"), false); + test(SV("abcdefghij"), S("abcdefghij"), true); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true); + test(SV("abcdefghijklmnopqrst"), S(""), false); + test(SV("abcdefghijklmnopqrst"), S("abcde"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), false); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true); + } +#endif +} diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp index 3cbbea7b490..10f9d849c2b 100644 --- a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp @@ -31,7 +31,7 @@ int sign(int x) template <class S> void -test(const S& s, typename S::size_type pos1, typename S::size_type n1, +test(const S& s, typename S::size_type pos1, typename S::size_type n1, const S& str, typename S::size_type pos2, typename S::size_type n2, int x) { try @@ -40,7 +40,7 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1, assert(pos1 <= s.size()); assert(pos2 <= str.size()); } - catch (std::out_of_range&) + catch (const std::out_of_range&) { assert(pos1 > s.size() || pos2 > str.size()); } @@ -48,8 +48,8 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1, template <class S> void -test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1, - const S& str, typename S::size_type pos2, int x) +test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1, + const S& str, typename S::size_type pos2, int x) { try { @@ -57,7 +57,7 @@ test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1, assert(pos1 <= s.size()); assert(pos2 <= str.size()); } - catch (std::out_of_range&) + catch (const std::out_of_range&) { assert(pos1 > s.size() || pos2 > str.size()); } |