string_size.pass.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <string>
  10. // size_type find_first_of(const basic_string& str, size_type pos = 0) const;
  11. #include <string>
  12. #include <cassert>
  13. template <class S>
  14. void
  15. test(const S& s, const S& str, typename S::size_type pos, typename S::size_type x)
  16. {
  17. assert(s.find_first_of(str, pos) == x);
  18. if (x != S::npos)
  19. assert(pos <= x && x < s.size());
  20. }
  21. template <class S>
  22. void
  23. test(const S& s, const S& str, typename S::size_type x)
  24. {
  25. assert(s.find_first_of(str) == x);
  26. if (x != S::npos)
  27. assert(x < s.size());
  28. }
  29. typedef std::string S;
  30. void test0()
  31. {
  32. test(S(""), S(""), 0, S::npos);
  33. test(S(""), S("laenf"), 0, S::npos);
  34. test(S(""), S("pqlnkmbdjo"), 0, S::npos);
  35. test(S(""), S("qkamfogpnljdcshbreti"), 0, S::npos);
  36. test(S(""), S(""), 1, S::npos);
  37. test(S(""), S("bjaht"), 1, S::npos);
  38. test(S(""), S("hjlcmgpket"), 1, S::npos);
  39. test(S(""), S("htaobedqikfplcgjsmrn"), 1, S::npos);
  40. test(S("fodgq"), S(""), 0, S::npos);
  41. test(S("qanej"), S("dfkap"), 0, 1);
  42. test(S("clbao"), S("ihqrfebgad"), 0, 2);
  43. test(S("mekdn"), S("ngtjfcalbseiqrphmkdo"), 0, 0);
  44. test(S("srdfq"), S(""), 1, S::npos);
  45. test(S("oemth"), S("ikcrq"), 1, S::npos);
  46. test(S("cdaih"), S("dmajblfhsg"), 1, 1);
  47. test(S("qohtk"), S("oqftjhdmkgsblacenirp"), 1, 1);
  48. test(S("cshmd"), S(""), 2, S::npos);
  49. test(S("lhcdo"), S("oebqi"), 2, 4);
  50. test(S("qnsoh"), S("kojhpmbsfe"), 2, 2);
  51. test(S("pkrof"), S("acbsjqogpltdkhinfrem"), 2, 2);
  52. test(S("fmtsp"), S(""), 4, S::npos);
  53. test(S("khbpm"), S("aobjd"), 4, S::npos);
  54. test(S("pbsji"), S("pcbahntsje"), 4, S::npos);
  55. test(S("mprdj"), S("fhepcrntkoagbmldqijs"), 4, 4);
  56. test(S("eqmpa"), S(""), 5, S::npos);
  57. test(S("omigs"), S("kocgb"), 5, S::npos);
  58. test(S("onmje"), S("fbslrjiqkm"), 5, S::npos);
  59. test(S("oqmrj"), S("jeidpcmalhfnqbgtrsko"), 5, S::npos);
  60. test(S("schfa"), S(""), 6, S::npos);
  61. test(S("igdsc"), S("qngpd"), 6, S::npos);
  62. test(S("brqgo"), S("rodhqklgmb"), 6, S::npos);
  63. test(S("tnrph"), S("thdjgafrlbkoiqcspmne"), 6, S::npos);
  64. test(S("hcjitbfapl"), S(""), 0, S::npos);
  65. test(S("daiprenocl"), S("ashjd"), 0, 0);
  66. test(S("litpcfdghe"), S("mgojkldsqh"), 0, 0);
  67. test(S("aidjksrolc"), S("imqnaghkfrdtlopbjesc"), 0, 0);
  68. test(S("qpghtfbaji"), S(""), 1, S::npos);
  69. test(S("gfshlcmdjr"), S("nadkh"), 1, 3);
  70. test(S("nkodajteqp"), S("ofdrqmkebl"), 1, 1);
  71. test(S("gbmetiprqd"), S("bdfjqgatlksriohemnpc"), 1, 1);
  72. test(S("crnklpmegd"), S(""), 5, S::npos);
  73. test(S("jsbtafedoc"), S("prqgn"), 5, S::npos);
  74. test(S("qnmodrtkeb"), S("pejafmnokr"), 5, 5);
  75. test(S("cpebqsfmnj"), S("odnqkgijrhabfmcestlp"), 5, 5);
  76. test(S("lmofqdhpki"), S(""), 9, S::npos);
  77. test(S("hnefkqimca"), S("rtjpa"), 9, 9);
  78. test(S("drtasbgmfp"), S("ktsrmnqagd"), 9, S::npos);
  79. test(S("lsaijeqhtr"), S("rtdhgcisbnmoaqkfpjle"), 9, 9);
  80. test(S("elgofjmbrq"), S(""), 10, S::npos);
  81. test(S("mjqdgalkpc"), S("dplqa"), 10, S::npos);
  82. test(S("kthqnfcerm"), S("dkacjoptns"), 10, S::npos);
  83. test(S("dfsjhanorc"), S("hqfimtrgnbekpdcsjalo"), 10, S::npos);
  84. test(S("eqsgalomhb"), S(""), 11, S::npos);
  85. test(S("akiteljmoh"), S("lofbc"), 11, S::npos);
  86. test(S("hlbdfreqjo"), S("astoegbfpn"), 11, S::npos);
  87. test(S("taqobhlerg"), S("pdgreqomsncafklhtibj"), 11, S::npos);
  88. test(S("snafbdlghrjkpqtoceim"), S(""), 0, S::npos);
  89. test(S("aemtbrgcklhndjisfpoq"), S("lbtqd"), 0, 3);
  90. test(S("pnracgfkjdiholtbqsem"), S("tboimldpjh"), 0, 0);
  91. test(S("dicfltehbsgrmojnpkaq"), S("slcerthdaiqjfnobgkpm"), 0, 0);
  92. test(S("jlnkraeodhcspfgbqitm"), S(""), 1, S::npos);
  93. test(S("lhosrngtmfjikbqpcade"), S("aqibs"), 1, 3);
  94. test(S("rbtaqjhgkneisldpmfoc"), S("gtfblmqinc"), 1, 1);
  95. test(S("gpifsqlrdkbonjtmheca"), S("mkqpbtdalgniorhfescj"), 1, 1);
  96. test(S("hdpkobnsalmcfijregtq"), S(""), 10, S::npos);
  97. test(S("jtlshdgqaiprkbcoenfm"), S("pblas"), 10, 10);
  98. test(S("fkdrbqltsgmcoiphneaj"), S("arosdhcfme"), 10, 10);
  99. test(S("crsplifgtqedjohnabmk"), S("blkhjeogicatqfnpdmsr"), 10, 10);
  100. test(S("niptglfbosehkamrdqcj"), S(""), 19, S::npos);
  101. test(S("copqdhstbingamjfkler"), S("djkqc"), 19, S::npos);
  102. test(S("mrtaefilpdsgocnhqbjk"), S("lgokshjtpb"), 19, 19);
  103. test(S("kojatdhlcmigpbfrqnes"), S("bqjhtkfepimcnsgrlado"), 19, 19);
  104. test(S("eaintpchlqsbdgrkjofm"), S(""), 20, S::npos);
  105. test(S("gjnhidfsepkrtaqbmclo"), S("nocfa"), 20, S::npos);
  106. test(S("spocfaktqdbiejlhngmr"), S("bgtajmiedc"), 20, S::npos);
  107. test(S("rphmlekgfscndtaobiqj"), S("lsckfnqgdahejiopbtmr"), 20, S::npos);
  108. test(S("liatsqdoegkmfcnbhrpj"), S(""), 21, S::npos);
  109. test(S("binjagtfldkrspcomqeh"), S("gfsrt"), 21, S::npos);
  110. test(S("latkmisecnorjbfhqpdg"), S("pfsocbhjtm"), 21, S::npos);
  111. test(S("lecfratdjkhnsmqpoigb"), S("tpflmdnoicjgkberhqsa"), 21, S::npos);
  112. }
  113. void test1()
  114. {
  115. test(S(""), S(""), S::npos);
  116. test(S(""), S("laenf"), S::npos);
  117. test(S(""), S("pqlnkmbdjo"), S::npos);
  118. test(S(""), S("qkamfogpnljdcshbreti"), S::npos);
  119. test(S("nhmko"), S(""), S::npos);
  120. test(S("lahfb"), S("irkhs"), 2);
  121. test(S("gmfhd"), S("kantesmpgj"), 0);
  122. test(S("odaft"), S("oknlrstdpiqmjbaghcfe"), 0);
  123. test(S("eolhfgpjqk"), S(""), S::npos);
  124. test(S("nbatdlmekr"), S("bnrpe"), 0);
  125. test(S("jdmciepkaq"), S("jtdaefblso"), 0);
  126. test(S("hkbgspoflt"), S("oselktgbcapndfjihrmq"), 0);
  127. test(S("gprdcokbnjhlsfmtieqa"), S(""), S::npos);
  128. test(S("qjghlnftcaismkropdeb"), S("bjaht"), 1);
  129. test(S("pnalfrdtkqcmojiesbhg"), S("hjlcmgpket"), 0);
  130. test(S("pniotcfrhqsmgdkjbael"), S("htaobedqikfplcgjsmrn"), 0);
  131. }
  132. int main()
  133. {
  134. test0();
  135. test1();
  136. }