summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/testSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-04-10 11:56:14 (GMT)
committerBrad King <brad.king@kitware.com>2020-04-10 11:56:14 (GMT)
commit0b495b6ca9bfb6c2c3da2ecb7c4301a89fe93692 (patch)
tree602f80814168e4accace5430524eb42825ed7c02 /Source/kwsys/testSystemTools.cxx
parent41c0adde026c9d49a69ee2d975fb46757fd9a4b5 (diff)
parent4ab6fcd676549814e9b4a029b6eac1f13ea8b6e6 (diff)
downloadCMake-0b495b6ca9bfb6c2c3da2ecb7c4301a89fe93692.zip
CMake-0b495b6ca9bfb6c2c3da2ecb7c4301a89fe93692.tar.gz
CMake-0b495b6ca9bfb6c2c3da2ecb7c4301a89fe93692.tar.bz2
Merge branch 'upstream-KWSys' into update-kwsys
# By KWSys Upstream * upstream-KWSys: KWSys 2020-04-10 (b62956f5)
Diffstat (limited to 'Source/kwsys/testSystemTools.cxx')
-rw-r--r--Source/kwsys/testSystemTools.cxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index aa38aec..8909b49 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/testSystemTools.cxx
@@ -1120,6 +1120,42 @@ static bool CheckURLParsing()
return ret;
}
+static bool CheckSplitString()
+{
+ bool ret = true;
+
+ auto check_split = [](std::string const& input,
+ std::initializer_list<const char*> expected) -> bool {
+ auto const components = kwsys::SystemTools::SplitString(input, '/');
+ if (components.size() != expected.size()) {
+ std::cerr << "Incorrect split count for " << input << ": "
+ << components.size() << std::endl;
+ return false;
+ }
+ size_t i = 0;
+ for (auto& part : expected) {
+ if (components[i] != part) {
+ std::cerr << "Incorrect split component " << i << " for " << input
+ << ": " << components[i] << std::endl;
+ return false;
+ }
+ ++i;
+ }
+ return true;
+ };
+
+ // No separators
+ ret &= check_split("nosep", { "nosep" });
+ // Simple
+ ret &= check_split("first/second", { "first", "second" });
+ // Separator at beginning
+ ret &= check_split("/starts/sep", { "", "starts", "sep" });
+ // Separator at end
+ ret &= check_split("ends/sep/", { "ends", "sep", "" });
+
+ return ret;
+}
+
int testSystemTools(int, char* [])
{
bool res = true;
@@ -1169,5 +1205,7 @@ int testSystemTools(int, char* [])
res &= CheckURLParsing();
+ res &= CheckSplitString();
+
return res ? 0 : 1;
}