testList.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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 <stdexcept>
  4. #include <string>
  5. #include <utility>
  6. #include <vector>
  7. #include <cmext/string_view>
  8. #include "cmList.h"
  9. #include "testCommon.h"
  10. namespace {
  11. void checkResult(bool success)
  12. {
  13. if (!success) {
  14. std::cout << " => failed";
  15. }
  16. std::cout << std::endl;
  17. }
  18. bool testConstructors()
  19. {
  20. std::cout << "testConstructors()";
  21. bool result = true;
  22. {
  23. cmList list;
  24. if (!list.empty() || list != cmList{}) {
  25. result = false;
  26. }
  27. }
  28. {
  29. cmList list{ "aa;bb" };
  30. if (list.size() != 2 || list.to_string() != "aa;bb") {
  31. result = false;
  32. }
  33. }
  34. {
  35. cmList list1{ "aa", "bb" };
  36. cmList list2("aa;bb"_s);
  37. if (list1.size() != 2 || list2.size() != 2 || list1 != list2) {
  38. result = false;
  39. }
  40. if (list1.to_string() != "aa;bb") {
  41. result = false;
  42. }
  43. if (list1.to_string() != list2.to_string()) {
  44. result = false;
  45. }
  46. }
  47. {
  48. std::vector<std::string> v{ "aa", "bb", "cc" };
  49. cmList list(v.begin(), v.end());
  50. if (list.size() != 3 || list.to_string() != "aa;bb;cc") {
  51. result = false;
  52. }
  53. }
  54. {
  55. std::vector<std::string> values{ "aa;bb", "cc", "dd;ee" };
  56. cmList list1(values.begin(), values.end());
  57. cmList list2(values.begin(), values.end(), cmList::ExpandElements::No);
  58. if (list1.size() != 5 || list1.to_string() != "aa;bb;cc;dd;ee") {
  59. result = false;
  60. }
  61. if (list2.size() != 3 || list2.to_string() != "aa;bb;cc;dd;ee") {
  62. result = false;
  63. }
  64. }
  65. {
  66. std::vector<std::string> values{ "aa;bb;;cc", "", "dd;ee" };
  67. cmList list1(values.begin(), values.end(), cmList::ExpandElements::No,
  68. cmList::EmptyElements::No);
  69. cmList list2(values.begin(), values.end(), cmList::ExpandElements::No,
  70. cmList::EmptyElements::Yes);
  71. cmList list3(values.begin(), values.end(), cmList::ExpandElements::Yes,
  72. cmList::EmptyElements::No);
  73. cmList list4(values.begin(), values.end(), cmList::ExpandElements::Yes,
  74. cmList::EmptyElements::Yes);
  75. if (list1.size() != 2 || list1.to_string() != "aa;bb;;cc;dd;ee") {
  76. result = false;
  77. }
  78. if (list2.size() != 3 || list2.to_string() != "aa;bb;;cc;;dd;ee") {
  79. result = false;
  80. }
  81. if (list3.size() != 5 || list3.to_string() != "aa;bb;cc;dd;ee") {
  82. result = false;
  83. }
  84. if (list4.size() != 7 || list4.to_string() != "aa;bb;;cc;;dd;ee") {
  85. result = false;
  86. }
  87. }
  88. {
  89. std::vector<std::string> values{ "aa;bb", "cc", "dd;ee" };
  90. cmList list1(values);
  91. cmList list2(values, cmList::ExpandElements::No);
  92. if (list1.size() != 5 || list1.to_string() != "aa;bb;cc;dd;ee") {
  93. result = false;
  94. }
  95. if (list2.size() != 3 || list2.to_string() != "aa;bb;cc;dd;ee") {
  96. result = false;
  97. }
  98. }
  99. {
  100. std::vector<std::string> values{ "aa", "bb", "cc", "dd", "ee" };
  101. cmList list(std::move(values));
  102. if (list.size() != 5 || list.to_string() != "aa;bb;cc;dd;ee") {
  103. result = false;
  104. }
  105. if (!values.empty()) {
  106. result = false;
  107. }
  108. }
  109. checkResult(result);
  110. return result;
  111. }
  112. bool testAssign()
  113. {
  114. std::cout << "testAssign()";
  115. bool result = true;
  116. {
  117. cmList list1{ "aa", "bb" };
  118. cmList list2{ "cc", "dd" };
  119. list2 = list1;
  120. if (list1.size() != 2 || list2.size() != 2 || list1 != list2) {
  121. result = false;
  122. }
  123. if (list1.to_string() != "aa;bb") {
  124. result = false;
  125. }
  126. if (list1.to_string() != list2.to_string()) {
  127. result = false;
  128. }
  129. }
  130. {
  131. cmList list1{ "aa", "bb" };
  132. cmList list2{ "cc", "dd" };
  133. list2 = std::move(list1);
  134. if (!list1.empty() || list2.size() != 2) {
  135. result = false;
  136. }
  137. if (list2.to_string() != "aa;bb") {
  138. result = false;
  139. }
  140. }
  141. {
  142. std::vector<std::string> v{ "aa", "bb" };
  143. cmList list{ "cc", "dd" };
  144. list = std::move(v);
  145. if (!v.empty() || list.size() != 2) {
  146. result = false;
  147. }
  148. if (list.to_string() != "aa;bb") {
  149. result = false;
  150. }
  151. }
  152. {
  153. cmList list{ "cc", "dd" };
  154. list = "aa;bb"_s;
  155. if (list.size() != 2) {
  156. result = false;
  157. }
  158. if (list.to_string() != "aa;bb") {
  159. result = false;
  160. }
  161. }
  162. checkResult(result);
  163. return result;
  164. }
  165. bool testConversions()
  166. {
  167. std::cout << "testConversions()";
  168. bool result = true;
  169. {
  170. cmList list("a;b;c"_s);
  171. std::string s = list.to_string();
  172. if (s != "a;b;c") {
  173. result = false;
  174. }
  175. }
  176. {
  177. cmList list("a;b;c"_s);
  178. std::vector<std::string> v = list;
  179. if (list.size() != 3 || v.size() != 3) {
  180. result = false;
  181. }
  182. }
  183. {
  184. cmList list("a;b;c"_s);
  185. std::vector<std::string> v = std::move(list);
  186. // Microsoft compiler is not able to handle correctly the move semantics
  187. // so the initial list is not moved, so do not check its size...
  188. if (v.size() != 3) {
  189. result = false;
  190. }
  191. }
  192. {
  193. cmList list("a;b;c"_s);
  194. std::vector<std::string> v;
  195. // compiler is not able to select the cmList conversion operator
  196. // and the std::vector assignment operator using the move semantics
  197. // v = std::move(list);
  198. v = std::move(list.data());
  199. if (!list.empty() || v.size() != 3) {
  200. result = false;
  201. }
  202. }
  203. checkResult(result);
  204. return result;
  205. }
  206. bool testAccess()
  207. {
  208. std::cout << "testAccess()";
  209. bool result = true;
  210. {
  211. cmList list{ "a", "b", "c" };
  212. if (list.get_item(1) != "b") {
  213. result = false;
  214. }
  215. }
  216. {
  217. cmList list{ "a", "b", "c" };
  218. if (list.get_item(-3) != "a") {
  219. result = false;
  220. }
  221. }
  222. {
  223. try {
  224. cmList list{ "a", "b", "c" };
  225. if (list.get_item(4) != "a") {
  226. result = false;
  227. }
  228. } catch (std::out_of_range&) {
  229. }
  230. }
  231. {
  232. try {
  233. cmList list{ "a", "b", "c" };
  234. if (list.get_item(-4) != "a") {
  235. result = false;
  236. }
  237. } catch (std::out_of_range&) {
  238. }
  239. }
  240. {
  241. cmList list{ "a", "b", "c", "d", "e" };
  242. auto sublist = list.sublist(list.begin() + 1, list.begin() + 3);
  243. if (sublist.size() != 2 || sublist != cmList{ "b", "c" }) {
  244. result = false;
  245. }
  246. }
  247. {
  248. cmList list{ "a", "b", "c", "d", "e" };
  249. auto sublist = list.sublist(1, 2);
  250. if (sublist.size() != 2 || sublist != cmList{ "b", "c" }) {
  251. result = false;
  252. }
  253. sublist = list.sublist(1, cmList::npos);
  254. if (sublist.size() != 4 || sublist != cmList{ "b", "c", "d", "e" }) {
  255. result = false;
  256. }
  257. }
  258. {
  259. cmList list{ "a", "b", "c", "d", "e", "f" };
  260. auto sublist = list.get_items({ 1, 3, 5 });
  261. if (sublist.size() != 3 || sublist != cmList{ "b", "d", "f" }) {
  262. result = false;
  263. }
  264. }
  265. {
  266. cmList list{ "a", "b", "c", "d", "e", "f" };
  267. auto sublist = list.get_items({ 1, -3, 5, -3 });
  268. if (sublist.size() != 4 || sublist != cmList{ "b", "d", "f", "d" }) {
  269. result = false;
  270. }
  271. }
  272. {
  273. cmList list{ "a", "b", "c", "d", "e", "f" };
  274. try {
  275. if (list.get_items({ 1, -3, 5, -3, 10 }).size() != 5) {
  276. result = false;
  277. }
  278. } catch (std::out_of_range&) {
  279. }
  280. }
  281. {
  282. cmList list{ "a", "b", "c", "d", "e", "f" };
  283. if (list.find("b") != 1) {
  284. result = false;
  285. }
  286. if (list.find("x") != cmList::npos) {
  287. result = false;
  288. }
  289. }
  290. checkResult(result);
  291. return result;
  292. }
  293. bool testModifiers()
  294. {
  295. std::cout << "testModifiers()";
  296. bool result = true;
  297. {
  298. cmList list{ "1;2;3;4;5" };
  299. auto it = list.insert(list.begin() + 2, "6;7;8"_s);
  300. if (list.size() != 8 || list.to_string() != "1;2;6;7;8;3;4;5") {
  301. result = false;
  302. }
  303. if (*it != "6") {
  304. result = false;
  305. }
  306. }
  307. {
  308. cmList list{ "1;2;3;4;5" };
  309. auto it =
  310. list.insert(list.begin() + 2, "6;7;8"_s, cmList::ExpandElements::No);
  311. if (list.size() != 6 || list.to_string() != "1;2;6;7;8;3;4;5") {
  312. result = false;
  313. }
  314. if (*it != "6;7;8") {
  315. result = false;
  316. }
  317. }
  318. {
  319. cmList list{ "1;2;3;4;5" };
  320. cmList v{ "6", "7", "8" };
  321. auto it = list.insert(list.begin() + 2, v);
  322. if (list.size() != 8 || list.to_string() != "1;2;6;7;8;3;4;5") {
  323. result = false;
  324. }
  325. if (*it != "6") {
  326. result = false;
  327. }
  328. }
  329. {
  330. cmList list{ "1;2;3;4;5" };
  331. cmList v{ "6", "7", "8" };
  332. auto it = list.insert(list.begin() + 2, std::move(v));
  333. if (list.size() != 8 || list.to_string() != "1;2;6;7;8;3;4;5") {
  334. result = false;
  335. }
  336. if (*it != "6") {
  337. result = false;
  338. }
  339. if (!v.empty()) {
  340. result = false;
  341. }
  342. }
  343. {
  344. cmList list{ "1;2;3;4;5" };
  345. std::vector<std::string> v{ "6", "7", "8" };
  346. auto it = list.insert(list.begin() + 2, v);
  347. if (list.size() != 8 || list.to_string() != "1;2;6;7;8;3;4;5") {
  348. result = false;
  349. }
  350. if (*it != "6") {
  351. result = false;
  352. }
  353. }
  354. {
  355. cmList list{ "1;2;3;4;5" };
  356. std::vector<std::string> v{ "6;7", "8" };
  357. auto it = list.insert(list.begin() + 2, v);
  358. if (list.size() != 8 || list.to_string() != "1;2;6;7;8;3;4;5") {
  359. result = false;
  360. }
  361. if (*it != "6") {
  362. result = false;
  363. }
  364. }
  365. {
  366. cmList list{ "1;2;3;4;5" };
  367. std::vector<std::string> v{ "6;7", "8" };
  368. auto it = list.insert(list.begin() + 2, v, cmList::ExpandElements::No);
  369. if (list.size() != 7 || list.to_string() != "1;2;6;7;8;3;4;5") {
  370. result = false;
  371. }
  372. if (*it != "6;7") {
  373. result = false;
  374. }
  375. }
  376. {
  377. cmList list{ "1;2;3;4;5" };
  378. std::vector<std::string> v{ "6;;7", "8" };
  379. auto it = list.insert(list.begin() + 2, v);
  380. if (list.size() != 8 || list.to_string() != "1;2;6;7;8;3;4;5") {
  381. result = false;
  382. }
  383. if (*it != "6") {
  384. result = false;
  385. }
  386. }
  387. {
  388. cmList list{ "1;2;3;4;5" };
  389. std::vector<std::string> v{ "6;;7", "8" };
  390. auto it = list.insert(list.begin() + 2, v, cmList::EmptyElements::Yes);
  391. if (list.size() != 9 || list.to_string() != "1;2;6;;7;8;3;4;5") {
  392. result = false;
  393. }
  394. if (*it != "6") {
  395. result = false;
  396. }
  397. }
  398. {
  399. cmList list{ "1;2;3;4;5" };
  400. std::vector<std::string> v{ "6", "7", "8" };
  401. auto it = list.insert(list.begin() + 2, std::move(v));
  402. if (list.size() != 8 || list.to_string() != "1;2;6;7;8;3;4;5") {
  403. result = false;
  404. }
  405. if (*it != "6") {
  406. result = false;
  407. }
  408. if (!v.empty()) {
  409. result = false;
  410. }
  411. }
  412. checkResult(result);
  413. return result;
  414. }
  415. bool testRemoveItems()
  416. {
  417. std::cout << "testRemoveItems()";
  418. bool result = true;
  419. {
  420. cmList list("a;b;c;d;e;f;g;h"_s);
  421. list.remove_items({ 1, 3, 5 });
  422. if (list.size() != 5 || list.to_string() != "a;c;e;g;h") {
  423. result = false;
  424. }
  425. }
  426. {
  427. cmList list("a;b;c;b;a;d;e;f"_s);
  428. list.remove_items({ "a", "b", "h" });
  429. if (list.size() != 4 || list.to_string() != "c;d;e;f") {
  430. result = false;
  431. }
  432. }
  433. {
  434. cmList list("a;b;c;d;e;f;g;h"_s);
  435. std::vector<cmList::index_type> remove{ 1, 3, 5 };
  436. list.remove_items(remove.begin(), remove.end());
  437. if (list.size() != 5 || list.to_string() != "a;c;e;g;h") {
  438. result = false;
  439. }
  440. }
  441. {
  442. cmList list("a;b;c;b;a;d;e;f"_s);
  443. std::vector<std::string> remove{ "b", "a", "h" };
  444. list.remove_items(remove.begin(), remove.end());
  445. if (list.size() != 4 || list.to_string() != "c;d;e;f") {
  446. result = false;
  447. }
  448. }
  449. checkResult(result);
  450. return result;
  451. }
  452. bool testRemoveDuplicates()
  453. {
  454. std::cout << "testRemoveDuplicates()";
  455. bool result = true;
  456. {
  457. cmList list("b;c;b;a;a;c;b;a;c;b"_s);
  458. list.remove_duplicates();
  459. if (list.size() != 3 || list.to_string() != "b;c;a") {
  460. result = false;
  461. }
  462. }
  463. checkResult(result);
  464. return result;
  465. }
  466. bool testFilter()
  467. {
  468. std::cout << "testFilter()";
  469. bool result = true;
  470. {
  471. cmList list{ "AA", "Aa", "aA" };
  472. list.filter("^A", cmList::FilterMode::INCLUDE);
  473. if (list.size() != 2 || list.to_string() != "AA;Aa") {
  474. result = false;
  475. }
  476. }
  477. {
  478. cmList list{ "AA", "Aa", "aA" };
  479. list.filter("^A", cmList::FilterMode::EXCLUDE);
  480. if (list.size() != 1 || list.to_string() != "aA") {
  481. result = false;
  482. }
  483. }
  484. {
  485. cmList list{ "AA", "Aa", "aA" };
  486. try {
  487. list.filter("^(A", cmList::FilterMode::EXCLUDE);
  488. if (list.size() != 1) {
  489. result = false;
  490. }
  491. } catch (std::invalid_argument const&) {
  492. }
  493. }
  494. checkResult(result);
  495. return result;
  496. }
  497. bool testReverse()
  498. {
  499. std::cout << "testReverse()";
  500. bool result = true;
  501. {
  502. cmList list{ "a", "b", "c" };
  503. if (list.reverse().to_string() != "c;b;a") {
  504. result = false;
  505. }
  506. }
  507. checkResult(result);
  508. return result;
  509. }
  510. bool testSort()
  511. {
  512. std::cout << "testSort()";
  513. bool result = true;
  514. using SortConfiguration = cmList::SortConfiguration;
  515. {
  516. cmList list{ "A", "D", "C", "B", "A" };
  517. list.sort();
  518. if (list.to_string() != "A;A;B;C;D") {
  519. result = false;
  520. }
  521. list.sort({ SortConfiguration::OrderMode::DESCENDING,
  522. SortConfiguration::CompareMethod::DEFAULT,
  523. SortConfiguration::CaseSensitivity::DEFAULT });
  524. if (list.to_string() != "D;C;B;A;A") {
  525. result = false;
  526. }
  527. }
  528. {
  529. SortConfiguration sortCfg;
  530. cmList list{ "1.0", "1.1", "2.5", "10.2" };
  531. list.sort(sortCfg);
  532. if (list.to_string() != "1.0;1.1;10.2;2.5") {
  533. result = false;
  534. }
  535. sortCfg.Compare = SortConfiguration::CompareMethod::NATURAL;
  536. list.sort(sortCfg);
  537. if (list.to_string() != "1.0;1.1;2.5;10.2") {
  538. result = false;
  539. }
  540. sortCfg.Order = SortConfiguration::OrderMode::DESCENDING;
  541. list.sort(sortCfg);
  542. if (list.to_string() != "10.2;2.5;1.1;1.0") {
  543. result = false;
  544. }
  545. }
  546. {
  547. SortConfiguration sortCfg;
  548. cmList list{ "/zz/bb.cc", "/xx/yy/dd.cc", "/aa/cc.aa" };
  549. list.sort(sortCfg);
  550. if (list.to_string() != "/aa/cc.aa;/xx/yy/dd.cc;/zz/bb.cc") {
  551. result = false;
  552. }
  553. sortCfg.Compare = SortConfiguration::CompareMethod::FILE_BASENAME;
  554. if (list.sort(sortCfg).to_string() != "/zz/bb.cc;/aa/cc.aa;/xx/yy/dd.cc") {
  555. result = false;
  556. }
  557. }
  558. {
  559. SortConfiguration sortCfg;
  560. cmList list{ "c/B", "a/c", "B/a" };
  561. if (list.sort().to_string() != "B/a;a/c;c/B") {
  562. result = false;
  563. }
  564. sortCfg.Case = SortConfiguration::CaseSensitivity::INSENSITIVE;
  565. if (list.sort(sortCfg).to_string() != "a/c;B/a;c/B") {
  566. result = false;
  567. }
  568. }
  569. checkResult(result);
  570. return result;
  571. }
  572. bool testTransform()
  573. {
  574. std::cout << "testTransform()";
  575. bool result = true;
  576. using AT = cmList::TransformSelector::AT;
  577. using FOR = cmList::TransformSelector::FOR;
  578. using REGEX = cmList::TransformSelector::REGEX;
  579. {
  580. cmList list({ "AA", "BB", "CC", "DD", "EE" });
  581. list.transform(cmList::TransformAction::APPEND, "-X");
  582. if (list.to_string() != "AA-X;BB-X;CC-X;DD-X;EE-X") {
  583. result = false;
  584. }
  585. }
  586. {
  587. cmList list({ "AA", "BB", "CC", "DD", "EE" });
  588. list.transform(cmList::TransformAction::PREPEND, "X-");
  589. if (list.to_string() != "X-AA;X-BB;X-CC;X-DD;X-EE") {
  590. result = false;
  591. }
  592. }
  593. {
  594. cmList list({ "AA", "BB", "CC", "DD", "EE" });
  595. list.transform(cmList::TransformAction::TOLOWER);
  596. if (list.to_string() != "aa;bb;cc;dd;ee") {
  597. result = false;
  598. }
  599. }
  600. {
  601. cmList list({ "aa", "bb", "cc", "dd", "ee" });
  602. list.transform(cmList::TransformAction::TOUPPER);
  603. if (list.to_string() != "AA;BB;CC;DD;EE") {
  604. result = false;
  605. }
  606. }
  607. {
  608. cmList list({ " AA", "BB ", " CC ", "DD", "EE" });
  609. list.transform(cmList::TransformAction::STRIP);
  610. if (list.to_string() != "AA;BB;CC;DD;EE") {
  611. result = false;
  612. }
  613. }
  614. {
  615. cmList list({ "$<CONFIG>AA", "BB$<OR>", "C$<AND>C", "$<OR>DD$<AND>",
  616. "$<>E$<>E$<>" });
  617. list.transform(cmList::TransformAction::GENEX_STRIP);
  618. if (list.to_string() != "AA;BB;CC;DD;EE") {
  619. result = false;
  620. }
  621. }
  622. {
  623. cmList list({ "ABC", "BBCB", "BCCCBC", "BCBCDD", "EBCBCEBC" });
  624. list.transform(cmList::TransformAction::REPLACE, "^BC|BC$", "X");
  625. if (list.to_string() != "AX;BBCB;XCCX;XBCDD;EBCBCEX") {
  626. result = false;
  627. }
  628. }
  629. {
  630. auto atSelector = cmList::TransformSelector::New<AT>({ 1, 2, 4 });
  631. cmList list({ "AA", "BB", "CC", "DD", "EE" });
  632. list.transform(cmList::TransformAction::TOLOWER, std::move(atSelector));
  633. if (list.to_string() != "AA;bb;cc;DD;ee") {
  634. result = false;
  635. }
  636. }
  637. {
  638. auto atSelector = cmList::TransformSelector::New<AT>({ 1, 2, -1 });
  639. cmList list({ "AA", "BB", "CC", "DD", "EE" });
  640. list.transform(cmList::TransformAction::TOLOWER, std::move(atSelector));
  641. if (list.to_string() != "AA;bb;cc;DD;ee") {
  642. result = false;
  643. }
  644. }
  645. {
  646. auto forSelector = cmList::TransformSelector::New<FOR>({ 1, 3 });
  647. cmList list({ "AA", "BB", "CC", "DD", "EE" });
  648. list.transform(cmList::TransformAction::TOLOWER, std::move(forSelector));
  649. if (list.to_string() != "AA;bb;cc;dd;EE") {
  650. result = false;
  651. }
  652. }
  653. {
  654. auto forSelector = cmList::TransformSelector::New<FOR>({ 0, 4, 2 });
  655. cmList list({ "AA", "BB", "CC", "DD", "EE" });
  656. list.transform(cmList::TransformAction::TOLOWER, std::move(forSelector));
  657. if (list.to_string() != "aa;BB;cc;DD;ee") {
  658. result = false;
  659. }
  660. }
  661. {
  662. auto regexSelector = cmList::TransformSelector::New<REGEX>("^(A|D|E)");
  663. cmList list({ "AA", "BB", "CC", "DD", "EE" });
  664. list.transform(cmList::TransformAction::TOLOWER, std::move(regexSelector));
  665. if (list.to_string() != "aa;BB;CC;dd;ee") {
  666. result = false;
  667. }
  668. }
  669. checkResult(result);
  670. return result;
  671. }
  672. bool testStaticModifiers()
  673. {
  674. std::cout << "testStaticModifiers()";
  675. bool result = true;
  676. {
  677. std::vector<std::string> v{ "a", "b", "c" };
  678. cmList::assign(v, "d;e"_s);
  679. if (v.size() != 2 || v[0] != "d" || v[1] != "e") {
  680. result = false;
  681. }
  682. }
  683. {
  684. std::vector<std::string> v{ "a", "b", "c" };
  685. cmList::append(v, "d;;e"_s);
  686. if (v.size() != 5 || v[3] != "d" || v[4] != "e") {
  687. result = false;
  688. }
  689. }
  690. {
  691. std::vector<std::string> v{ "a", "b", "c" };
  692. cmList::append(v, "d;;e"_s, cmList::EmptyElements::Yes);
  693. if (v.size() != 6 || v[3] != "d" || !v[4].empty() || v[5] != "e") {
  694. result = false;
  695. }
  696. }
  697. {
  698. std::vector<std::string> v{ "a", "b", "c" };
  699. cmList::prepend(v, "d;e"_s);
  700. if (v.size() != 5 || v[0] != "d" || v[1] != "e") {
  701. result = false;
  702. }
  703. }
  704. {
  705. std::vector<std::string> v{ "a", "b", "c" };
  706. cmList::prepend(v, "d;;e"_s, cmList::EmptyElements::Yes);
  707. if (v.size() != 6 || v[0] != "d" || !v[1].empty() || v[2] != "e") {
  708. result = false;
  709. }
  710. }
  711. {
  712. std::string list{ "a;b;c" };
  713. cmList::append(list, "d;e"_s);
  714. if (list != "a;b;c;d;e") {
  715. result = false;
  716. }
  717. }
  718. {
  719. std::string list;
  720. cmList::append(list, "d;e"_s);
  721. if (list != "d;e") {
  722. result = false;
  723. }
  724. }
  725. {
  726. std::string list{ "a;b;c" };
  727. cmList::append(list, ""_s);
  728. if (list != "a;b;c;") {
  729. result = false;
  730. }
  731. }
  732. {
  733. std::string list{ "a;b;c" };
  734. std::vector<std::string> v{ "d", "e" };
  735. cmList::append(list, v.begin(), v.end());
  736. if (list != "a;b;c;d;e") {
  737. result = false;
  738. }
  739. }
  740. {
  741. std::string list{ "a;b;c" };
  742. std::vector<std::string> v;
  743. cmList::append(list, v.begin(), v.end());
  744. if (list != "a;b;c") {
  745. result = false;
  746. }
  747. }
  748. {
  749. std::string list;
  750. std::vector<std::string> v{ "d", "e" };
  751. cmList::append(list, v.begin(), v.end());
  752. if (list != "d;e") {
  753. result = false;
  754. }
  755. }
  756. {
  757. std::string list{ "a;b;c" };
  758. cmList::prepend(list, "d;e"_s);
  759. if (list != "d;e;a;b;c") {
  760. result = false;
  761. }
  762. }
  763. {
  764. std::string list;
  765. cmList::prepend(list, "d;e"_s);
  766. if (list != "d;e") {
  767. result = false;
  768. }
  769. }
  770. {
  771. std::string list{ "a;b;c" };
  772. cmList::prepend(list, ""_s);
  773. if (list != ";a;b;c") {
  774. result = false;
  775. }
  776. }
  777. {
  778. std::string list{ "a;b;c" };
  779. std::vector<std::string> v{ "d", "e" };
  780. cmList::prepend(list, v.begin(), v.end());
  781. if (list != "d;e;a;b;c") {
  782. result = false;
  783. }
  784. }
  785. {
  786. std::string list{ "a;b;c" };
  787. std::vector<std::string> v;
  788. cmList::prepend(list, v.begin(), v.end());
  789. if (list != "a;b;c") {
  790. result = false;
  791. }
  792. }
  793. {
  794. std::string list;
  795. std::vector<std::string> v{ "d", "e" };
  796. cmList::prepend(list, v.begin(), v.end());
  797. if (list != "d;e") {
  798. result = false;
  799. }
  800. }
  801. checkResult(result);
  802. return result;
  803. }
  804. }
  805. int testList(int /*unused*/, char* /*unused*/[])
  806. {
  807. return runTests({ testConstructors, testAssign, testConversions, testAccess,
  808. testModifiers, testRemoveItems, testRemoveDuplicates,
  809. testFilter, testReverse, testSort, testTransform,
  810. testStaticModifiers },
  811. false);
  812. }