MCPcopy Create free account
hub / github.com/Kitware/CMake / testStringAlgorithms

Function testStringAlgorithms

Tests/CMakeLib/testStringAlgorithms.cxx:17–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include "cmStringAlgorithms.h"
16
17int testStringAlgorithms(int /*unused*/, char* /*unused*/[])
18{
19 int failed = 0;
20
21 auto assert_ok = [&failed](bool test, cm::string_view title) {
22 if (test) {
23 std::cout << "Passed: " << title << "\n";
24 } else {
25 std::cout << "Failed: " << title << "\n";
26 ++failed;
27 }
28 };
29
30 auto assert_string = [&failed](cm::string_view generated,
31 cm::string_view expected,
32 cm::string_view title) {
33 if (generated == expected) {
34 std::cout << "Passed: " << title << "\n";
35 } else {
36 std::cout << "Failed: " << title << "\n";
37 std::cout << "Expected: " << expected << "\n";
38 std::cout << "Got: " << generated << "\n";
39 ++failed;
40 }
41 };
42
43 // ----------------------------------------------------------------------
44 // Test cmTrimWhitespace
45 {
46 std::string base = "base";
47 std::string spaces = " \f\f\n\n\r\r\t\t\v\v";
48 assert_string(cmTrimWhitespace(spaces + base), base,
49 "cmTrimWhitespace front");
50 assert_string(cmTrimWhitespace(base + spaces), base,
51 "cmTrimWhitespace back");
52 assert_string(cmTrimWhitespace(spaces + base + spaces), base,
53 "cmTrimWhitespace front and back");
54 }
55
56 // ----------------------------------------------------------------------
57 // Test cmRemoveQuotes
58 {
59 auto test = [&assert_string](cm::string_view source,
60 cm::string_view expected,
61 cm::string_view title) {
62 assert_string(cmRemoveQuotes(source), expected, title);
63 };
64
65 test("", "", "cmRemoveQuotes empty");
66 test("\"", "\"", "cmRemoveQuotes single quote");
67 test("\"\"", "", "cmRemoveQuotes double quote");
68 test("\"a", "\"a", "cmRemoveQuotes quote char");
69 test("\"ab", "\"ab", "cmRemoveQuotes quote char char");
70 test("a\"", "a\"", "cmRemoveQuotes char quote");
71 test("ab\"", "ab\"", "cmRemoveQuotes char char quote");
72 test("a", "a", "cmRemoveQuotes single char");
73 test("ab", "ab", "cmRemoveQuotes two chars");
74 test("abc", "abc", "cmRemoveQuotes three chars");

Callers

nothing calls this directly

Calls 15

cmTrimWhitespaceFunction · 0.85
cmRemoveQuotesFunction · 0.85
cmEscapeQuotesFunction · 0.85
cmTokenizeFunction · 0.85
cmTokenizedViewFunction · 0.85
moveFunction · 0.85
cmWrapFunction · 0.85
cmHasPrefixFunction · 0.85
cmHasLiteralPrefixFunction · 0.85
cmHasSuffixFunction · 0.85
cmHasLiteralSuffixFunction · 0.85
cmStrToLongFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…