Author: tstellar Date: Mon Nov 13 13:27:53 2017 New Revision: 318088 URL: http://llvm.org/viewvc/llvm-project?rev=318088&view=rev Log: Merging r312693:
------------------------------------------------------------------------ r312693 | marshall | 2017-09-06 21:19:32 -0700 (Wed, 06 Sep 2017) | 1 line Add even more string_view tests. These found some bugs in the default parameter value for rfind/find_last_of/find_last_not_of ------------------------------------------------------------------------ Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/string_view.pass.cpp libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_view_size.pass.cpp libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.of/string_view_size.pass.cpp libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.of/string_view_size.pass.cpp libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_rfind/string_view_size.pass.cpp Modified: libcxx/branches/release_50/include/string Modified: libcxx/branches/release_50/include/string URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/include/string?rev=318088&r1=318087&r2=318088&view=diff ============================================================================== --- libcxx/branches/release_50/include/string (original) +++ libcxx/branches/release_50/include/string Mon Nov 13 13:27:53 2017 @@ -259,7 +259,7 @@ public: size_type find(value_type c, size_type pos = 0) const noexcept; size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; - size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; + size_type rfind(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept; size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; size_type rfind(const value_type* s, size_type pos = npos) const noexcept; size_type rfind(value_type c, size_type pos = npos) const noexcept; @@ -271,7 +271,7 @@ public: size_type find_first_of(value_type c, size_type pos = 0) const noexcept; size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; - size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; + size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept; size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; size_type find_last_of(value_type c, size_type pos = npos) const noexcept; @@ -283,7 +283,7 @@ public: size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; - size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; + size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept; size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; @@ -1147,7 +1147,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; + size_type rfind(__self_view __sv, size_type __pos = npos) const _NOEXCEPT; size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; @@ -1166,7 +1166,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; + size_type find_last_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT; size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; @@ -1186,7 +1186,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; + size_type find_last_not_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT; size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp?rev=318088&view=auto ============================================================================== --- libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp (added) +++ libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp Mon Nov 13 13:27:53 2017 @@ -0,0 +1,383 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// int compare(size_type pos1, size_type n1, basic_string_vew sv) const; + +#include <string> +#include <stdexcept> +#include <cassert> + +#include "min_allocator.h" + +#include "test_macros.h" + +int sign(int x) +{ + if (x == 0) + return 0; + if (x < 0) + return -1; + return 1; +} + +template <class S, class SV> +void +test(const S& s, typename S::size_type pos1, typename S::size_type n1, + SV sv, int x) +{ + if (pos1 <= s.size()) + assert(sign(s.compare(pos1, n1, sv)) == sign(x)); +#ifndef TEST_HAS_NO_EXCEPTIONS + else + { + try + { + s.compare(pos1, n1, sv); + assert(false); + } + catch (std::out_of_range&) + { + assert(pos1 > s.size()); + } + } +#endif +} + +template <class S, class SV> +void test0() +{ + test(S(""), 0, 0, SV(""), 0); + test(S(""), 0, 0, SV("abcde"), -5); + test(S(""), 0, 0, SV("abcdefghij"), -10); + test(S(""), 0, 0, SV("abcdefghijklmnopqrst"), -20); + test(S(""), 0, 1, SV(""), 0); + test(S(""), 0, 1, SV("abcde"), -5); + test(S(""), 0, 1, SV("abcdefghij"), -10); + test(S(""), 0, 1, SV("abcdefghijklmnopqrst"), -20); + test(S(""), 1, 0, SV(""), 0); + test(S(""), 1, 0, SV("abcde"), 0); + test(S(""), 1, 0, SV("abcdefghij"), 0); + test(S(""), 1, 0, SV("abcdefghijklmnopqrst"), 0); + test(S("abcde"), 0, 0, SV(""), 0); + test(S("abcde"), 0, 0, SV("abcde"), -5); + test(S("abcde"), 0, 0, SV("abcdefghij"), -10); + test(S("abcde"), 0, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcde"), 0, 1, SV(""), 1); + test(S("abcde"), 0, 1, SV("abcde"), -4); + test(S("abcde"), 0, 1, SV("abcdefghij"), -9); + test(S("abcde"), 0, 1, SV("abcdefghijklmnopqrst"), -19); + test(S("abcde"), 0, 2, SV(""), 2); + test(S("abcde"), 0, 2, SV("abcde"), -3); + test(S("abcde"), 0, 2, SV("abcdefghij"), -8); + test(S("abcde"), 0, 2, SV("abcdefghijklmnopqrst"), -18); + test(S("abcde"), 0, 4, SV(""), 4); + test(S("abcde"), 0, 4, SV("abcde"), -1); + test(S("abcde"), 0, 4, SV("abcdefghij"), -6); + test(S("abcde"), 0, 4, SV("abcdefghijklmnopqrst"), -16); + test(S("abcde"), 0, 5, SV(""), 5); + test(S("abcde"), 0, 5, SV("abcde"), 0); + test(S("abcde"), 0, 5, SV("abcdefghij"), -5); + test(S("abcde"), 0, 5, SV("abcdefghijklmnopqrst"), -15); + test(S("abcde"), 0, 6, SV(""), 5); + test(S("abcde"), 0, 6, SV("abcde"), 0); + test(S("abcde"), 0, 6, SV("abcdefghij"), -5); + test(S("abcde"), 0, 6, SV("abcdefghijklmnopqrst"), -15); + test(S("abcde"), 1, 0, SV(""), 0); + test(S("abcde"), 1, 0, SV("abcde"), -5); + test(S("abcde"), 1, 0, SV("abcdefghij"), -10); + test(S("abcde"), 1, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcde"), 1, 1, SV(""), 1); + test(S("abcde"), 1, 1, SV("abcde"), 1); + test(S("abcde"), 1, 1, SV("abcdefghij"), 1); + test(S("abcde"), 1, 1, SV("abcdefghijklmnopqrst"), 1); + test(S("abcde"), 1, 2, SV(""), 2); + test(S("abcde"), 1, 2, SV("abcde"), 1); + test(S("abcde"), 1, 2, SV("abcdefghij"), 1); + test(S("abcde"), 1, 2, SV("abcdefghijklmnopqrst"), 1); + test(S("abcde"), 1, 3, SV(""), 3); + test(S("abcde"), 1, 3, SV("abcde"), 1); + test(S("abcde"), 1, 3, SV("abcdefghij"), 1); + test(S("abcde"), 1, 3, SV("abcdefghijklmnopqrst"), 1); + test(S("abcde"), 1, 4, SV(""), 4); + test(S("abcde"), 1, 4, SV("abcde"), 1); + test(S("abcde"), 1, 4, SV("abcdefghij"), 1); + test(S("abcde"), 1, 4, SV("abcdefghijklmnopqrst"), 1); + test(S("abcde"), 1, 5, SV(""), 4); + test(S("abcde"), 1, 5, SV("abcde"), 1); + test(S("abcde"), 1, 5, SV("abcdefghij"), 1); + test(S("abcde"), 1, 5, SV("abcdefghijklmnopqrst"), 1); + test(S("abcde"), 2, 0, SV(""), 0); + test(S("abcde"), 2, 0, SV("abcde"), -5); + test(S("abcde"), 2, 0, SV("abcdefghij"), -10); + test(S("abcde"), 2, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcde"), 2, 1, SV(""), 1); + test(S("abcde"), 2, 1, SV("abcde"), 2); + test(S("abcde"), 2, 1, SV("abcdefghij"), 2); + test(S("abcde"), 2, 1, SV("abcdefghijklmnopqrst"), 2); + test(S("abcde"), 2, 2, SV(""), 2); + test(S("abcde"), 2, 2, SV("abcde"), 2); + test(S("abcde"), 2, 2, SV("abcdefghij"), 2); + test(S("abcde"), 2, 2, SV("abcdefghijklmnopqrst"), 2); + test(S("abcde"), 2, 3, SV(""), 3); + test(S("abcde"), 2, 3, SV("abcde"), 2); + test(S("abcde"), 2, 3, SV("abcdefghij"), 2); + test(S("abcde"), 2, 3, SV("abcdefghijklmnopqrst"), 2); + test(S("abcde"), 2, 4, SV(""), 3); + test(S("abcde"), 2, 4, SV("abcde"), 2); + test(S("abcde"), 2, 4, SV("abcdefghij"), 2); + test(S("abcde"), 2, 4, SV("abcdefghijklmnopqrst"), 2); + test(S("abcde"), 4, 0, SV(""), 0); + test(S("abcde"), 4, 0, SV("abcde"), -5); + test(S("abcde"), 4, 0, SV("abcdefghij"), -10); + test(S("abcde"), 4, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcde"), 4, 1, SV(""), 1); + test(S("abcde"), 4, 1, SV("abcde"), 4); + test(S("abcde"), 4, 1, SV("abcdefghij"), 4); + test(S("abcde"), 4, 1, SV("abcdefghijklmnopqrst"), 4); + test(S("abcde"), 4, 2, SV(""), 1); + test(S("abcde"), 4, 2, SV("abcde"), 4); + test(S("abcde"), 4, 2, SV("abcdefghij"), 4); + test(S("abcde"), 4, 2, SV("abcdefghijklmnopqrst"), 4); + test(S("abcde"), 5, 0, SV(""), 0); + test(S("abcde"), 5, 0, SV("abcde"), -5); + test(S("abcde"), 5, 0, SV("abcdefghij"), -10); + test(S("abcde"), 5, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcde"), 5, 1, SV(""), 0); + test(S("abcde"), 5, 1, SV("abcde"), -5); + test(S("abcde"), 5, 1, SV("abcdefghij"), -10); + test(S("abcde"), 5, 1, SV("abcdefghijklmnopqrst"), -20); +} + +template <class S, class SV> +void test1() +{ + test(S("abcde"), 6, 0, SV(""), 0); + test(S("abcde"), 6, 0, SV("abcde"), 0); + test(S("abcde"), 6, 0, SV("abcdefghij"), 0); + test(S("abcde"), 6, 0, SV("abcdefghijklmnopqrst"), 0); + test(S("abcdefghij"), 0, 0, SV(""), 0); + test(S("abcdefghij"), 0, 0, SV("abcde"), -5); + test(S("abcdefghij"), 0, 0, SV("abcdefghij"), -10); + test(S("abcdefghij"), 0, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghij"), 0, 1, SV(""), 1); + test(S("abcdefghij"), 0, 1, SV("abcde"), -4); + test(S("abcdefghij"), 0, 1, SV("abcdefghij"), -9); + test(S("abcdefghij"), 0, 1, SV("abcdefghijklmnopqrst"), -19); + test(S("abcdefghij"), 0, 5, SV(""), 5); + test(S("abcdefghij"), 0, 5, SV("abcde"), 0); + test(S("abcdefghij"), 0, 5, SV("abcdefghij"), -5); + test(S("abcdefghij"), 0, 5, SV("abcdefghijklmnopqrst"), -15); + test(S("abcdefghij"), 0, 9, SV(""), 9); + test(S("abcdefghij"), 0, 9, SV("abcde"), 4); + test(S("abcdefghij"), 0, 9, SV("abcdefghij"), -1); + test(S("abcdefghij"), 0, 9, SV("abcdefghijklmnopqrst"), -11); + test(S("abcdefghij"), 0, 10, SV(""), 10); + test(S("abcdefghij"), 0, 10, SV("abcde"), 5); + test(S("abcdefghij"), 0, 10, SV("abcdefghij"), 0); + test(S("abcdefghij"), 0, 10, SV("abcdefghijklmnopqrst"), -10); + test(S("abcdefghij"), 0, 11, SV(""), 10); + test(S("abcdefghij"), 0, 11, SV("abcde"), 5); + test(S("abcdefghij"), 0, 11, SV("abcdefghij"), 0); + test(S("abcdefghij"), 0, 11, SV("abcdefghijklmnopqrst"), -10); + test(S("abcdefghij"), 1, 0, SV(""), 0); + test(S("abcdefghij"), 1, 0, SV("abcde"), -5); + test(S("abcdefghij"), 1, 0, SV("abcdefghij"), -10); + test(S("abcdefghij"), 1, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghij"), 1, 1, SV(""), 1); + test(S("abcdefghij"), 1, 1, SV("abcde"), 1); + test(S("abcdefghij"), 1, 1, SV("abcdefghij"), 1); + test(S("abcdefghij"), 1, 1, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghij"), 1, 4, SV(""), 4); + test(S("abcdefghij"), 1, 4, SV("abcde"), 1); + test(S("abcdefghij"), 1, 4, SV("abcdefghij"), 1); + test(S("abcdefghij"), 1, 4, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghij"), 1, 8, SV(""), 8); + test(S("abcdefghij"), 1, 8, SV("abcde"), 1); + test(S("abcdefghij"), 1, 8, SV("abcdefghij"), 1); + test(S("abcdefghij"), 1, 8, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghij"), 1, 9, SV(""), 9); + test(S("abcdefghij"), 1, 9, SV("abcde"), 1); + test(S("abcdefghij"), 1, 9, SV("abcdefghij"), 1); + test(S("abcdefghij"), 1, 9, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghij"), 1, 10, SV(""), 9); + test(S("abcdefghij"), 1, 10, SV("abcde"), 1); + test(S("abcdefghij"), 1, 10, SV("abcdefghij"), 1); + test(S("abcdefghij"), 1, 10, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghij"), 5, 0, SV(""), 0); + test(S("abcdefghij"), 5, 0, SV("abcde"), -5); + test(S("abcdefghij"), 5, 0, SV("abcdefghij"), -10); + test(S("abcdefghij"), 5, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghij"), 5, 1, SV(""), 1); + test(S("abcdefghij"), 5, 1, SV("abcde"), 5); + test(S("abcdefghij"), 5, 1, SV("abcdefghij"), 5); + test(S("abcdefghij"), 5, 1, SV("abcdefghijklmnopqrst"), 5); + test(S("abcdefghij"), 5, 2, SV(""), 2); + test(S("abcdefghij"), 5, 2, SV("abcde"), 5); + test(S("abcdefghij"), 5, 2, SV("abcdefghij"), 5); + test(S("abcdefghij"), 5, 2, SV("abcdefghijklmnopqrst"), 5); + test(S("abcdefghij"), 5, 4, SV(""), 4); + test(S("abcdefghij"), 5, 4, SV("abcde"), 5); + test(S("abcdefghij"), 5, 4, SV("abcdefghij"), 5); + test(S("abcdefghij"), 5, 4, SV("abcdefghijklmnopqrst"), 5); + test(S("abcdefghij"), 5, 5, SV(""), 5); + test(S("abcdefghij"), 5, 5, SV("abcde"), 5); + test(S("abcdefghij"), 5, 5, SV("abcdefghij"), 5); + test(S("abcdefghij"), 5, 5, SV("abcdefghijklmnopqrst"), 5); + test(S("abcdefghij"), 5, 6, SV(""), 5); + test(S("abcdefghij"), 5, 6, SV("abcde"), 5); + test(S("abcdefghij"), 5, 6, SV("abcdefghij"), 5); + test(S("abcdefghij"), 5, 6, SV("abcdefghijklmnopqrst"), 5); + test(S("abcdefghij"), 9, 0, SV(""), 0); + test(S("abcdefghij"), 9, 0, SV("abcde"), -5); + test(S("abcdefghij"), 9, 0, SV("abcdefghij"), -10); + test(S("abcdefghij"), 9, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghij"), 9, 1, SV(""), 1); + test(S("abcdefghij"), 9, 1, SV("abcde"), 9); + test(S("abcdefghij"), 9, 1, SV("abcdefghij"), 9); + test(S("abcdefghij"), 9, 1, SV("abcdefghijklmnopqrst"), 9); + test(S("abcdefghij"), 9, 2, SV(""), 1); + test(S("abcdefghij"), 9, 2, SV("abcde"), 9); + test(S("abcdefghij"), 9, 2, SV("abcdefghij"), 9); + test(S("abcdefghij"), 9, 2, SV("abcdefghijklmnopqrst"), 9); + test(S("abcdefghij"), 10, 0, SV(""), 0); + test(S("abcdefghij"), 10, 0, SV("abcde"), -5); + test(S("abcdefghij"), 10, 0, SV("abcdefghij"), -10); + test(S("abcdefghij"), 10, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghij"), 10, 1, SV(""), 0); + test(S("abcdefghij"), 10, 1, SV("abcde"), -5); + test(S("abcdefghij"), 10, 1, SV("abcdefghij"), -10); + test(S("abcdefghij"), 10, 1, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghij"), 11, 0, SV(""), 0); + test(S("abcdefghij"), 11, 0, SV("abcde"), 0); + test(S("abcdefghij"), 11, 0, SV("abcdefghij"), 0); + test(S("abcdefghij"), 11, 0, SV("abcdefghijklmnopqrst"), 0); +} + +template <class S, class SV> +void test2() +{ + test(S("abcdefghijklmnopqrst"), 0, 0, SV(""), 0); + test(S("abcdefghijklmnopqrst"), 0, 0, SV("abcde"), -5); + test(S("abcdefghijklmnopqrst"), 0, 0, SV("abcdefghij"), -10); + test(S("abcdefghijklmnopqrst"), 0, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghijklmnopqrst"), 0, 1, SV(""), 1); + test(S("abcdefghijklmnopqrst"), 0, 1, SV("abcde"), -4); + test(S("abcdefghijklmnopqrst"), 0, 1, SV("abcdefghij"), -9); + test(S("abcdefghijklmnopqrst"), 0, 1, SV("abcdefghijklmnopqrst"), -19); + test(S("abcdefghijklmnopqrst"), 0, 10, SV(""), 10); + test(S("abcdefghijklmnopqrst"), 0, 10, SV("abcde"), 5); + test(S("abcdefghijklmnopqrst"), 0, 10, SV("abcdefghij"), 0); + test(S("abcdefghijklmnopqrst"), 0, 10, SV("abcdefghijklmnopqrst"), -10); + test(S("abcdefghijklmnopqrst"), 0, 19, SV(""), 19); + test(S("abcdefghijklmnopqrst"), 0, 19, SV("abcde"), 14); + test(S("abcdefghijklmnopqrst"), 0, 19, SV("abcdefghij"), 9); + test(S("abcdefghijklmnopqrst"), 0, 19, SV("abcdefghijklmnopqrst"), -1); + test(S("abcdefghijklmnopqrst"), 0, 20, SV(""), 20); + test(S("abcdefghijklmnopqrst"), 0, 20, SV("abcde"), 15); + test(S("abcdefghijklmnopqrst"), 0, 20, SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), 0, 20, SV("abcdefghijklmnopqrst"), 0); + test(S("abcdefghijklmnopqrst"), 0, 21, SV(""), 20); + test(S("abcdefghijklmnopqrst"), 0, 21, SV("abcde"), 15); + test(S("abcdefghijklmnopqrst"), 0, 21, SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), 0, 21, SV("abcdefghijklmnopqrst"), 0); + test(S("abcdefghijklmnopqrst"), 1, 0, SV(""), 0); + test(S("abcdefghijklmnopqrst"), 1, 0, SV("abcde"), -5); + test(S("abcdefghijklmnopqrst"), 1, 0, SV("abcdefghij"), -10); + test(S("abcdefghijklmnopqrst"), 1, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghijklmnopqrst"), 1, 1, SV(""), 1); + test(S("abcdefghijklmnopqrst"), 1, 1, SV("abcde"), 1); + test(S("abcdefghijklmnopqrst"), 1, 1, SV("abcdefghij"), 1); + test(S("abcdefghijklmnopqrst"), 1, 1, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghijklmnopqrst"), 1, 9, SV(""), 9); + test(S("abcdefghijklmnopqrst"), 1, 9, SV("abcde"), 1); + test(S("abcdefghijklmnopqrst"), 1, 9, SV("abcdefghij"), 1); + test(S("abcdefghijklmnopqrst"), 1, 9, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghijklmnopqrst"), 1, 18, SV(""), 18); + test(S("abcdefghijklmnopqrst"), 1, 18, SV("abcde"), 1); + test(S("abcdefghijklmnopqrst"), 1, 18, SV("abcdefghij"), 1); + test(S("abcdefghijklmnopqrst"), 1, 18, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghijklmnopqrst"), 1, 19, SV(""), 19); + test(S("abcdefghijklmnopqrst"), 1, 19, SV("abcde"), 1); + test(S("abcdefghijklmnopqrst"), 1, 19, SV("abcdefghij"), 1); + test(S("abcdefghijklmnopqrst"), 1, 19, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghijklmnopqrst"), 1, 20, SV(""), 19); + test(S("abcdefghijklmnopqrst"), 1, 20, SV("abcde"), 1); + test(S("abcdefghijklmnopqrst"), 1, 20, SV("abcdefghij"), 1); + test(S("abcdefghijklmnopqrst"), 1, 20, SV("abcdefghijklmnopqrst"), 1); + test(S("abcdefghijklmnopqrst"), 10, 0, SV(""), 0); + test(S("abcdefghijklmnopqrst"), 10, 0, SV("abcde"), -5); + test(S("abcdefghijklmnopqrst"), 10, 0, SV("abcdefghij"), -10); + test(S("abcdefghijklmnopqrst"), 10, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghijklmnopqrst"), 10, 1, SV(""), 1); + test(S("abcdefghijklmnopqrst"), 10, 1, SV("abcde"), 10); + test(S("abcdefghijklmnopqrst"), 10, 1, SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), 10, 1, SV("abcdefghijklmnopqrst"), 10); + test(S("abcdefghijklmnopqrst"), 10, 5, SV(""), 5); + test(S("abcdefghijklmnopqrst"), 10, 5, SV("abcde"), 10); + test(S("abcdefghijklmnopqrst"), 10, 5, SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), 10, 5, SV("abcdefghijklmnopqrst"), 10); + test(S("abcdefghijklmnopqrst"), 10, 9, SV(""), 9); + test(S("abcdefghijklmnopqrst"), 10, 9, SV("abcde"), 10); + test(S("abcdefghijklmnopqrst"), 10, 9, SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), 10, 9, SV("abcdefghijklmnopqrst"), 10); + test(S("abcdefghijklmnopqrst"), 10, 10, SV(""), 10); + test(S("abcdefghijklmnopqrst"), 10, 10, SV("abcde"), 10); + test(S("abcdefghijklmnopqrst"), 10, 10, SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), 10, 10, SV("abcdefghijklmnopqrst"), 10); + test(S("abcdefghijklmnopqrst"), 10, 11, SV(""), 10); + test(S("abcdefghijklmnopqrst"), 10, 11, SV("abcde"), 10); + test(S("abcdefghijklmnopqrst"), 10, 11, SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), 10, 11, SV("abcdefghijklmnopqrst"), 10); + test(S("abcdefghijklmnopqrst"), 19, 0, SV(""), 0); + test(S("abcdefghijklmnopqrst"), 19, 0, SV("abcde"), -5); + test(S("abcdefghijklmnopqrst"), 19, 0, SV("abcdefghij"), -10); + test(S("abcdefghijklmnopqrst"), 19, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghijklmnopqrst"), 19, 1, SV(""), 1); + test(S("abcdefghijklmnopqrst"), 19, 1, SV("abcde"), 19); + test(S("abcdefghijklmnopqrst"), 19, 1, SV("abcdefghij"), 19); + test(S("abcdefghijklmnopqrst"), 19, 1, SV("abcdefghijklmnopqrst"), 19); + test(S("abcdefghijklmnopqrst"), 19, 2, SV(""), 1); + test(S("abcdefghijklmnopqrst"), 19, 2, SV("abcde"), 19); + test(S("abcdefghijklmnopqrst"), 19, 2, SV("abcdefghij"), 19); + test(S("abcdefghijklmnopqrst"), 19, 2, SV("abcdefghijklmnopqrst"), 19); + test(S("abcdefghijklmnopqrst"), 20, 0, SV(""), 0); + test(S("abcdefghijklmnopqrst"), 20, 0, SV("abcde"), -5); + test(S("abcdefghijklmnopqrst"), 20, 0, SV("abcdefghij"), -10); + test(S("abcdefghijklmnopqrst"), 20, 0, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghijklmnopqrst"), 20, 1, SV(""), 0); + test(S("abcdefghijklmnopqrst"), 20, 1, SV("abcde"), -5); + test(S("abcdefghijklmnopqrst"), 20, 1, SV("abcdefghij"), -10); + test(S("abcdefghijklmnopqrst"), 20, 1, SV("abcdefghijklmnopqrst"), -20); + test(S("abcdefghijklmnopqrst"), 21, 0, SV(""), 0); + test(S("abcdefghijklmnopqrst"), 21, 0, SV("abcde"), 0); + test(S("abcdefghijklmnopqrst"), 21, 0, SV("abcdefghij"), 0); + test(S("abcdefghijklmnopqrst"), 21, 0, SV("abcdefghijklmnopqrst"), 0); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + test2<S, SV>(); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + test2<S, SV>(); + } +#endif +} Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/string_view.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/string_view.pass.cpp?rev=318088&view=auto ============================================================================== --- libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/string_view.pass.cpp (added) +++ libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_compare/string_view.pass.cpp Mon Nov 13 13:27:53 2017 @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// int compare(const basic_string_view sv) const + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +int sign(int x) +{ + if (x == 0) + return 0; + if (x < 0) + return -1; + return 1; +} + +template <class S, class SV> +void +test(const S& s, SV sv, int x) +{ + assert(sign(s.compare(sv)) == sign(x)); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(""), SV(""), 0); + test(S(""), SV("abcde"), -5); + test(S(""), SV("abcdefghij"), -10); + test(S(""), SV("abcdefghijklmnopqrst"), -20); + test(S("abcde"), SV(""), 5); + test(S("abcde"), SV("abcde"), 0); + test(S("abcde"), SV("abcdefghij"), -5); + test(S("abcde"), SV("abcdefghijklmnopqrst"), -15); + test(S("abcdefghij"), SV(""), 10); + test(S("abcdefghij"), SV("abcde"), 5); + test(S("abcdefghij"), SV("abcdefghij"), 0); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), -10); + test(S("abcdefghijklmnopqrst"), SV(""), 20); + test(S("abcdefghijklmnopqrst"), SV("abcde"), 15); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), 0); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::string_view SV; + test(S(""), SV(""), 0); + test(S(""), SV("abcde"), -5); + test(S(""), SV("abcdefghij"), -10); + test(S(""), SV("abcdefghijklmnopqrst"), -20); + test(S("abcde"), SV(""), 5); + test(S("abcde"), SV("abcde"), 0); + test(S("abcde"), SV("abcdefghij"), -5); + test(S("abcde"), SV("abcdefghijklmnopqrst"), -15); + test(S("abcdefghij"), SV(""), 10); + test(S("abcdefghij"), SV("abcde"), 5); + test(S("abcdefghij"), SV("abcdefghij"), 0); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), -10); + test(S("abcdefghijklmnopqrst"), SV(""), 20); + test(S("abcdefghijklmnopqrst"), SV("abcde"), 15); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), 10); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), 0); + } +#endif +} Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_view_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_view_size.pass.cpp?rev=318088&view=auto ============================================================================== --- libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_view_size.pass.cpp (added) +++ libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_view_size.pass.cpp Mon Nov 13 13:27:53 2017 @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// size_type find_first_not_of(basic_string_view sv, size_type pos = 0) const; + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type pos, typename S::size_type x) +{ + assert(s.find_first_not_of(sv, pos) == x); + if (x != S::npos) + assert(pos <= x && x < s.size()); +} + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type x) +{ + assert(s.find_first_not_of(sv) == x); + if (x != S::npos) + assert(x < s.size()); +} + +template <class S, class SV> +void test0() +{ + test(S(""), SV(""), 0, S::npos); + test(S(""), SV("laenf"), 0, S::npos); + test(S(""), SV("pqlnkmbdjo"), 0, S::npos); + test(S(""), SV("qkamfogpnljdcshbreti"), 0, S::npos); + test(S(""), SV(""), 1, S::npos); + test(S(""), SV("bjaht"), 1, S::npos); + test(S(""), SV("hjlcmgpket"), 1, S::npos); + test(S(""), SV("htaobedqikfplcgjsmrn"), 1, S::npos); + test(S("fodgq"), SV(""), 0, 0); + test(S("qanej"), SV("dfkap"), 0, 0); + test(S("clbao"), SV("ihqrfebgad"), 0, 0); + test(S("mekdn"), SV("ngtjfcalbseiqrphmkdo"), 0, S::npos); + test(S("srdfq"), SV(""), 1, 1); + test(S("oemth"), SV("ikcrq"), 1, 1); + test(S("cdaih"), SV("dmajblfhsg"), 1, 3); + test(S("qohtk"), SV("oqftjhdmkgsblacenirp"), 1, S::npos); + test(S("cshmd"), SV(""), 2, 2); + test(S("lhcdo"), SV("oebqi"), 2, 2); + test(S("qnsoh"), SV("kojhpmbsfe"), 2, S::npos); + test(S("pkrof"), SV("acbsjqogpltdkhinfrem"), 2, S::npos); + test(S("fmtsp"), SV(""), 4, 4); + test(S("khbpm"), SV("aobjd"), 4, 4); + test(S("pbsji"), SV("pcbahntsje"), 4, 4); + test(S("mprdj"), SV("fhepcrntkoagbmldqijs"), 4, S::npos); + test(S("eqmpa"), SV(""), 5, S::npos); + test(S("omigs"), SV("kocgb"), 5, S::npos); + test(S("onmje"), SV("fbslrjiqkm"), 5, S::npos); + test(S("oqmrj"), SV("jeidpcmalhfnqbgtrsko"), 5, S::npos); + test(S("schfa"), SV(""), 6, S::npos); + test(S("igdsc"), SV("qngpd"), 6, S::npos); + test(S("brqgo"), SV("rodhqklgmb"), 6, S::npos); + test(S("tnrph"), SV("thdjgafrlbkoiqcspmne"), 6, S::npos); + test(S("hcjitbfapl"), SV(""), 0, 0); + test(S("daiprenocl"), SV("ashjd"), 0, 2); + test(S("litpcfdghe"), SV("mgojkldsqh"), 0, 1); + test(S("aidjksrolc"), SV("imqnaghkfrdtlopbjesc"), 0, S::npos); + test(S("qpghtfbaji"), SV(""), 1, 1); + test(S("gfshlcmdjr"), SV("nadkh"), 1, 1); + test(S("nkodajteqp"), SV("ofdrqmkebl"), 1, 4); + test(S("gbmetiprqd"), SV("bdfjqgatlksriohemnpc"), 1, S::npos); + test(S("crnklpmegd"), SV(""), 5, 5); + test(S("jsbtafedoc"), SV("prqgn"), 5, 5); + test(S("qnmodrtkeb"), SV("pejafmnokr"), 5, 6); + test(S("cpebqsfmnj"), SV("odnqkgijrhabfmcestlp"), 5, S::npos); + test(S("lmofqdhpki"), SV(""), 9, 9); + test(S("hnefkqimca"), SV("rtjpa"), 9, S::npos); + test(S("drtasbgmfp"), SV("ktsrmnqagd"), 9, 9); + test(S("lsaijeqhtr"), SV("rtdhgcisbnmoaqkfpjle"), 9, S::npos); + test(S("elgofjmbrq"), SV(""), 10, S::npos); + test(S("mjqdgalkpc"), SV("dplqa"), 10, S::npos); + test(S("kthqnfcerm"), SV("dkacjoptns"), 10, S::npos); + test(S("dfsjhanorc"), SV("hqfimtrgnbekpdcsjalo"), 10, S::npos); + test(S("eqsgalomhb"), SV(""), 11, S::npos); + test(S("akiteljmoh"), SV("lofbc"), 11, S::npos); + test(S("hlbdfreqjo"), SV("astoegbfpn"), 11, S::npos); + test(S("taqobhlerg"), SV("pdgreqomsncafklhtibj"), 11, S::npos); + test(S("snafbdlghrjkpqtoceim"), SV(""), 0, 0); + test(S("aemtbrgcklhndjisfpoq"), SV("lbtqd"), 0, 0); + test(S("pnracgfkjdiholtbqsem"), SV("tboimldpjh"), 0, 1); + test(S("dicfltehbsgrmojnpkaq"), SV("slcerthdaiqjfnobgkpm"), 0, S::npos); + test(S("jlnkraeodhcspfgbqitm"), SV(""), 1, 1); + test(S("lhosrngtmfjikbqpcade"), SV("aqibs"), 1, 1); + test(S("rbtaqjhgkneisldpmfoc"), SV("gtfblmqinc"), 1, 3); + test(S("gpifsqlrdkbonjtmheca"), SV("mkqpbtdalgniorhfescj"), 1, S::npos); + test(S("hdpkobnsalmcfijregtq"), SV(""), 10, 10); + test(S("jtlshdgqaiprkbcoenfm"), SV("pblas"), 10, 11); + test(S("fkdrbqltsgmcoiphneaj"), SV("arosdhcfme"), 10, 13); + test(S("crsplifgtqedjohnabmk"), SV("blkhjeogicatqfnpdmsr"), 10, S::npos); + test(S("niptglfbosehkamrdqcj"), SV(""), 19, 19); + test(S("copqdhstbingamjfkler"), SV("djkqc"), 19, 19); + test(S("mrtaefilpdsgocnhqbjk"), SV("lgokshjtpb"), 19, S::npos); + test(S("kojatdhlcmigpbfrqnes"), SV("bqjhtkfepimcnsgrlado"), 19, S::npos); + test(S("eaintpchlqsbdgrkjofm"), SV(""), 20, S::npos); + test(S("gjnhidfsepkrtaqbmclo"), SV("nocfa"), 20, S::npos); + test(S("spocfaktqdbiejlhngmr"), SV("bgtajmiedc"), 20, S::npos); + test(S("rphmlekgfscndtaobiqj"), SV("lsckfnqgdahejiopbtmr"), 20, S::npos); + test(S("liatsqdoegkmfcnbhrpj"), SV(""), 21, S::npos); + test(S("binjagtfldkrspcomqeh"), SV("gfsrt"), 21, S::npos); + test(S("latkmisecnorjbfhqpdg"), SV("pfsocbhjtm"), 21, S::npos); + test(S("lecfratdjkhnsmqpoigb"), SV("tpflmdnoicjgkberhqsa"), 21, S::npos); +} + +template <class S, class SV> +void test1() +{ + test(S(""), SV(""), S::npos); + test(S(""), SV("laenf"), S::npos); + test(S(""), SV("pqlnkmbdjo"), S::npos); + test(S(""), SV("qkamfogpnljdcshbreti"), S::npos); + test(S("nhmko"), SV(""), 0); + test(S("lahfb"), SV("irkhs"), 0); + test(S("gmfhd"), SV("kantesmpgj"), 2); + test(S("odaft"), SV("oknlrstdpiqmjbaghcfe"), S::npos); + test(S("eolhfgpjqk"), SV(""), 0); + test(S("nbatdlmekr"), SV("bnrpe"), 2); + test(S("jdmciepkaq"), SV("jtdaefblso"), 2); + test(S("hkbgspoflt"), SV("oselktgbcapndfjihrmq"), S::npos); + test(S("gprdcokbnjhlsfmtieqa"), SV(""), 0); + test(S("qjghlnftcaismkropdeb"), SV("bjaht"), 0); + test(S("pnalfrdtkqcmojiesbhg"), SV("hjlcmgpket"), 1); + test(S("pniotcfrhqsmgdkjbael"), SV("htaobedqikfplcgjsmrn"), S::npos); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#endif +} Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.of/string_view_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.of/string_view_size.pass.cpp?rev=318088&view=auto ============================================================================== --- libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.of/string_view_size.pass.cpp (added) +++ libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.first.of/string_view_size.pass.cpp Mon Nov 13 13:27:53 2017 @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// size_type find_first_of(const basic_string_view sv, size_type pos = 0) const; + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type pos, typename S::size_type x) +{ + assert(s.find_first_of(sv, pos) == x); + if (x != S::npos) + assert(pos <= x && x < s.size()); +} + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type x) +{ + assert(s.find_first_of(sv) == x); + if (x != S::npos) + assert(x < s.size()); +} + +template <class S, class SV> +void test0() +{ + test(S(""), SV(""), 0, S::npos); + test(S(""), SV("laenf"), 0, S::npos); + test(S(""), SV("pqlnkmbdjo"), 0, S::npos); + test(S(""), SV("qkamfogpnljdcshbreti"), 0, S::npos); + test(S(""), SV(""), 1, S::npos); + test(S(""), SV("bjaht"), 1, S::npos); + test(S(""), SV("hjlcmgpket"), 1, S::npos); + test(S(""), SV("htaobedqikfplcgjsmrn"), 1, S::npos); + test(S("fodgq"), SV(""), 0, S::npos); + test(S("qanej"), SV("dfkap"), 0, 1); + test(S("clbao"), SV("ihqrfebgad"), 0, 2); + test(S("mekdn"), SV("ngtjfcalbseiqrphmkdo"), 0, 0); + test(S("srdfq"), SV(""), 1, S::npos); + test(S("oemth"), SV("ikcrq"), 1, S::npos); + test(S("cdaih"), SV("dmajblfhsg"), 1, 1); + test(S("qohtk"), SV("oqftjhdmkgsblacenirp"), 1, 1); + test(S("cshmd"), SV(""), 2, S::npos); + test(S("lhcdo"), SV("oebqi"), 2, 4); + test(S("qnsoh"), SV("kojhpmbsfe"), 2, 2); + test(S("pkrof"), SV("acbsjqogpltdkhinfrem"), 2, 2); + test(S("fmtsp"), SV(""), 4, S::npos); + test(S("khbpm"), SV("aobjd"), 4, S::npos); + test(S("pbsji"), SV("pcbahntsje"), 4, S::npos); + test(S("mprdj"), SV("fhepcrntkoagbmldqijs"), 4, 4); + test(S("eqmpa"), SV(""), 5, S::npos); + test(S("omigs"), SV("kocgb"), 5, S::npos); + test(S("onmje"), SV("fbslrjiqkm"), 5, S::npos); + test(S("oqmrj"), SV("jeidpcmalhfnqbgtrsko"), 5, S::npos); + test(S("schfa"), SV(""), 6, S::npos); + test(S("igdsc"), SV("qngpd"), 6, S::npos); + test(S("brqgo"), SV("rodhqklgmb"), 6, S::npos); + test(S("tnrph"), SV("thdjgafrlbkoiqcspmne"), 6, S::npos); + test(S("hcjitbfapl"), SV(""), 0, S::npos); + test(S("daiprenocl"), SV("ashjd"), 0, 0); + test(S("litpcfdghe"), SV("mgojkldsqh"), 0, 0); + test(S("aidjksrolc"), SV("imqnaghkfrdtlopbjesc"), 0, 0); + test(S("qpghtfbaji"), SV(""), 1, S::npos); + test(S("gfshlcmdjr"), SV("nadkh"), 1, 3); + test(S("nkodajteqp"), SV("ofdrqmkebl"), 1, 1); + test(S("gbmetiprqd"), SV("bdfjqgatlksriohemnpc"), 1, 1); + test(S("crnklpmegd"), SV(""), 5, S::npos); + test(S("jsbtafedoc"), SV("prqgn"), 5, S::npos); + test(S("qnmodrtkeb"), SV("pejafmnokr"), 5, 5); + test(S("cpebqsfmnj"), SV("odnqkgijrhabfmcestlp"), 5, 5); + test(S("lmofqdhpki"), SV(""), 9, S::npos); + test(S("hnefkqimca"), SV("rtjpa"), 9, 9); + test(S("drtasbgmfp"), SV("ktsrmnqagd"), 9, S::npos); + test(S("lsaijeqhtr"), SV("rtdhgcisbnmoaqkfpjle"), 9, 9); + test(S("elgofjmbrq"), SV(""), 10, S::npos); + test(S("mjqdgalkpc"), SV("dplqa"), 10, S::npos); + test(S("kthqnfcerm"), SV("dkacjoptns"), 10, S::npos); + test(S("dfsjhanorc"), SV("hqfimtrgnbekpdcsjalo"), 10, S::npos); + test(S("eqsgalomhb"), SV(""), 11, S::npos); + test(S("akiteljmoh"), SV("lofbc"), 11, S::npos); + test(S("hlbdfreqjo"), SV("astoegbfpn"), 11, S::npos); + test(S("taqobhlerg"), SV("pdgreqomsncafklhtibj"), 11, S::npos); + test(S("snafbdlghrjkpqtoceim"), SV(""), 0, S::npos); + test(S("aemtbrgcklhndjisfpoq"), SV("lbtqd"), 0, 3); + test(S("pnracgfkjdiholtbqsem"), SV("tboimldpjh"), 0, 0); + test(S("dicfltehbsgrmojnpkaq"), SV("slcerthdaiqjfnobgkpm"), 0, 0); + test(S("jlnkraeodhcspfgbqitm"), SV(""), 1, S::npos); + test(S("lhosrngtmfjikbqpcade"), SV("aqibs"), 1, 3); + test(S("rbtaqjhgkneisldpmfoc"), SV("gtfblmqinc"), 1, 1); + test(S("gpifsqlrdkbonjtmheca"), SV("mkqpbtdalgniorhfescj"), 1, 1); + test(S("hdpkobnsalmcfijregtq"), SV(""), 10, S::npos); + test(S("jtlshdgqaiprkbcoenfm"), SV("pblas"), 10, 10); + test(S("fkdrbqltsgmcoiphneaj"), SV("arosdhcfme"), 10, 10); + test(S("crsplifgtqedjohnabmk"), SV("blkhjeogicatqfnpdmsr"), 10, 10); + test(S("niptglfbosehkamrdqcj"), SV(""), 19, S::npos); + test(S("copqdhstbingamjfkler"), SV("djkqc"), 19, S::npos); + test(S("mrtaefilpdsgocnhqbjk"), SV("lgokshjtpb"), 19, 19); + test(S("kojatdhlcmigpbfrqnes"), SV("bqjhtkfepimcnsgrlado"), 19, 19); + test(S("eaintpchlqsbdgrkjofm"), SV(""), 20, S::npos); + test(S("gjnhidfsepkrtaqbmclo"), SV("nocfa"), 20, S::npos); + test(S("spocfaktqdbiejlhngmr"), SV("bgtajmiedc"), 20, S::npos); + test(S("rphmlekgfscndtaobiqj"), SV("lsckfnqgdahejiopbtmr"), 20, S::npos); + test(S("liatsqdoegkmfcnbhrpj"), SV(""), 21, S::npos); + test(S("binjagtfldkrspcomqeh"), SV("gfsrt"), 21, S::npos); + test(S("latkmisecnorjbfhqpdg"), SV("pfsocbhjtm"), 21, S::npos); + test(S("lecfratdjkhnsmqpoigb"), SV("tpflmdnoicjgkberhqsa"), 21, S::npos); +} + +template <class S, class SV> +void test1() +{ + test(S(""), SV(""), S::npos); + test(S(""), SV("laenf"), S::npos); + test(S(""), SV("pqlnkmbdjo"), S::npos); + test(S(""), SV("qkamfogpnljdcshbreti"), S::npos); + test(S("nhmko"), SV(""), S::npos); + test(S("lahfb"), SV("irkhs"), 2); + test(S("gmfhd"), SV("kantesmpgj"), 0); + test(S("odaft"), SV("oknlrstdpiqmjbaghcfe"), 0); + test(S("eolhfgpjqk"), SV(""), S::npos); + test(S("nbatdlmekr"), SV("bnrpe"), 0); + test(S("jdmciepkaq"), SV("jtdaefblso"), 0); + test(S("hkbgspoflt"), SV("oselktgbcapndfjihrmq"), 0); + test(S("gprdcokbnjhlsfmtieqa"), SV(""), S::npos); + test(S("qjghlnftcaismkropdeb"), SV("bjaht"), 1); + test(S("pnalfrdtkqcmojiesbhg"), SV("hjlcmgpket"), 0); + test(S("pniotcfrhqsmgdkjbael"), SV("htaobedqikfplcgjsmrn"), 0); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#endif +} Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp?rev=318088&view=auto ============================================================================== --- libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp (added) +++ libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp Mon Nov 13 13:27:53 2017 @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// size_type find_last_not_of(basic_string_view sv, size_type pos = npos) const; + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type pos, typename S::size_type x) +{ + assert(s.find_last_not_of(sv, pos) == x); + if (x != S::npos) + assert(x <= pos && x < s.size()); +} + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type x) +{ + assert(s.find_last_not_of(sv) == x); + if (x != S::npos) + assert(x < s.size()); +} + +template <class S, class SV> +void test0() +{ + test(S(""), SV(""), 0, S::npos); + test(S(""), SV("laenf"), 0, S::npos); + test(S(""), SV("pqlnkmbdjo"), 0, S::npos); + test(S(""), SV("qkamfogpnljdcshbreti"), 0, S::npos); + test(S(""), SV(""), 1, S::npos); + test(S(""), SV("bjaht"), 1, S::npos); + test(S(""), SV("hjlcmgpket"), 1, S::npos); + test(S(""), SV("htaobedqikfplcgjsmrn"), 1, S::npos); + test(S("fodgq"), SV(""), 0, 0); + test(S("qanej"), SV("dfkap"), 0, 0); + test(S("clbao"), SV("ihqrfebgad"), 0, 0); + test(S("mekdn"), SV("ngtjfcalbseiqrphmkdo"), 0, S::npos); + test(S("srdfq"), SV(""), 1, 1); + test(S("oemth"), SV("ikcrq"), 1, 1); + test(S("cdaih"), SV("dmajblfhsg"), 1, 0); + test(S("qohtk"), SV("oqftjhdmkgsblacenirp"), 1, S::npos); + test(S("cshmd"), SV(""), 2, 2); + test(S("lhcdo"), SV("oebqi"), 2, 2); + test(S("qnsoh"), SV("kojhpmbsfe"), 2, 1); + test(S("pkrof"), SV("acbsjqogpltdkhinfrem"), 2, S::npos); + test(S("fmtsp"), SV(""), 4, 4); + test(S("khbpm"), SV("aobjd"), 4, 4); + test(S("pbsji"), SV("pcbahntsje"), 4, 4); + test(S("mprdj"), SV("fhepcrntkoagbmldqijs"), 4, S::npos); + test(S("eqmpa"), SV(""), 5, 4); + test(S("omigs"), SV("kocgb"), 5, 4); + test(S("onmje"), SV("fbslrjiqkm"), 5, 4); + test(S("oqmrj"), SV("jeidpcmalhfnqbgtrsko"), 5, S::npos); + test(S("schfa"), SV(""), 6, 4); + test(S("igdsc"), SV("qngpd"), 6, 4); + test(S("brqgo"), SV("rodhqklgmb"), 6, S::npos); + test(S("tnrph"), SV("thdjgafrlbkoiqcspmne"), 6, S::npos); + test(S("hcjitbfapl"), SV(""), 0, 0); + test(S("daiprenocl"), SV("ashjd"), 0, S::npos); + test(S("litpcfdghe"), SV("mgojkldsqh"), 0, S::npos); + test(S("aidjksrolc"), SV("imqnaghkfrdtlopbjesc"), 0, S::npos); + test(S("qpghtfbaji"), SV(""), 1, 1); + test(S("gfshlcmdjr"), SV("nadkh"), 1, 1); + test(S("nkodajteqp"), SV("ofdrqmkebl"), 1, 0); + test(S("gbmetiprqd"), SV("bdfjqgatlksriohemnpc"), 1, S::npos); + test(S("crnklpmegd"), SV(""), 5, 5); + test(S("jsbtafedoc"), SV("prqgn"), 5, 5); + test(S("qnmodrtkeb"), SV("pejafmnokr"), 5, 4); + test(S("cpebqsfmnj"), SV("odnqkgijrhabfmcestlp"), 5, S::npos); + test(S("lmofqdhpki"), SV(""), 9, 9); + test(S("hnefkqimca"), SV("rtjpa"), 9, 8); + test(S("drtasbgmfp"), SV("ktsrmnqagd"), 9, 9); + test(S("lsaijeqhtr"), SV("rtdhgcisbnmoaqkfpjle"), 9, S::npos); + test(S("elgofjmbrq"), SV(""), 10, 9); + test(S("mjqdgalkpc"), SV("dplqa"), 10, 9); + test(S("kthqnfcerm"), SV("dkacjoptns"), 10, 9); + test(S("dfsjhanorc"), SV("hqfimtrgnbekpdcsjalo"), 10, S::npos); + test(S("eqsgalomhb"), SV(""), 11, 9); + test(S("akiteljmoh"), SV("lofbc"), 11, 9); + test(S("hlbdfreqjo"), SV("astoegbfpn"), 11, 8); + test(S("taqobhlerg"), SV("pdgreqomsncafklhtibj"), 11, S::npos); + test(S("snafbdlghrjkpqtoceim"), SV(""), 0, 0); + test(S("aemtbrgcklhndjisfpoq"), SV("lbtqd"), 0, 0); + test(S("pnracgfkjdiholtbqsem"), SV("tboimldpjh"), 0, S::npos); + test(S("dicfltehbsgrmojnpkaq"), SV("slcerthdaiqjfnobgkpm"), 0, S::npos); + test(S("jlnkraeodhcspfgbqitm"), SV(""), 1, 1); + test(S("lhosrngtmfjikbqpcade"), SV("aqibs"), 1, 1); + test(S("rbtaqjhgkneisldpmfoc"), SV("gtfblmqinc"), 1, 0); + test(S("gpifsqlrdkbonjtmheca"), SV("mkqpbtdalgniorhfescj"), 1, S::npos); + test(S("hdpkobnsalmcfijregtq"), SV(""), 10, 10); + test(S("jtlshdgqaiprkbcoenfm"), SV("pblas"), 10, 9); + test(S("fkdrbqltsgmcoiphneaj"), SV("arosdhcfme"), 10, 9); + test(S("crsplifgtqedjohnabmk"), SV("blkhjeogicatqfnpdmsr"), 10, S::npos); + test(S("niptglfbosehkamrdqcj"), SV(""), 19, 19); + test(S("copqdhstbingamjfkler"), SV("djkqc"), 19, 19); + test(S("mrtaefilpdsgocnhqbjk"), SV("lgokshjtpb"), 19, 16); + test(S("kojatdhlcmigpbfrqnes"), SV("bqjhtkfepimcnsgrlado"), 19, S::npos); + test(S("eaintpchlqsbdgrkjofm"), SV(""), 20, 19); + test(S("gjnhidfsepkrtaqbmclo"), SV("nocfa"), 20, 18); + test(S("spocfaktqdbiejlhngmr"), SV("bgtajmiedc"), 20, 19); + test(S("rphmlekgfscndtaobiqj"), SV("lsckfnqgdahejiopbtmr"), 20, S::npos); + test(S("liatsqdoegkmfcnbhrpj"), SV(""), 21, 19); + test(S("binjagtfldkrspcomqeh"), SV("gfsrt"), 21, 19); + test(S("latkmisecnorjbfhqpdg"), SV("pfsocbhjtm"), 21, 19); + test(S("lecfratdjkhnsmqpoigb"), SV("tpflmdnoicjgkberhqsa"), 21, S::npos); +} + +template <class S, class SV> +void test1() +{ + test(S(""), SV(""), S::npos); + test(S(""), SV("laenf"), S::npos); + test(S(""), SV("pqlnkmbdjo"), S::npos); + test(S(""), SV("qkamfogpnljdcshbreti"), S::npos); + test(S("nhmko"), SV(""), 4); + test(S("lahfb"), SV("irkhs"), 4); + test(S("gmfhd"), SV("kantesmpgj"), 4); + test(S("odaft"), SV("oknlrstdpiqmjbaghcfe"), S::npos); + test(S("eolhfgpjqk"), SV(""), 9); + test(S("nbatdlmekr"), SV("bnrpe"), 8); + test(S("jdmciepkaq"), SV("jtdaefblso"), 9); + test(S("hkbgspoflt"), SV("oselktgbcapndfjihrmq"), S::npos); + test(S("gprdcokbnjhlsfmtieqa"), SV(""), 19); + test(S("qjghlnftcaismkropdeb"), SV("bjaht"), 18); + test(S("pnalfrdtkqcmojiesbhg"), SV("hjlcmgpket"), 17); + test(S("pniotcfrhqsmgdkjbael"), SV("htaobedqikfplcgjsmrn"), S::npos); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::string_view SV; +// test0<S, SV>(); +// test1<S, SV>(); + } +#endif +} Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.of/string_view_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.of/string_view_size.pass.cpp?rev=318088&view=auto ============================================================================== --- libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.of/string_view_size.pass.cpp (added) +++ libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find.last.of/string_view_size.pass.cpp Mon Nov 13 13:27:53 2017 @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// size_type find_last_of(const basic_string_view sv, size_type pos = npos) const; + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type pos, typename S::size_type x) +{ + assert(s.find_last_of(sv, pos) == x); + if (x != S::npos) + assert(x <= pos && x < s.size()); +} + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type x) +{ + assert(s.find_last_of(sv) == x); + if (x != S::npos) + assert(x < s.size()); +} + +template <class S, class SV> +void test0() +{ + test(S(""), SV(""), 0, S::npos); + test(S(""), SV("laenf"), 0, S::npos); + test(S(""), SV("pqlnkmbdjo"), 0, S::npos); + test(S(""), SV("qkamfogpnljdcshbreti"), 0, S::npos); + test(S(""), SV(""), 1, S::npos); + test(S(""), SV("bjaht"), 1, S::npos); + test(S(""), SV("hjlcmgpket"), 1, S::npos); + test(S(""), SV("htaobedqikfplcgjsmrn"), 1, S::npos); + test(S("fodgq"), SV(""), 0, S::npos); + test(S("qanej"), SV("dfkap"), 0, S::npos); + test(S("clbao"), SV("ihqrfebgad"), 0, S::npos); + test(S("mekdn"), SV("ngtjfcalbseiqrphmkdo"), 0, 0); + test(S("srdfq"), SV(""), 1, S::npos); + test(S("oemth"), SV("ikcrq"), 1, S::npos); + test(S("cdaih"), SV("dmajblfhsg"), 1, 1); + test(S("qohtk"), SV("oqftjhdmkgsblacenirp"), 1, 1); + test(S("cshmd"), SV(""), 2, S::npos); + test(S("lhcdo"), SV("oebqi"), 2, S::npos); + test(S("qnsoh"), SV("kojhpmbsfe"), 2, 2); + test(S("pkrof"), SV("acbsjqogpltdkhinfrem"), 2, 2); + test(S("fmtsp"), SV(""), 4, S::npos); + test(S("khbpm"), SV("aobjd"), 4, 2); + test(S("pbsji"), SV("pcbahntsje"), 4, 3); + test(S("mprdj"), SV("fhepcrntkoagbmldqijs"), 4, 4); + test(S("eqmpa"), SV(""), 5, S::npos); + test(S("omigs"), SV("kocgb"), 5, 3); + test(S("onmje"), SV("fbslrjiqkm"), 5, 3); + test(S("oqmrj"), SV("jeidpcmalhfnqbgtrsko"), 5, 4); + test(S("schfa"), SV(""), 6, S::npos); + test(S("igdsc"), SV("qngpd"), 6, 2); + test(S("brqgo"), SV("rodhqklgmb"), 6, 4); + test(S("tnrph"), SV("thdjgafrlbkoiqcspmne"), 6, 4); + test(S("hcjitbfapl"), SV(""), 0, S::npos); + test(S("daiprenocl"), SV("ashjd"), 0, 0); + test(S("litpcfdghe"), SV("mgojkldsqh"), 0, 0); + test(S("aidjksrolc"), SV("imqnaghkfrdtlopbjesc"), 0, 0); + test(S("qpghtfbaji"), SV(""), 1, S::npos); + test(S("gfshlcmdjr"), SV("nadkh"), 1, S::npos); + test(S("nkodajteqp"), SV("ofdrqmkebl"), 1, 1); + test(S("gbmetiprqd"), SV("bdfjqgatlksriohemnpc"), 1, 1); + test(S("crnklpmegd"), SV(""), 5, S::npos); + test(S("jsbtafedoc"), SV("prqgn"), 5, S::npos); + test(S("qnmodrtkeb"), SV("pejafmnokr"), 5, 5); + test(S("cpebqsfmnj"), SV("odnqkgijrhabfmcestlp"), 5, 5); + test(S("lmofqdhpki"), SV(""), 9, S::npos); + test(S("hnefkqimca"), SV("rtjpa"), 9, 9); + test(S("drtasbgmfp"), SV("ktsrmnqagd"), 9, 7); + test(S("lsaijeqhtr"), SV("rtdhgcisbnmoaqkfpjle"), 9, 9); + test(S("elgofjmbrq"), SV(""), 10, S::npos); + test(S("mjqdgalkpc"), SV("dplqa"), 10, 8); + test(S("kthqnfcerm"), SV("dkacjoptns"), 10, 6); + test(S("dfsjhanorc"), SV("hqfimtrgnbekpdcsjalo"), 10, 9); + test(S("eqsgalomhb"), SV(""), 11, S::npos); + test(S("akiteljmoh"), SV("lofbc"), 11, 8); + test(S("hlbdfreqjo"), SV("astoegbfpn"), 11, 9); + test(S("taqobhlerg"), SV("pdgreqomsncafklhtibj"), 11, 9); + test(S("snafbdlghrjkpqtoceim"), SV(""), 0, S::npos); + test(S("aemtbrgcklhndjisfpoq"), SV("lbtqd"), 0, S::npos); + test(S("pnracgfkjdiholtbqsem"), SV("tboimldpjh"), 0, 0); + test(S("dicfltehbsgrmojnpkaq"), SV("slcerthdaiqjfnobgkpm"), 0, 0); + test(S("jlnkraeodhcspfgbqitm"), SV(""), 1, S::npos); + test(S("lhosrngtmfjikbqpcade"), SV("aqibs"), 1, S::npos); + test(S("rbtaqjhgkneisldpmfoc"), SV("gtfblmqinc"), 1, 1); + test(S("gpifsqlrdkbonjtmheca"), SV("mkqpbtdalgniorhfescj"), 1, 1); + test(S("hdpkobnsalmcfijregtq"), SV(""), 10, S::npos); + test(S("jtlshdgqaiprkbcoenfm"), SV("pblas"), 10, 10); + test(S("fkdrbqltsgmcoiphneaj"), SV("arosdhcfme"), 10, 10); + test(S("crsplifgtqedjohnabmk"), SV("blkhjeogicatqfnpdmsr"), 10, 10); + test(S("niptglfbosehkamrdqcj"), SV(""), 19, S::npos); + test(S("copqdhstbingamjfkler"), SV("djkqc"), 19, 16); + test(S("mrtaefilpdsgocnhqbjk"), SV("lgokshjtpb"), 19, 19); + test(S("kojatdhlcmigpbfrqnes"), SV("bqjhtkfepimcnsgrlado"), 19, 19); + test(S("eaintpchlqsbdgrkjofm"), SV(""), 20, S::npos); + test(S("gjnhidfsepkrtaqbmclo"), SV("nocfa"), 20, 19); + test(S("spocfaktqdbiejlhngmr"), SV("bgtajmiedc"), 20, 18); + test(S("rphmlekgfscndtaobiqj"), SV("lsckfnqgdahejiopbtmr"), 20, 19); + test(S("liatsqdoegkmfcnbhrpj"), SV(""), 21, S::npos); + test(S("binjagtfldkrspcomqeh"), SV("gfsrt"), 21, 12); + test(S("latkmisecnorjbfhqpdg"), SV("pfsocbhjtm"), 21, 17); + test(S("lecfratdjkhnsmqpoigb"), SV("tpflmdnoicjgkberhqsa"), 21, 19); +} + +template <class S, class SV> +void test1() +{ + test(S(""), SV(""), S::npos); + test(S(""), SV("laenf"), S::npos); + test(S(""), SV("pqlnkmbdjo"), S::npos); + test(S(""), SV("qkamfogpnljdcshbreti"), S::npos); + test(S("nhmko"), SV(""), S::npos); + test(S("lahfb"), SV("irkhs"), 2); + test(S("gmfhd"), SV("kantesmpgj"), 1); + test(S("odaft"), SV("oknlrstdpiqmjbaghcfe"), 4); + test(S("eolhfgpjqk"), SV(""), S::npos); + test(S("nbatdlmekr"), SV("bnrpe"), 9); + test(S("jdmciepkaq"), SV("jtdaefblso"), 8); + test(S("hkbgspoflt"), SV("oselktgbcapndfjihrmq"), 9); + test(S("gprdcokbnjhlsfmtieqa"), SV(""), S::npos); + test(S("qjghlnftcaismkropdeb"), SV("bjaht"), 19); + test(S("pnalfrdtkqcmojiesbhg"), SV("hjlcmgpket"), 19); + test(S("pniotcfrhqsmgdkjbael"), SV("htaobedqikfplcgjsmrn"), 19); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#endif +} Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp?rev=318088&view=auto ============================================================================== --- libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp (added) +++ libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp Mon Nov 13 13:27:53 2017 @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// size_type find(basic_string_view sv, size_type pos = 0) const; + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type pos, typename S::size_type x) +{ + assert(s.find(sv, pos) == x); + if (x != S::npos) + assert(pos <= x && x + sv.size() <= s.size()); +} + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type x) +{ + assert(s.find(sv) == x); + if (x != S::npos) + assert(0 <= x && x + sv.size() <= s.size()); +} + +template <class S, class SV> +void test0() +{ + test(S(""), SV(""), 0, 0); + test(S(""), SV("abcde"), 0, S::npos); + test(S(""), SV("abcdeabcde"), 0, S::npos); + test(S(""), SV("abcdeabcdeabcdeabcde"), 0, S::npos); + test(S(""), SV(""), 1, S::npos); + test(S(""), SV("abcde"), 1, S::npos); + test(S(""), SV("abcdeabcde"), 1, S::npos); + test(S(""), SV("abcdeabcdeabcdeabcde"), 1, S::npos); + test(S("abcde"), SV(""), 0, 0); + test(S("abcde"), SV("abcde"), 0, 0); + test(S("abcde"), SV("abcdeabcde"), 0, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 0, S::npos); + test(S("abcde"), SV(""), 1, 1); + test(S("abcde"), SV("abcde"), 1, S::npos); + test(S("abcde"), SV("abcdeabcde"), 1, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 1, S::npos); + test(S("abcde"), SV(""), 2, 2); + test(S("abcde"), SV("abcde"), 2, S::npos); + test(S("abcde"), SV("abcdeabcde"), 2, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 2, S::npos); + test(S("abcde"), SV(""), 4, 4); + test(S("abcde"), SV("abcde"), 4, S::npos); + test(S("abcde"), SV("abcdeabcde"), 4, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 4, S::npos); + test(S("abcde"), SV(""), 5, 5); + test(S("abcde"), SV("abcde"), 5, S::npos); + test(S("abcde"), SV("abcdeabcde"), 5, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 5, S::npos); + test(S("abcde"), SV(""), 6, S::npos); + test(S("abcde"), SV("abcde"), 6, S::npos); + test(S("abcde"), SV("abcdeabcde"), 6, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 6, S::npos); + test(S("abcdeabcde"), SV(""), 0, 0); + test(S("abcdeabcde"), SV("abcde"), 0, 0); + test(S("abcdeabcde"), SV("abcdeabcde"), 0, 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 0, S::npos); + test(S("abcdeabcde"), SV(""), 1, 1); + test(S("abcdeabcde"), SV("abcde"), 1, 5); + test(S("abcdeabcde"), SV("abcdeabcde"), 1, S::npos); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 1, S::npos); + test(S("abcdeabcde"), SV(""), 5, 5); + test(S("abcdeabcde"), SV("abcde"), 5, 5); + test(S("abcdeabcde"), SV("abcdeabcde"), 5, S::npos); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 5, S::npos); + test(S("abcdeabcde"), SV(""), 9, 9); + test(S("abcdeabcde"), SV("abcde"), 9, S::npos); + test(S("abcdeabcde"), SV("abcdeabcde"), 9, S::npos); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 9, S::npos); + test(S("abcdeabcde"), SV(""), 10, 10); + test(S("abcdeabcde"), SV("abcde"), 10, S::npos); + test(S("abcdeabcde"), SV("abcdeabcde"), 10, S::npos); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 10, S::npos); + test(S("abcdeabcde"), SV(""), 11, S::npos); + test(S("abcdeabcde"), SV("abcde"), 11, S::npos); + test(S("abcdeabcde"), SV("abcdeabcde"), 11, S::npos); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 11, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV(""), 0, 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 0, 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 0, 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 0, 0); + test(S("abcdeabcdeabcdeabcde"), SV(""), 1, 1); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 1, 5); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 1, 5); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 1, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV(""), 10, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 10, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 10, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 10, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV(""), 19, 19); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 19, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 19, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 19, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV(""), 20, 20); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 20, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 20, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 20, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV(""), 21, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 21, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 21, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 21, S::npos); +} + +template <class S, class SV> +void test1() +{ + test(S(""), SV(""), 0); + test(S(""), SV("abcde"), S::npos); + test(S(""), SV("abcdeabcde"), S::npos); + test(S(""), SV("abcdeabcdeabcdeabcde"), S::npos); + test(S("abcde"), SV(""), 0); + test(S("abcde"), SV("abcde"), 0); + test(S("abcde"), SV("abcdeabcde"), S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), S::npos); + test(S("abcdeabcde"), SV(""), 0); + test(S("abcdeabcde"), SV("abcde"), 0); + test(S("abcdeabcde"), SV("abcdeabcde"), 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), S::npos); + test(S("abcdeabcdeabcdeabcde"), SV(""), 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 0); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#endif +} Added: libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_rfind/string_view_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_rfind/string_view_size.pass.cpp?rev=318088&view=auto ============================================================================== --- libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_rfind/string_view_size.pass.cpp (added) +++ libcxx/branches/release_50/test/std/strings/basic.string/string.ops/string_rfind/string_view_size.pass.cpp Mon Nov 13 13:27:53 2017 @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// size_type rfind(basic_string_view sv, size_type pos = npos) const; + +#include <string> +#include <cassert> + +#include "min_allocator.h" + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type pos, typename S::size_type x) +{ + assert(s.rfind(sv, pos) == x); + if (x != S::npos) + assert(x <= pos && x + sv.size() <= s.size()); +} + +template <class S, class SV> +void +test(const S& s, SV sv, typename S::size_type x) +{ + assert(s.rfind(sv) == x); + if (x != S::npos) + assert(0 <= x && x + sv.size() <= s.size()); +} + +template <class S, class SV> +void test0() +{ + test(S(""), SV(""), 0, 0); + test(S(""), SV("abcde"), 0, S::npos); + test(S(""), SV("abcdeabcde"), 0, S::npos); + test(S(""), SV("abcdeabcdeabcdeabcde"), 0, S::npos); + test(S(""), SV(""), 1, 0); + test(S(""), SV("abcde"), 1, S::npos); + test(S(""), SV("abcdeabcde"), 1, S::npos); + test(S(""), SV("abcdeabcdeabcdeabcde"), 1, S::npos); + test(S("abcde"), SV(""), 0, 0); + test(S("abcde"), SV("abcde"), 0, 0); + test(S("abcde"), SV("abcdeabcde"), 0, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 0, S::npos); + test(S("abcde"), SV(""), 1, 1); + test(S("abcde"), SV("abcde"), 1, 0); + test(S("abcde"), SV("abcdeabcde"), 1, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 1, S::npos); + test(S("abcde"), SV(""), 2, 2); + test(S("abcde"), SV("abcde"), 2, 0); + test(S("abcde"), SV("abcdeabcde"), 2, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 2, S::npos); + test(S("abcde"), SV(""), 4, 4); + test(S("abcde"), SV("abcde"), 4, 0); + test(S("abcde"), SV("abcdeabcde"), 4, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 4, S::npos); + test(S("abcde"), SV(""), 5, 5); + test(S("abcde"), SV("abcde"), 5, 0); + test(S("abcde"), SV("abcdeabcde"), 5, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 5, S::npos); + test(S("abcde"), SV(""), 6, 5); + test(S("abcde"), SV("abcde"), 6, 0); + test(S("abcde"), SV("abcdeabcde"), 6, S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), 6, S::npos); + test(S("abcdeabcde"), SV(""), 0, 0); + test(S("abcdeabcde"), SV("abcde"), 0, 0); + test(S("abcdeabcde"), SV("abcdeabcde"), 0, 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 0, S::npos); + test(S("abcdeabcde"), SV(""), 1, 1); + test(S("abcdeabcde"), SV("abcde"), 1, 0); + test(S("abcdeabcde"), SV("abcdeabcde"), 1, 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 1, S::npos); + test(S("abcdeabcde"), SV(""), 5, 5); + test(S("abcdeabcde"), SV("abcde"), 5, 5); + test(S("abcdeabcde"), SV("abcdeabcde"), 5, 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 5, S::npos); + test(S("abcdeabcde"), SV(""), 9, 9); + test(S("abcdeabcde"), SV("abcde"), 9, 5); + test(S("abcdeabcde"), SV("abcdeabcde"), 9, 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 9, S::npos); + test(S("abcdeabcde"), SV(""), 10, 10); + test(S("abcdeabcde"), SV("abcde"), 10, 5); + test(S("abcdeabcde"), SV("abcdeabcde"), 10, 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 10, S::npos); + test(S("abcdeabcde"), SV(""), 11, 10); + test(S("abcdeabcde"), SV("abcde"), 11, 5); + test(S("abcdeabcde"), SV("abcdeabcde"), 11, 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), 11, S::npos); + test(S("abcdeabcdeabcdeabcde"), SV(""), 0, 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 0, 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 0, 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 0, 0); + test(S("abcdeabcdeabcdeabcde"), SV(""), 1, 1); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 1, 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 1, 0); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 1, 0); + test(S("abcdeabcdeabcdeabcde"), SV(""), 10, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 10, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 10, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 10, 0); + test(S("abcdeabcdeabcdeabcde"), SV(""), 19, 19); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 19, 15); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 19, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 19, 0); + test(S("abcdeabcdeabcdeabcde"), SV(""), 20, 20); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 20, 15); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 20, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 20, 0); + test(S("abcdeabcdeabcdeabcde"), SV(""), 21, 20); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 21, 15); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 21, 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 21, 0); +} + +template <class S, class SV> +void test1() +{ + test(S(""), SV(""), 0); + test(S(""), SV("abcde"), S::npos); + test(S(""), SV("abcdeabcde"), S::npos); + test(S(""), SV("abcdeabcdeabcdeabcde"), S::npos); + test(S("abcde"), SV(""), 5); + test(S("abcde"), SV("abcde"), 0); + test(S("abcde"), SV("abcdeabcde"), S::npos); + test(S("abcde"), SV("abcdeabcdeabcdeabcde"), S::npos); + test(S("abcdeabcde"), SV(""), 10); + test(S("abcdeabcde"), SV("abcde"), 5); + test(S("abcdeabcde"), SV("abcdeabcde"), 0); + test(S("abcdeabcde"), SV("abcdeabcdeabcdeabcde"), S::npos); + test(S("abcdeabcdeabcdeabcde"), SV(""), 20); + test(S("abcdeabcdeabcdeabcde"), SV("abcde"), 15); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcde"), 10); + test(S("abcdeabcdeabcdeabcde"), SV("abcdeabcdeabcdeabcde"), 0); +} + +int main() +{ + { + typedef std::string S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#if TEST_STD_VER >= 11 + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + typedef std::string_view SV; + test0<S, SV>(); + test1<S, SV>(); + } +#endif +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits