char_size.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// size_type find_first_of(charT c, size_type pos = 0) const;
13
14#include <string>
15#include <cassert>
16
17template <class S>
18void
19test(const S& s, typename S::value_type c, typename S::size_type pos,
20     typename S::size_type x)
21{
22    assert(s.find_first_of(c, pos) == x);
23    if (x != S::npos)
24        assert(pos <= x && x < s.size());
25}
26
27template <class S>
28void
29test(const S& s, typename S::value_type c, typename S::size_type x)
30{
31    assert(s.find_first_of(c) == x);
32    if (x != S::npos)
33        assert(x < s.size());
34}
35
36typedef std::string S;
37
38int main()
39{
40    test(S(""), 'e', 0, S::npos);
41    test(S(""), 'e', 1, S::npos);
42    test(S("kitcj"), 'e', 0, S::npos);
43    test(S("qkamf"), 'e', 1, S::npos);
44    test(S("nhmko"), 'e', 2, S::npos);
45    test(S("tpsaf"), 'e', 4, S::npos);
46    test(S("lahfb"), 'e', 5, S::npos);
47    test(S("irkhs"), 'e', 6, S::npos);
48    test(S("gmfhdaipsr"), 'e', 0, S::npos);
49    test(S("kantesmpgj"), 'e', 1, 4);
50    test(S("odaftiegpm"), 'e', 5, 6);
51    test(S("oknlrstdpi"), 'e', 9, S::npos);
52    test(S("eolhfgpjqk"), 'e', 10, S::npos);
53    test(S("pcdrofikas"), 'e', 11, S::npos);
54    test(S("nbatdlmekrgcfqsophij"), 'e', 0, 7);
55    test(S("bnrpehidofmqtcksjgla"), 'e', 1, 4);
56    test(S("jdmciepkaqgotsrfnhlb"), 'e', 10, S::npos);
57    test(S("jtdaefblsokrmhpgcnqi"), 'e', 19, S::npos);
58    test(S("hkbgspofltajcnedqmri"), 'e', 20, S::npos);
59    test(S("oselktgbcapndfjihrmq"), 'e', 21, S::npos);
60
61    test(S(""), 'e', S::npos);
62    test(S("csope"), 'e', 4);
63    test(S("gfsmthlkon"), 'e', S::npos);
64    test(S("laenfsbridchgotmkqpj"), 'e', 2);
65}
66