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 //===----------------------------------------------------------------------===//
12 // constexpr size_type find(charT c, size_type pos = 0) const;
14 #include <experimental/string_view>
17 #include "test_macros.h"
18 #include "constexpr_char_traits.hpp"
22 test(const S& s, typename S::value_type c, typename S::size_type pos,
23 typename S::size_type x)
25 assert(s.find(c, pos) == x);
27 assert(pos <= x && x + 1 <= s.size());
32 test(const S& s, typename S::value_type c, typename S::size_type x)
34 assert(s.find(c) == x);
36 assert(0 <= x && x + 1 <= s.size());
42 typedef std::experimental::string_view S;
43 test(S(""), 'c', 0, S::npos);
44 test(S(""), 'c', 1, S::npos);
45 test(S("abcde"), 'c', 0, 2);
46 test(S("abcde"), 'c', 1, 2);
47 test(S("abcde"), 'c', 2, 2);
48 test(S("abcde"), 'c', 4, S::npos);
49 test(S("abcde"), 'c', 5, S::npos);
50 test(S("abcde"), 'c', 6, S::npos);
51 test(S("abcdeabcde"), 'c', 0, 2);
52 test(S("abcdeabcde"), 'c', 1, 2);
53 test(S("abcdeabcde"), 'c', 5, 7);
54 test(S("abcdeabcde"), 'c', 9, S::npos);
55 test(S("abcdeabcde"), 'c', 10, S::npos);
56 test(S("abcdeabcde"), 'c', 11, S::npos);
57 test(S("abcdeabcdeabcdeabcde"), 'c', 0, 2);
58 test(S("abcdeabcdeabcdeabcde"), 'c', 1, 2);
59 test(S("abcdeabcdeabcdeabcde"), 'c', 10, 12);
60 test(S("abcdeabcdeabcdeabcde"), 'c', 19, S::npos);
61 test(S("abcdeabcdeabcdeabcde"), 'c', 20, S::npos);
62 test(S("abcdeabcdeabcdeabcde"), 'c', 21, S::npos);
64 test(S(""), 'c', S::npos);
65 test(S("abcde"), 'c', 2);
66 test(S("abcdeabcde"), 'c', 2);
67 test(S("abcdeabcdeabcdeabcde"), 'c', 2);
72 typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
74 constexpr SV sv2 { "abcde", 5 };
76 static_assert (sv1.find( 'c', 0 ) == SV::npos, "" );
77 static_assert (sv1.find( 'c', 1 ) == SV::npos, "" );
78 static_assert (sv2.find( 'c', 0 ) == 2, "" );
79 static_assert (sv2.find( 'c', 1 ) == 2, "" );
80 static_assert (sv2.find( 'c', 2 ) == 2, "" );
81 static_assert (sv2.find( 'c', 3 ) == SV::npos, "" );
82 static_assert (sv2.find( 'c', 4 ) == SV::npos, "" );