testString.cxx 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmString.hxx"
  4. #include "cm_static_string_view.hxx"
  5. #include "cm_string_view.hxx"
  6. #include <cstring>
  7. #include <iostream>
  8. #include <iterator>
  9. #include <sstream>
  10. #include <stdexcept>
  11. #include <string>
  12. #include <type_traits>
  13. #include <utility>
  14. #define ASSERT_TRUE(x) \
  15. if (!(x)) { \
  16. std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << "\n"; \
  17. return false; \
  18. }
  19. static bool testConstructDefault()
  20. {
  21. std::cout << "testConstructDefault()\n";
  22. cm::String str;
  23. cm::String const& str_const = str;
  24. ASSERT_TRUE(bool(str_const) == false);
  25. ASSERT_TRUE(str_const.data() == nullptr);
  26. ASSERT_TRUE(str_const.size() == 0);
  27. ASSERT_TRUE(str_const.empty());
  28. ASSERT_TRUE(str.c_str() == nullptr);
  29. ASSERT_TRUE(str.str().empty());
  30. return true;
  31. }
  32. static bool testFromNullPtr(cm::String str)
  33. {
  34. cm::String const& str_const = str;
  35. ASSERT_TRUE(bool(str_const) == false);
  36. ASSERT_TRUE(str_const.data() == nullptr);
  37. ASSERT_TRUE(str_const.size() == 0);
  38. ASSERT_TRUE(str_const.empty());
  39. ASSERT_TRUE(str.c_str() == nullptr);
  40. ASSERT_TRUE(str.str().empty());
  41. return true;
  42. }
  43. static bool testConstructFromNullPtr()
  44. {
  45. std::cout << "testConstructFromNullPtr()\n";
  46. return testFromNullPtr(nullptr);
  47. }
  48. static bool testAssignFromNullPtr()
  49. {
  50. std::cout << "testAssignFromNullPtr()\n";
  51. cm::String str;
  52. str = nullptr;
  53. return testFromNullPtr(str);
  54. }
  55. static bool testFromCStrNull(cm::String str)
  56. {
  57. cm::String const& str_const = str;
  58. ASSERT_TRUE(bool(str_const) == false);
  59. ASSERT_TRUE(str_const.data() == nullptr);
  60. ASSERT_TRUE(str_const.size() == 0);
  61. ASSERT_TRUE(str_const.empty());
  62. ASSERT_TRUE(str.c_str() == nullptr);
  63. ASSERT_TRUE(str.str().empty());
  64. return true;
  65. }
  66. static bool testConstructFromCStrNull()
  67. {
  68. std::cout << "testConstructFromCStrNull()\n";
  69. const char* null = nullptr;
  70. return testFromCStrNull(null);
  71. }
  72. static bool testAssignFromCStrNull()
  73. {
  74. std::cout << "testAssignFromCStrNull()\n";
  75. const char* null = nullptr;
  76. cm::String str;
  77. str = null;
  78. return testFromCStrNull(str);
  79. }
  80. static char const charArray[] = "abc";
  81. static bool testFromCharArray(cm::String str)
  82. {
  83. cm::String const& str_const = str;
  84. ASSERT_TRUE(str_const.data() != charArray);
  85. ASSERT_TRUE(str_const.size() == sizeof(charArray) - 1);
  86. ASSERT_TRUE(str.c_str() != charArray);
  87. cm::String substr = str.substr(1);
  88. cm::String const& substr_const = substr;
  89. ASSERT_TRUE(substr_const.data() != &charArray[1]);
  90. ASSERT_TRUE(substr_const.size() == 2);
  91. ASSERT_TRUE(substr.c_str() != &charArray[1]);
  92. return true;
  93. }
  94. static bool testConstructFromCharArray()
  95. {
  96. std::cout << "testConstructFromCharArray()\n";
  97. return testFromCharArray(charArray);
  98. }
  99. static bool testAssignFromCharArray()
  100. {
  101. std::cout << "testAssignFromCharArray()\n";
  102. cm::String str;
  103. str = charArray;
  104. return testFromCharArray(str);
  105. }
  106. static const char* cstr = "abc";
  107. static bool testFromCStr(cm::String const& str)
  108. {
  109. ASSERT_TRUE(str.data() != cstr);
  110. ASSERT_TRUE(str.size() == 3);
  111. ASSERT_TRUE(std::strncmp(str.data(), cstr, 3) == 0);
  112. return true;
  113. }
  114. static bool testConstructFromCStr()
  115. {
  116. std::cout << "testConstructFromCStr()\n";
  117. return testFromCStr(cstr);
  118. ;
  119. }
  120. static bool testAssignFromCStr()
  121. {
  122. std::cout << "testAssignFromCStr()\n";
  123. cm::String str;
  124. str = cstr;
  125. return testFromCStr(str);
  126. ;
  127. }
  128. static const std::string stdstr = "abc";
  129. static bool testFromStdString(cm::String const& str)
  130. {
  131. #if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI
  132. // It would be nice to check this everywhere, but several platforms
  133. // still use a CoW implementation even in C++11.
  134. ASSERT_TRUE(str.data() != stdstr.data());
  135. #endif
  136. ASSERT_TRUE(str.size() == 3);
  137. ASSERT_TRUE(std::strncmp(str.data(), stdstr.data(), 3) == 0);
  138. return true;
  139. }
  140. static bool testConstructFromStdString()
  141. {
  142. std::cout << "testConstructFromStdString()\n";
  143. return testFromStdString(stdstr);
  144. }
  145. static bool testAssignFromStdString()
  146. {
  147. std::cout << "testAssignFromStdString()\n";
  148. cm::String str;
  149. str = stdstr;
  150. return testFromStdString(str);
  151. }
  152. static bool testConstructFromView()
  153. {
  154. std::cout << "testConstructFromView()\n";
  155. cm::string_view view = cstr;
  156. return testFromCStr(view);
  157. }
  158. static bool testAssignFromView()
  159. {
  160. std::cout << "testAssignFromView()\n";
  161. cm::string_view view = cstr;
  162. cm::String str;
  163. str = view;
  164. return testFromCStr(str);
  165. }
  166. static bool testFromChar(cm::String const& str)
  167. {
  168. ASSERT_TRUE(str.size() == 1);
  169. ASSERT_TRUE(std::strncmp(str.data(), "a", 1) == 0);
  170. return true;
  171. }
  172. static bool testConstructFromChar()
  173. {
  174. std::cout << "testConstructFromChar()\n";
  175. return testFromChar('a');
  176. }
  177. static bool testAssignFromChar()
  178. {
  179. std::cout << "testAssignFromChar()\n";
  180. cm::String str;
  181. str = 'a';
  182. return testFromChar(str);
  183. }
  184. static bool testConstructFromInitList()
  185. {
  186. std::cout << "testConstructFromInitList()\n";
  187. cm::String const str{ 'a', 'b', 'c' };
  188. ASSERT_TRUE(str.size() == 3);
  189. ASSERT_TRUE(std::strncmp(str.data(), "abc", 3) == 0);
  190. return true;
  191. }
  192. static bool testAssignFromInitList()
  193. {
  194. std::cout << "testAssignFromInitList()\n";
  195. cm::String str;
  196. str = { 'a', 'b', 'c' };
  197. ASSERT_TRUE(str.size() == 3);
  198. ASSERT_TRUE(std::strncmp(str.data(), "abc", 3) == 0);
  199. return true;
  200. }
  201. static bool testConstructFromBuffer()
  202. {
  203. std::cout << "testConstructFromBuffer()\n";
  204. cm::String const str(cstr, 3);
  205. return testFromCStr(str);
  206. }
  207. static bool testConstructFromInputIterator()
  208. {
  209. std::cout << "testConstructFromInputIterator()\n";
  210. cm::String const str(cstr, cstr + 3);
  211. ASSERT_TRUE(str.data() != cstr);
  212. ASSERT_TRUE(str.size() == 3);
  213. ASSERT_TRUE(std::strncmp(str.data(), cstr, 3) == 0);
  214. return true;
  215. }
  216. static bool testConstructFromN()
  217. {
  218. std::cout << "testConstructFromN()\n";
  219. cm::String const str(3, 'a');
  220. ASSERT_TRUE(str.size() == 3);
  221. ASSERT_TRUE(std::strncmp(str.data(), "aaa", 3) == 0);
  222. return true;
  223. }
  224. static const auto staticStringView = "abc"_s;
  225. static bool testFromStaticStringView(cm::String str)
  226. {
  227. cm::String const& str_const = str;
  228. ASSERT_TRUE(str_const.data() == staticStringView.data());
  229. ASSERT_TRUE(str_const.size() == staticStringView.size());
  230. ASSERT_TRUE(str.c_str() == staticStringView);
  231. cm::String substr = str.substr(1);
  232. cm::String const& substr_const = substr;
  233. ASSERT_TRUE(substr_const.data() == &staticStringView[1]);
  234. ASSERT_TRUE(substr_const.size() == 2);
  235. ASSERT_TRUE(substr.c_str() == &staticStringView[1]);
  236. return true;
  237. }
  238. static bool testConstructFromStaticStringView()
  239. {
  240. std::cout << "testConstructFromStaticStringView()\n";
  241. return testFromStaticStringView(staticStringView);
  242. }
  243. static bool testAssignFromStaticStringView()
  244. {
  245. std::cout << "testAssignFromStaticStringView()\n";
  246. cm::String str;
  247. str = staticStringView;
  248. return testFromStaticStringView(str);
  249. }
  250. static bool testConstructCopy()
  251. {
  252. std::cout << "testConstructCopy()\n";
  253. cm::String s1 = std::string("abc");
  254. cm::String s2 = s1;
  255. ASSERT_TRUE(s1.data() == s2.data());
  256. ASSERT_TRUE(s1.size() == 3);
  257. ASSERT_TRUE(s2.size() == 3);
  258. ASSERT_TRUE(std::strncmp(s2.data(), "abc", 3) == 0);
  259. return true;
  260. }
  261. static bool testConstructMove()
  262. {
  263. std::cout << "testConstructMove()\n";
  264. cm::String s1 = std::string("abc");
  265. cm::String s2 = std::move(s1);
  266. ASSERT_TRUE(s1.data() == nullptr);
  267. ASSERT_TRUE(s1.size() == 0);
  268. ASSERT_TRUE(s2.size() == 3);
  269. ASSERT_TRUE(std::strncmp(s2.data(), "abc", 3) == 0);
  270. return true;
  271. }
  272. static bool testAssignCopy()
  273. {
  274. std::cout << "testAssignCopy()\n";
  275. cm::String s1 = std::string("abc");
  276. cm::String s2;
  277. s2 = s1;
  278. ASSERT_TRUE(s1.data() == s2.data());
  279. ASSERT_TRUE(s1.size() == 3);
  280. ASSERT_TRUE(s2.size() == 3);
  281. ASSERT_TRUE(std::strncmp(s2.data(), "abc", 3) == 0);
  282. return true;
  283. }
  284. static bool testAssignMove()
  285. {
  286. std::cout << "testAssignMove()\n";
  287. cm::String s1 = std::string("abc");
  288. cm::String s2;
  289. s2 = std::move(s1);
  290. ASSERT_TRUE(s1.data() == nullptr);
  291. ASSERT_TRUE(s1.size() == 0);
  292. ASSERT_TRUE(s2.size() == 3);
  293. ASSERT_TRUE(std::strncmp(s2.data(), "abc", 3) == 0);
  294. return true;
  295. }
  296. static bool testOperatorBool()
  297. {
  298. std::cout << "testOperatorBool()\n";
  299. cm::String str;
  300. ASSERT_TRUE(!str);
  301. str = "";
  302. ASSERT_TRUE(str);
  303. str = static_cast<const char*>(nullptr);
  304. ASSERT_TRUE(!str);
  305. str = std::string();
  306. ASSERT_TRUE(str);
  307. str = nullptr;
  308. ASSERT_TRUE(!str);
  309. return true;
  310. }
  311. static bool testOperatorIndex()
  312. {
  313. std::cout << "testOperatorIndex()\n";
  314. cm::String str = "abc";
  315. ASSERT_TRUE(str[0] == 'a');
  316. ASSERT_TRUE(str[1] == 'b');
  317. ASSERT_TRUE(str[2] == 'c');
  318. return true;
  319. }
  320. static bool testOperatorPlusEqual()
  321. {
  322. std::cout << "testOperatorPlusEqual()\n";
  323. cm::String str = "a";
  324. str += "b";
  325. {
  326. const char* c = "c";
  327. str += c;
  328. }
  329. str += 'd';
  330. str += std::string("e");
  331. str += cm::string_view("f", 1);
  332. str += cm::String("g");
  333. ASSERT_TRUE(str.size() == 7);
  334. ASSERT_TRUE(std::strncmp(str.data(), "abcdefg", 7) == 0);
  335. return true;
  336. }
  337. static bool testOperatorCompare()
  338. {
  339. std::cout << "testOperatorCompare()\n";
  340. cm::String str = "b";
  341. {
  342. ASSERT_TRUE(str == "b");
  343. ASSERT_TRUE("b" == str);
  344. ASSERT_TRUE(str != "a");
  345. ASSERT_TRUE("a" != str);
  346. ASSERT_TRUE(str < "c");
  347. ASSERT_TRUE("a" < str);
  348. ASSERT_TRUE(str > "a");
  349. ASSERT_TRUE("c" > str);
  350. ASSERT_TRUE(str <= "b");
  351. ASSERT_TRUE("b" <= str);
  352. ASSERT_TRUE(str >= "b");
  353. ASSERT_TRUE("b" >= str);
  354. }
  355. {
  356. const char* a = "a";
  357. const char* b = "b";
  358. const char* c = "c";
  359. ASSERT_TRUE(str == b);
  360. ASSERT_TRUE(b == str);
  361. ASSERT_TRUE(str != a);
  362. ASSERT_TRUE(a != str);
  363. ASSERT_TRUE(str < c);
  364. ASSERT_TRUE(a < str);
  365. ASSERT_TRUE(str > a);
  366. ASSERT_TRUE(c > str);
  367. ASSERT_TRUE(str <= b);
  368. ASSERT_TRUE(b <= str);
  369. ASSERT_TRUE(str >= b);
  370. ASSERT_TRUE(b >= str);
  371. }
  372. {
  373. ASSERT_TRUE(str == 'b');
  374. ASSERT_TRUE('b' == str);
  375. ASSERT_TRUE(str != 'a');
  376. ASSERT_TRUE('a' != str);
  377. ASSERT_TRUE(str < 'c');
  378. ASSERT_TRUE('a' < str);
  379. ASSERT_TRUE(str > 'a');
  380. ASSERT_TRUE('c' > str);
  381. ASSERT_TRUE(str <= 'b');
  382. ASSERT_TRUE('b' <= str);
  383. ASSERT_TRUE(str >= 'b');
  384. ASSERT_TRUE('b' >= str);
  385. }
  386. {
  387. std::string const a = "a";
  388. std::string const b = "b";
  389. std::string const c = "c";
  390. ASSERT_TRUE(str == b);
  391. ASSERT_TRUE(b == str);
  392. ASSERT_TRUE(str != a);
  393. ASSERT_TRUE(a != str);
  394. ASSERT_TRUE(str < c);
  395. ASSERT_TRUE(a < str);
  396. ASSERT_TRUE(str > a);
  397. ASSERT_TRUE(c > str);
  398. ASSERT_TRUE(str <= b);
  399. ASSERT_TRUE(b <= str);
  400. ASSERT_TRUE(str >= b);
  401. ASSERT_TRUE(b >= str);
  402. }
  403. {
  404. cm::string_view const a("a", 1);
  405. cm::string_view const b("b", 1);
  406. cm::string_view const c("c", 1);
  407. ASSERT_TRUE(str == b);
  408. ASSERT_TRUE(b == str);
  409. ASSERT_TRUE(str != a);
  410. ASSERT_TRUE(a != str);
  411. ASSERT_TRUE(str < c);
  412. ASSERT_TRUE(a < str);
  413. ASSERT_TRUE(str > a);
  414. ASSERT_TRUE(c > str);
  415. ASSERT_TRUE(str <= b);
  416. ASSERT_TRUE(b <= str);
  417. ASSERT_TRUE(str >= b);
  418. ASSERT_TRUE(b >= str);
  419. }
  420. {
  421. cm::String const a("a");
  422. cm::String const b("b");
  423. cm::String const c("c");
  424. ASSERT_TRUE(str == b);
  425. ASSERT_TRUE(b == str);
  426. ASSERT_TRUE(str != a);
  427. ASSERT_TRUE(a != str);
  428. ASSERT_TRUE(str < c);
  429. ASSERT_TRUE(a < str);
  430. ASSERT_TRUE(str > a);
  431. ASSERT_TRUE(c > str);
  432. ASSERT_TRUE(str <= b);
  433. ASSERT_TRUE(b <= str);
  434. ASSERT_TRUE(str >= b);
  435. ASSERT_TRUE(b >= str);
  436. }
  437. return true;
  438. }
  439. static bool testOperatorStream()
  440. {
  441. std::cout << "testOperatorStream()\n";
  442. std::ostringstream ss;
  443. ss << "a" << cm::String("b") << 'c';
  444. ASSERT_TRUE(ss.str() == "abc");
  445. return true;
  446. }
  447. static bool testOperatorStdStringPlusEqual()
  448. {
  449. std::cout << "testOperatorStdStringPlusEqual()\n";
  450. std::string s = "a";
  451. s += cm::String("b");
  452. ASSERT_TRUE(s == "ab");
  453. return true;
  454. }
  455. static bool testMethod_borrow()
  456. {
  457. std::cout << "testMethod_borrow()\n";
  458. std::string s = "abc";
  459. cm::String str = cm::String::borrow(s);
  460. ASSERT_TRUE(str.data() == s.data());
  461. ASSERT_TRUE(str.size() == s.size());
  462. ASSERT_TRUE(str == s);
  463. return true;
  464. }
  465. static bool testMethod_view()
  466. {
  467. std::cout << "testMethod_view()\n";
  468. cm::String str;
  469. ASSERT_TRUE(str.view().data() == nullptr);
  470. ASSERT_TRUE(str.view().size() == 0);
  471. str = charArray;
  472. ASSERT_TRUE(str.view().data() != charArray);
  473. ASSERT_TRUE(str.view().size() == sizeof(charArray) - 1);
  474. str = std::string("abc");
  475. ASSERT_TRUE(str.view().size() == 3);
  476. ASSERT_TRUE(strncmp(str.view().data(), "abc", 3) == 0);
  477. return true;
  478. }
  479. static bool testMethod_empty()
  480. {
  481. std::cout << "testMethod_empty()\n";
  482. cm::String str;
  483. ASSERT_TRUE(str.empty());
  484. str = "";
  485. ASSERT_TRUE(str.empty());
  486. str = "abc";
  487. ASSERT_TRUE(!str.empty());
  488. str = std::string();
  489. ASSERT_TRUE(str.empty());
  490. str = std::string("abc");
  491. ASSERT_TRUE(!str.empty());
  492. return true;
  493. }
  494. static bool testMethod_length()
  495. {
  496. std::cout << "testMethod_length()\n";
  497. cm::String str;
  498. ASSERT_TRUE(str.length() == 0);
  499. str = "";
  500. ASSERT_TRUE(str.length() == 0);
  501. str = "abc";
  502. ASSERT_TRUE(str.length() == 3);
  503. str = std::string();
  504. ASSERT_TRUE(str.length() == 0);
  505. str = std::string("abc");
  506. ASSERT_TRUE(str.length() == 3);
  507. return true;
  508. }
  509. static bool testMethod_at()
  510. {
  511. std::cout << "testMethod_at()\n";
  512. cm::String str = "abc";
  513. ASSERT_TRUE(str.at(0) == 'a');
  514. ASSERT_TRUE(str.at(1) == 'b');
  515. ASSERT_TRUE(str.at(2) == 'c');
  516. bool except_out_of_range = false;
  517. try {
  518. str.at(3);
  519. } catch (std::out_of_range&) {
  520. except_out_of_range = true;
  521. }
  522. ASSERT_TRUE(except_out_of_range);
  523. return true;
  524. }
  525. static bool testMethod_front_back()
  526. {
  527. std::cout << "testMethod_front_back()\n";
  528. cm::String str = "abc";
  529. ASSERT_TRUE(str.front() == 'a');
  530. ASSERT_TRUE(str.back() == 'c');
  531. return true;
  532. }
  533. static bool testMethodIterators()
  534. {
  535. std::cout << "testMethodIterators()\n";
  536. cm::String str = "abc";
  537. ASSERT_TRUE(*str.begin() == 'a');
  538. ASSERT_TRUE(*(str.end() - 1) == 'c');
  539. ASSERT_TRUE(str.end() - str.begin() == 3);
  540. ASSERT_TRUE(*str.cbegin() == 'a');
  541. ASSERT_TRUE(*(str.cend() - 1) == 'c');
  542. ASSERT_TRUE(str.cend() - str.cbegin() == 3);
  543. ASSERT_TRUE(*str.rbegin() == 'c');
  544. ASSERT_TRUE(*(str.rend() - 1) == 'a');
  545. ASSERT_TRUE(str.rend() - str.rbegin() == 3);
  546. ASSERT_TRUE(*str.crbegin() == 'c');
  547. ASSERT_TRUE(*(str.crend() - 1) == 'a');
  548. ASSERT_TRUE(str.crend() - str.crbegin() == 3);
  549. return true;
  550. }
  551. static bool testMethod_clear()
  552. {
  553. std::cout << "testMethod_clear()\n";
  554. cm::String str = "abc";
  555. ASSERT_TRUE(!str.empty());
  556. str.clear();
  557. ASSERT_TRUE(str.empty());
  558. return true;
  559. }
  560. static bool testMethod_insert()
  561. {
  562. std::cout << "testMethod_insert()\n";
  563. cm::String str = "abc";
  564. str.insert(1, 2, 'd').insert(0, 1, '_');
  565. ASSERT_TRUE(str.size() == 6);
  566. ASSERT_TRUE(std::strncmp(str.data(), "_addbc", 6) == 0);
  567. return true;
  568. }
  569. static bool testMethod_erase()
  570. {
  571. std::cout << "testMethod_erase()\n";
  572. cm::String str = "abcdefg";
  573. str.erase(5).erase(1, 2);
  574. ASSERT_TRUE(str.size() == 3);
  575. ASSERT_TRUE(std::strncmp(str.data(), "ade", 3) == 0);
  576. return true;
  577. }
  578. static bool testMethod_push_back()
  579. {
  580. std::cout << "testMethod_push_back()\n";
  581. cm::String str = "abc";
  582. str.push_back('d');
  583. ASSERT_TRUE(str == "abcd");
  584. return true;
  585. }
  586. static bool testMethod_pop_back()
  587. {
  588. std::cout << "testMethod_pop_back()\n";
  589. cm::String str = "abc";
  590. str.pop_back();
  591. ASSERT_TRUE(str == "ab");
  592. return true;
  593. }
  594. static bool testMethod_replace()
  595. {
  596. std::cout << "testMethod_replace()\n";
  597. {
  598. cm::String str = "abcd";
  599. const char* bc = "bc";
  600. ASSERT_TRUE(str.replace(1, 2, "BC") == "aBCd");
  601. ASSERT_TRUE(str.replace(1, 2, bc) == "abcd");
  602. ASSERT_TRUE(str.replace(1, 2, 'x') == "axd");
  603. ASSERT_TRUE(str.replace(1, 1, std::string("bc")) == "abcd");
  604. ASSERT_TRUE(str.replace(1, 2, cm::string_view("BC", 2)) == "aBCd");
  605. ASSERT_TRUE(str.replace(1, 2, cm::String("bc")) == "abcd");
  606. }
  607. {
  608. cm::String str = "abcd";
  609. const char* bc = "bc";
  610. ASSERT_TRUE(str.replace(str.begin() + 1, str.begin() + 3, "BC") == "aBCd");
  611. ASSERT_TRUE(str.replace(str.begin() + 1, str.begin() + 3, bc) == "abcd");
  612. ASSERT_TRUE(str.replace(str.begin() + 1, str.begin() + 3, 'x') == "axd");
  613. ASSERT_TRUE(str.replace(str.begin() + 1, str.begin() + 2,
  614. std::string("bc")) == "abcd");
  615. ASSERT_TRUE(str.replace(str.begin() + 1, str.begin() + 3,
  616. cm::string_view("BC", 2)) == "aBCd");
  617. ASSERT_TRUE(str.replace(str.begin() + 1, str.begin() + 3,
  618. cm::String("bc")) == "abcd");
  619. }
  620. {
  621. cm::String str = "abcd";
  622. const char* bc = "_bc";
  623. ASSERT_TRUE(str.replace(1, 2, "_BC_", 1, 2) == "aBCd");
  624. ASSERT_TRUE(str.replace(1, 2, bc, 1) == "abcd");
  625. ASSERT_TRUE(str.replace(1, 2, 'x', 0) == "axd");
  626. ASSERT_TRUE(str.replace(1, 1, std::string("_bc_"), 1, 2) == "abcd");
  627. ASSERT_TRUE(str.replace(1, 2, cm::string_view("_BC", 3), 1) == "aBCd");
  628. ASSERT_TRUE(str.replace(1, 2, cm::String("_bc_"), 1, 2) == "abcd");
  629. }
  630. {
  631. cm::String str = "abcd";
  632. const char* bc = "_bc_";
  633. ASSERT_TRUE(str.replace(1, 2, 2, 'x') == "axxd");
  634. ASSERT_TRUE(str.replace(str.begin() + 1, str.begin() + 3, 2, 'y') ==
  635. "ayyd");
  636. ASSERT_TRUE(
  637. str.replace(str.begin() + 1, str.begin() + 3, bc + 1, bc + 3) == "abcd");
  638. }
  639. return true;
  640. }
  641. static bool testMethod_copy()
  642. {
  643. std::cout << "testMethod_copy()\n";
  644. cm::String str = "abc";
  645. char dest[2];
  646. cm::String::size_type n = str.copy(dest, 2, 1);
  647. ASSERT_TRUE(n == 2);
  648. ASSERT_TRUE(std::strncmp(dest, "bc", 2) == 0);
  649. n = str.copy(dest, 2);
  650. ASSERT_TRUE(n == 2);
  651. ASSERT_TRUE(std::strncmp(dest, "ab", 2) == 0);
  652. return true;
  653. }
  654. static bool testMethod_resize()
  655. {
  656. std::cout << "testMethod_resize()\n";
  657. cm::String str = "abc";
  658. str.resize(3);
  659. ASSERT_TRUE(str == "abc");
  660. str.resize(2);
  661. ASSERT_TRUE(str == "ab");
  662. str.resize(3, 'c');
  663. ASSERT_TRUE(str == "abc");
  664. return true;
  665. }
  666. static bool testMethod_swap()
  667. {
  668. std::cout << "testMethod_swap()\n";
  669. cm::String str1 = std::string("1");
  670. cm::String str2 = std::string("2");
  671. str1.swap(str2);
  672. ASSERT_TRUE(str1 == "2");
  673. ASSERT_TRUE(str2 == "1");
  674. return true;
  675. }
  676. static bool testMethod_substr_AtEnd(cm::String str)
  677. {
  678. cm::String substr = str.substr(1);
  679. ASSERT_TRUE(substr.data() == str.data() + 1);
  680. ASSERT_TRUE(substr.size() == 2);
  681. // c_str() at the end of the buffer does not internally mutate.
  682. ASSERT_TRUE(std::strcmp(substr.c_str(), "bc") == 0);
  683. ASSERT_TRUE(substr.c_str() == str.data() + 1);
  684. ASSERT_TRUE(substr.data() == str.data() + 1);
  685. ASSERT_TRUE(substr.size() == 2);
  686. // str() internally mutates.
  687. ASSERT_TRUE(substr.str() == "bc");
  688. ASSERT_TRUE(substr.data() != str.data() + 1);
  689. ASSERT_TRUE(substr.size() == 2);
  690. ASSERT_TRUE(substr.c_str() != str.data() + 1);
  691. ASSERT_TRUE(std::strcmp(substr.c_str(), "bc") == 0);
  692. return true;
  693. }
  694. static bool testMethod_substr_AtEndBorrowed()
  695. {
  696. std::cout << "testMethod_substr_AtEndBorrowed()\n";
  697. return testMethod_substr_AtEnd("abc"_s);
  698. }
  699. static bool testMethod_substr_AtEndOwned()
  700. {
  701. std::cout << "testMethod_substr_AtEndOwned()\n";
  702. return testMethod_substr_AtEnd(std::string("abc"));
  703. }
  704. static bool testMethod_substr_AtStart(cm::String str)
  705. {
  706. {
  707. cm::String substr = str.substr(0, 2);
  708. ASSERT_TRUE(substr.data() == str.data());
  709. ASSERT_TRUE(substr.size() == 2);
  710. // c_str() not at the end of the buffer internally mutates.
  711. const char* substr_c = substr.c_str();
  712. ASSERT_TRUE(std::strcmp(substr_c, "ab") == 0);
  713. ASSERT_TRUE(substr_c != str.data());
  714. ASSERT_TRUE(substr.data() != str.data());
  715. ASSERT_TRUE(substr.size() == 2);
  716. // str() does not need to internally mutate after c_str() did so
  717. ASSERT_TRUE(substr.str() == "ab");
  718. ASSERT_TRUE(substr.data() == substr_c);
  719. ASSERT_TRUE(substr.size() == 2);
  720. ASSERT_TRUE(substr.c_str() == substr_c);
  721. }
  722. {
  723. cm::String substr = str.substr(0, 2);
  724. ASSERT_TRUE(substr.data() == str.data());
  725. ASSERT_TRUE(substr.size() == 2);
  726. // str() internally mutates.
  727. ASSERT_TRUE(substr.str() == "ab");
  728. ASSERT_TRUE(substr.data() != str.data());
  729. ASSERT_TRUE(substr.size() == 2);
  730. ASSERT_TRUE(substr.c_str() != str.data());
  731. // c_str() does not internally after str() did so
  732. const char* substr_c = substr.c_str();
  733. ASSERT_TRUE(std::strcmp(substr_c, "ab") == 0);
  734. ASSERT_TRUE(substr_c == substr.data());
  735. ASSERT_TRUE(substr.size() == 2);
  736. }
  737. return true;
  738. }
  739. static bool testMethod_substr_AtStartBorrowed()
  740. {
  741. std::cout << "testMethod_substr_AtStartBorrowed()\n";
  742. return testMethod_substr_AtStart("abc"_s);
  743. }
  744. static bool testMethod_substr_AtStartOwned()
  745. {
  746. std::cout << "testMethod_substr_AtStartOwned()\n";
  747. return testMethod_substr_AtStart(std::string("abc"));
  748. }
  749. static bool testMethod_compare()
  750. {
  751. std::cout << "testMethod_compare()\n";
  752. cm::String str = "b";
  753. ASSERT_TRUE(str.compare("a") > 0);
  754. ASSERT_TRUE(str.compare("b") == 0);
  755. ASSERT_TRUE(str.compare("c") < 0);
  756. {
  757. const char* a = "a";
  758. const char* b = "b";
  759. const char* c = "c";
  760. ASSERT_TRUE(str.compare(a) > 0);
  761. ASSERT_TRUE(str.compare(b) == 0);
  762. ASSERT_TRUE(str.compare(c) < 0);
  763. }
  764. ASSERT_TRUE(str.compare('a') > 0);
  765. ASSERT_TRUE(str.compare('b') == 0);
  766. ASSERT_TRUE(str.compare('c') < 0);
  767. ASSERT_TRUE(str.compare(std::string("a")) > 0);
  768. ASSERT_TRUE(str.compare(std::string("b")) == 0);
  769. ASSERT_TRUE(str.compare(std::string("c")) < 0);
  770. ASSERT_TRUE(str.compare(cm::string_view("a_", 1)) > 0);
  771. ASSERT_TRUE(str.compare(cm::string_view("b_", 1)) == 0);
  772. ASSERT_TRUE(str.compare(cm::string_view("c_", 1)) < 0);
  773. ASSERT_TRUE(str.compare(cm::String("a")) > 0);
  774. ASSERT_TRUE(str.compare(cm::String("b")) == 0);
  775. ASSERT_TRUE(str.compare(cm::String("c")) < 0);
  776. ASSERT_TRUE(str.compare(0, 1, cm::string_view("a", 1)) > 0);
  777. ASSERT_TRUE(str.compare(1, 0, cm::string_view("", 0)) == 0);
  778. ASSERT_TRUE(str.compare(0, 1, cm::string_view("ac", 2), 1, 1) < 0);
  779. ASSERT_TRUE(str.compare(1, 0, "") == 0);
  780. ASSERT_TRUE(str.compare(1, 0, "_", 0) == 0);
  781. return true;
  782. }
  783. static bool testMethod_find()
  784. {
  785. std::cout << "testMethod_find()\n";
  786. cm::String str = "abcabc";
  787. ASSERT_TRUE(str.find("a") == 0);
  788. ASSERT_TRUE(str.find("a", 1) == 3);
  789. {
  790. const char* a = "a";
  791. ASSERT_TRUE(str.find(a) == 0);
  792. ASSERT_TRUE(str.find(a, 1) == 3);
  793. }
  794. ASSERT_TRUE(str.find('a') == 0);
  795. ASSERT_TRUE(str.find('a', 1) == 3);
  796. ASSERT_TRUE(str.find(std::string("a")) == 0);
  797. ASSERT_TRUE(str.find(std::string("a"), 1) == 3);
  798. ASSERT_TRUE(str.find(cm::string_view("a_", 1)) == 0);
  799. ASSERT_TRUE(str.find(cm::string_view("a_", 1), 1) == 3);
  800. ASSERT_TRUE(str.find(cm::String("a")) == 0);
  801. ASSERT_TRUE(str.find(cm::String("a"), 1) == 3);
  802. ASSERT_TRUE(str.find("ab_", 1, 2) == 3);
  803. return true;
  804. }
  805. static bool testMethod_rfind()
  806. {
  807. std::cout << "testMethod_rfind()\n";
  808. cm::String str = "abcabc";
  809. ASSERT_TRUE(str.rfind("a") == 3);
  810. ASSERT_TRUE(str.rfind("a", 1) == 0);
  811. {
  812. const char* a = "a";
  813. ASSERT_TRUE(str.rfind(a) == 3);
  814. ASSERT_TRUE(str.rfind(a, 1) == 0);
  815. }
  816. ASSERT_TRUE(str.rfind('a') == 3);
  817. ASSERT_TRUE(str.rfind('a', 1) == 0);
  818. ASSERT_TRUE(str.rfind(std::string("a")) == 3);
  819. ASSERT_TRUE(str.rfind(std::string("a"), 1) == 0);
  820. ASSERT_TRUE(str.rfind(cm::string_view("a_", 1)) == 3);
  821. ASSERT_TRUE(str.rfind(cm::string_view("a_", 1), 1) == 0);
  822. ASSERT_TRUE(str.rfind(cm::String("a")) == 3);
  823. ASSERT_TRUE(str.rfind(cm::String("a"), 1) == 0);
  824. ASSERT_TRUE(str.rfind("ab_", 1, 2) == 0);
  825. return true;
  826. }
  827. static bool testMethod_find_first_of()
  828. {
  829. std::cout << "testMethod_find_first_of()\n";
  830. cm::String str = "abcabc";
  831. ASSERT_TRUE(str.find_first_of("_a") == 0);
  832. ASSERT_TRUE(str.find_first_of("_a", 1) == 3);
  833. {
  834. const char* a = "_a";
  835. ASSERT_TRUE(str.find_first_of(a) == 0);
  836. ASSERT_TRUE(str.find_first_of(a, 1) == 3);
  837. }
  838. ASSERT_TRUE(str.find_first_of('a') == 0);
  839. ASSERT_TRUE(str.find_first_of('a', 1) == 3);
  840. ASSERT_TRUE(str.find_first_of(std::string("_a")) == 0);
  841. ASSERT_TRUE(str.find_first_of(std::string("_a"), 1) == 3);
  842. ASSERT_TRUE(str.find_first_of(cm::string_view("ba_", 1)) == 1);
  843. ASSERT_TRUE(str.find_first_of(cm::string_view("ba_", 1), 2) == 4);
  844. ASSERT_TRUE(str.find_first_of(cm::String("ab")) == 0);
  845. ASSERT_TRUE(str.find_first_of(cm::String("ab"), 2) == 3);
  846. ASSERT_TRUE(str.find_first_of("_ab", 1, 2) == 3);
  847. return true;
  848. }
  849. static bool testMethod_find_first_not_of()
  850. {
  851. std::cout << "testMethod_find_first_not_of()\n";
  852. cm::String str = "abcabc";
  853. ASSERT_TRUE(str.find_first_not_of("_a") == 1);
  854. ASSERT_TRUE(str.find_first_not_of("_a", 2) == 2);
  855. {
  856. const char* a = "_a";
  857. ASSERT_TRUE(str.find_first_not_of(a) == 1);
  858. ASSERT_TRUE(str.find_first_not_of(a, 2) == 2);
  859. }
  860. ASSERT_TRUE(str.find_first_not_of('a') == 1);
  861. ASSERT_TRUE(str.find_first_not_of('a', 2) == 2);
  862. ASSERT_TRUE(str.find_first_not_of(std::string("_a")) == 1);
  863. ASSERT_TRUE(str.find_first_not_of(std::string("_a"), 2) == 2);
  864. ASSERT_TRUE(str.find_first_not_of(cm::string_view("ba_", 1)) == 0);
  865. ASSERT_TRUE(str.find_first_not_of(cm::string_view("ba_", 1), 1) == 2);
  866. ASSERT_TRUE(str.find_first_not_of(cm::String("_a")) == 1);
  867. ASSERT_TRUE(str.find_first_not_of(cm::String("_a"), 2) == 2);
  868. ASSERT_TRUE(str.find_first_not_of("_bca", 1, 3) == 3);
  869. return true;
  870. }
  871. static bool testMethod_find_last_of()
  872. {
  873. std::cout << "testMethod_find_last_of()\n";
  874. cm::String str = "abcabc";
  875. ASSERT_TRUE(str.find_last_of("_a") == 3);
  876. ASSERT_TRUE(str.find_last_of("_a", 1) == 0);
  877. {
  878. const char* a = "_a";
  879. ASSERT_TRUE(str.find_last_of(a) == 3);
  880. ASSERT_TRUE(str.find_last_of(a, 1) == 0);
  881. }
  882. ASSERT_TRUE(str.find_last_of('a') == 3);
  883. ASSERT_TRUE(str.find_last_of('a', 1) == 0);
  884. ASSERT_TRUE(str.find_last_of(std::string("_a")) == 3);
  885. ASSERT_TRUE(str.find_last_of(std::string("_a"), 1) == 0);
  886. ASSERT_TRUE(str.find_last_of(cm::string_view("ba_", 1)) == 4);
  887. ASSERT_TRUE(str.find_last_of(cm::string_view("ba_", 1), 2) == 1);
  888. ASSERT_TRUE(str.find_last_of(cm::String("ab")) == 4);
  889. ASSERT_TRUE(str.find_last_of(cm::String("ab"), 2) == 1);
  890. ASSERT_TRUE(str.find_last_of("_ab", 1, 2) == 0);
  891. return true;
  892. }
  893. static bool testMethod_find_last_not_of()
  894. {
  895. std::cout << "testMethod_find_last_not_of()\n";
  896. cm::String str = "abcabc";
  897. ASSERT_TRUE(str.find_last_not_of("_a") == 5);
  898. ASSERT_TRUE(str.find_last_not_of("_a", 1) == 1);
  899. {
  900. const char* a = "_a";
  901. ASSERT_TRUE(str.find_last_not_of(a) == 5);
  902. ASSERT_TRUE(str.find_last_not_of(a, 1) == 1);
  903. }
  904. ASSERT_TRUE(str.find_last_not_of('a') == 5);
  905. ASSERT_TRUE(str.find_last_not_of('a', 1) == 1);
  906. ASSERT_TRUE(str.find_last_not_of(std::string("_a")) == 5);
  907. ASSERT_TRUE(str.find_last_not_of(std::string("_a"), 1) == 1);
  908. ASSERT_TRUE(str.find_last_not_of(cm::string_view("cb_", 1)) == 4);
  909. ASSERT_TRUE(str.find_last_not_of(cm::string_view("cb_", 1), 2) == 1);
  910. ASSERT_TRUE(str.find_last_not_of(cm::String("_a")) == 5);
  911. ASSERT_TRUE(str.find_last_not_of(cm::String("_a"), 1) == 1);
  912. ASSERT_TRUE(str.find_last_not_of("cb_", 2, 2) == 0);
  913. return true;
  914. }
  915. static bool testAddition()
  916. {
  917. std::cout << "testAddition()\n";
  918. {
  919. ASSERT_TRUE(cm::String("a") + "b" == "ab");
  920. ASSERT_TRUE("ab" == "a" + cm::String("b"));
  921. ASSERT_TRUE("a" + cm::String("b") + "c" == "abc");
  922. ASSERT_TRUE("abc" == "a" + cm::String("b") + "c");
  923. ASSERT_TRUE("a" + (cm::String("b") + "c") + "d" == "abcd");
  924. ASSERT_TRUE("abcd" == "a" + (cm::String("b") + "c") + "d");
  925. }
  926. {
  927. ASSERT_TRUE(cm::String("a"_s) + "b"_s == "ab"_s);
  928. ASSERT_TRUE("ab"_s == "a"_s + cm::String("b"_s));
  929. ASSERT_TRUE("a"_s + cm::String("b"_s) + "c"_s == "abc"_s);
  930. ASSERT_TRUE("abc"_s == "a"_s + cm::String("b"_s) + "c"_s);
  931. ASSERT_TRUE("a"_s + (cm::String("b"_s) + "c"_s) + "d"_s == "abcd"_s);
  932. ASSERT_TRUE("abcd"_s == "a"_s + (cm::String("b"_s) + "c"_s) + "d"_s);
  933. }
  934. {
  935. const char* a = "a";
  936. const char* b = "b";
  937. const char* ab = "ab";
  938. ASSERT_TRUE(cm::String(a) + b == ab);
  939. ASSERT_TRUE(ab == a + cm::String(b));
  940. const char* c = "c";
  941. const char* abc = "abc";
  942. ASSERT_TRUE(a + cm::String(b) + c == abc);
  943. ASSERT_TRUE(abc == a + cm::String(b) + c);
  944. const char* d = "d";
  945. const char* abcd = "abcd";
  946. ASSERT_TRUE(a + (cm::String(b) + c) + d == abcd);
  947. ASSERT_TRUE(abcd == a + (cm::String(b) + c) + d);
  948. }
  949. {
  950. ASSERT_TRUE(cm::String('a') + 'b' == "ab");
  951. ASSERT_TRUE("ab" == 'a' + cm::String('b'));
  952. ASSERT_TRUE('a' + cm::String('b') + 'c' == "abc");
  953. ASSERT_TRUE("abc" == 'a' + cm::String('b') + 'c');
  954. ASSERT_TRUE('a' + (cm::String('b') + 'c') + 'd' == "abcd");
  955. ASSERT_TRUE("abcd" == 'a' + (cm::String('b') + 'c') + 'd');
  956. }
  957. {
  958. std::string a = "a";
  959. std::string b = "b";
  960. std::string ab = "ab";
  961. ASSERT_TRUE(cm::String(a) + b == ab);
  962. ASSERT_TRUE(ab == a + cm::String(b));
  963. std::string c = "c";
  964. std::string abc = "abc";
  965. ASSERT_TRUE(a + cm::String(b) + c == abc);
  966. ASSERT_TRUE(abc == a + cm::String(b) + c);
  967. std::string d = "d";
  968. std::string abcd = "abcd";
  969. ASSERT_TRUE(a + (cm::String(b) + c) + d == abcd);
  970. ASSERT_TRUE(abcd == a + (cm::String(b) + c) + d);
  971. }
  972. {
  973. cm::string_view a("a", 1);
  974. cm::string_view b("b", 1);
  975. cm::string_view ab("ab", 2);
  976. ASSERT_TRUE(cm::String(a) + b == ab);
  977. ASSERT_TRUE(ab == a + cm::String(b));
  978. cm::string_view c("c", 1);
  979. cm::string_view abc("abc", 3);
  980. ASSERT_TRUE(a + cm::String(b) + c == abc);
  981. ASSERT_TRUE(abc == a + cm::String(b) + c);
  982. cm::string_view d("d", 1);
  983. cm::string_view abcd("abcd", 4);
  984. ASSERT_TRUE(a + (cm::String(b) + c) + d == abcd);
  985. ASSERT_TRUE(abcd == a + (cm::String(b) + c) + d);
  986. }
  987. {
  988. cm::String a = "a";
  989. cm::String b = "b";
  990. cm::String ab = "ab";
  991. ASSERT_TRUE(a + b == ab);
  992. ASSERT_TRUE(ab == a + b);
  993. cm::String c = "c";
  994. cm::String abc = "abc";
  995. ASSERT_TRUE(a + cm::String(b) + c == abc);
  996. ASSERT_TRUE(abc == a + cm::String(b) + c);
  997. cm::String d = "d";
  998. cm::String abcd = "abcd";
  999. ASSERT_TRUE(a + (cm::String(b) + c) + d == abcd);
  1000. ASSERT_TRUE(abcd == a + (cm::String(b) + c) + d);
  1001. }
  1002. {
  1003. cm::String str;
  1004. str += "a" + cm::String("b") + 'c';
  1005. ASSERT_TRUE(str == "abc");
  1006. }
  1007. {
  1008. std::string s;
  1009. s += "a" + cm::String("b") + 'c';
  1010. ASSERT_TRUE(s == "abc");
  1011. }
  1012. {
  1013. std::ostringstream ss;
  1014. ss << ("a" + cm::String("b") + 'c');
  1015. ASSERT_TRUE(ss.str() == "abc");
  1016. }
  1017. return true;
  1018. }
  1019. int testString(int /*unused*/, char* /*unused*/ [])
  1020. {
  1021. if (!testConstructDefault()) {
  1022. return 1;
  1023. }
  1024. if (!testConstructFromNullPtr()) {
  1025. return 1;
  1026. }
  1027. if (!testConstructFromCStrNull()) {
  1028. return 1;
  1029. }
  1030. if (!testConstructFromCharArray()) {
  1031. return 1;
  1032. }
  1033. if (!testConstructFromCStr()) {
  1034. return 1;
  1035. }
  1036. if (!testConstructFromStdString()) {
  1037. return 1;
  1038. }
  1039. if (!testConstructFromView()) {
  1040. return 1;
  1041. }
  1042. if (!testConstructFromChar()) {
  1043. return 1;
  1044. }
  1045. if (!testConstructFromInitList()) {
  1046. return 1;
  1047. }
  1048. if (!testConstructFromBuffer()) {
  1049. return 1;
  1050. }
  1051. if (!testConstructFromInputIterator()) {
  1052. return 1;
  1053. }
  1054. if (!testConstructFromN()) {
  1055. return 1;
  1056. }
  1057. if (!testConstructFromStaticStringView()) {
  1058. return 1;
  1059. }
  1060. if (!testConstructCopy()) {
  1061. return 1;
  1062. }
  1063. if (!testConstructMove()) {
  1064. return 1;
  1065. }
  1066. if (!testAssignCopy()) {
  1067. return 1;
  1068. }
  1069. if (!testAssignMove()) {
  1070. return 1;
  1071. }
  1072. if (!testAssignFromChar()) {
  1073. return 1;
  1074. }
  1075. if (!testAssignFromView()) {
  1076. return 1;
  1077. }
  1078. if (!testAssignFromStdString()) {
  1079. return 1;
  1080. }
  1081. if (!testAssignFromCStr()) {
  1082. return 1;
  1083. }
  1084. if (!testAssignFromCharArray()) {
  1085. return 1;
  1086. }
  1087. if (!testAssignFromCStrNull()) {
  1088. return 1;
  1089. }
  1090. if (!testAssignFromNullPtr()) {
  1091. return 1;
  1092. }
  1093. if (!testAssignFromInitList()) {
  1094. return 1;
  1095. }
  1096. if (!testAssignFromStaticStringView()) {
  1097. return 1;
  1098. }
  1099. if (!testOperatorBool()) {
  1100. return 1;
  1101. }
  1102. if (!testOperatorIndex()) {
  1103. return 1;
  1104. }
  1105. if (!testOperatorPlusEqual()) {
  1106. return 1;
  1107. }
  1108. if (!testOperatorCompare()) {
  1109. return 1;
  1110. }
  1111. if (!testOperatorStream()) {
  1112. return 1;
  1113. }
  1114. if (!testOperatorStdStringPlusEqual()) {
  1115. return 1;
  1116. }
  1117. if (!testMethod_borrow()) {
  1118. return 1;
  1119. }
  1120. if (!testMethod_view()) {
  1121. return 1;
  1122. }
  1123. if (!testMethod_empty()) {
  1124. return 1;
  1125. }
  1126. if (!testMethod_length()) {
  1127. return 1;
  1128. }
  1129. if (!testMethod_at()) {
  1130. return 1;
  1131. }
  1132. if (!testMethod_front_back()) {
  1133. return 1;
  1134. }
  1135. if (!testMethod_clear()) {
  1136. return 1;
  1137. }
  1138. if (!testMethod_insert()) {
  1139. return 1;
  1140. }
  1141. if (!testMethod_erase()) {
  1142. return 1;
  1143. }
  1144. if (!testMethod_push_back()) {
  1145. return 1;
  1146. }
  1147. if (!testMethod_pop_back()) {
  1148. return 1;
  1149. }
  1150. if (!testMethod_replace()) {
  1151. return 1;
  1152. }
  1153. if (!testMethod_copy()) {
  1154. return 1;
  1155. }
  1156. if (!testMethod_resize()) {
  1157. return 1;
  1158. }
  1159. if (!testMethod_swap()) {
  1160. return 1;
  1161. }
  1162. if (!testMethodIterators()) {
  1163. return 1;
  1164. }
  1165. if (!testMethod_substr_AtEndBorrowed()) {
  1166. return 1;
  1167. }
  1168. if (!testMethod_substr_AtEndOwned()) {
  1169. return 1;
  1170. }
  1171. if (!testMethod_substr_AtStartBorrowed()) {
  1172. return 1;
  1173. }
  1174. if (!testMethod_substr_AtStartOwned()) {
  1175. return 1;
  1176. }
  1177. if (!testMethod_compare()) {
  1178. return 1;
  1179. }
  1180. if (!testMethod_find()) {
  1181. return 1;
  1182. }
  1183. if (!testMethod_rfind()) {
  1184. return 1;
  1185. }
  1186. if (!testMethod_find_first_of()) {
  1187. return 1;
  1188. }
  1189. if (!testMethod_find_first_not_of()) {
  1190. return 1;
  1191. }
  1192. if (!testMethod_find_last_of()) {
  1193. return 1;
  1194. }
  1195. if (!testMethod_find_last_not_of()) {
  1196. return 1;
  1197. }
  1198. if (!testAddition()) {
  1199. return 1;
  1200. }
  1201. return 0;
  1202. }