1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // constexpr size_type rfind(charT c, size_type pos = npos) const;
13 #include <experimental/string_view>
16 #include "test_macros.h"
17 #include "constexpr_char_traits.hpp"
21 test(const S& s, typename S::value_type c, typename S::size_type pos,
22 typename S::size_type x)
24 assert(s.rfind(c, pos) == x);
26 assert(x <= pos && x + 1 <= s.size());
31 test(const S& s, typename S::value_type c, typename S::size_type x)
33 assert(s.rfind(c) == x);
35 assert(x + 1 <= s.size());
41 typedef std::experimental::string_view S;
42 test(S(""), 'b', 0, S::npos);
43 test(S(""), 'b', 1, S::npos);
44 test(S("abcde"), 'b', 0, S::npos);
45 test(S("abcde"), 'b', 1, 1);
46 test(S("abcde"), 'b', 2, 1);
47 test(S("abcde"), 'b', 4, 1);
48 test(S("abcde"), 'b', 5, 1);
49 test(S("abcde"), 'b', 6, 1);
50 test(S("abcdeabcde"), 'b', 0, S::npos);
51 test(S("abcdeabcde"), 'b', 1, 1);
52 test(S("abcdeabcde"), 'b', 5, 1);
53 test(S("abcdeabcde"), 'b', 9, 6);
54 test(S("abcdeabcde"), 'b', 10, 6);
55 test(S("abcdeabcde"), 'b', 11, 6);
56 test(S("abcdeabcdeabcdeabcde"), 'b', 0, S::npos);
57 test(S("abcdeabcdeabcdeabcde"), 'b', 1, 1);
58 test(S("abcdeabcdeabcdeabcde"), 'b', 10, 6);
59 test(S("abcdeabcdeabcdeabcde"), 'b', 19, 16);
60 test(S("abcdeabcdeabcdeabcde"), 'b', 20, 16);
61 test(S("abcdeabcdeabcdeabcde"), 'b', 21, 16);
63 test(S(""), 'b', S::npos);
64 test(S("abcde"), 'b', 1);
65 test(S("abcdeabcde"), 'b', 6);
66 test(S("abcdeabcdeabcdeabcde"), 'b', 16);
71 typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
73 constexpr SV sv2 { "abcde", 5 };
75 static_assert (sv1.rfind( 'b', 0 ) == SV::npos, "" );
76 static_assert (sv1.rfind( 'b', 1 ) == SV::npos, "" );
77 static_assert (sv2.rfind( 'b', 0 ) == SV::npos, "" );
78 static_assert (sv2.rfind( 'b', 1 ) == 1, "" );
79 static_assert (sv2.rfind( 'b', 2 ) == 1, "" );
80 static_assert (sv2.rfind( 'b', 3 ) == 1, "" );
81 static_assert (sv2.rfind( 'b', 4 ) == 1, "" );