summaryrefslogtreecommitdiff
path: root/src/utils/stringutils_unittest.cc
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-27 23:42:54 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-27 23:42:54 +0300
commiteb5128aa6ce4a33aa9021b51231d0934294c7caa (patch)
tree26db4336d595812e0fdcedf18e97ccc3c091b4ab /src/utils/stringutils_unittest.cc
parent555be6547d24f09e5c2a901673237276fa4ae0bd (diff)
downloadmv-eb5128aa6ce4a33aa9021b51231d0934294c7caa.tar.gz
mv-eb5128aa6ce4a33aa9021b51231d0934294c7caa.tar.bz2
mv-eb5128aa6ce4a33aa9021b51231d0934294c7caa.tar.xz
mv-eb5128aa6ce4a33aa9021b51231d0934294c7caa.zip
Add string function for sanitization strings.
Diffstat (limited to 'src/utils/stringutils_unittest.cc')
-rw-r--r--src/utils/stringutils_unittest.cc127
1 files changed, 127 insertions, 0 deletions
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index 60588571a..82a15fdff 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -545,6 +545,50 @@ TEST_CASE("stringuntils replaceAll 1")
REQUIRE("this is test line" == replaceAll(str1, str2, str3));
}
+TEST_CASE("stringuntils replaceRecursiveAll 1")
+{
+ std::string str;
+ str = "";
+ replaceRecursiveAll(str, "line", '.');
+ REQUIRE(str == "");
+ str = "test line";
+ replaceRecursiveAll(str, "line", '.');
+ REQUIRE(str == "test .");
+ str = "11112222";
+ replaceRecursiveAll(str, "11", '1');
+ REQUIRE(str == "12222");
+ str = "122221";
+ replaceRecursiveAll(str, "11", '1');
+ REQUIRE(str == "122221");
+ str = "1222211";
+ replaceRecursiveAll(str, "11", '1');
+ REQUIRE(str == "122221");
+ str = "11112222";
+ replaceRecursiveAll(str, "112", '1');
+ REQUIRE(str == "111222");
+ str = "111122224";
+ replaceRecursiveAll(str, "112", '1');
+ REQUIRE(str == "1112224");
+ str = "3111122224";
+ replaceRecursiveAll(str, "112", '1');
+ REQUIRE(str == "31112224");
+ str = "121212";
+ replaceRecursiveAll(str, "12", '1');
+ REQUIRE(str == "111");
+ str = "1121212";
+ replaceRecursiveAll(str, "12", '1');
+ REQUIRE(str == "1111");
+ str = "11212122";
+ replaceRecursiveAll(str, "12", '1');
+ REQUIRE(str == "1111");
+ str = "112121222";
+ replaceRecursiveAll(str, "12", '1');
+ REQUIRE(str == "1111");
+ str = "112211221122";
+ replaceRecursiveAll(str, "12", '1');
+ REQUIRE(str == "111111");
+}
+
TEST_CASE("stringuntils getBoolFromString 1")
{
REQUIRE(getBoolFromString("true"));
@@ -1209,6 +1253,89 @@ TEST_CASE("stringuntils escapeString")
REQUIRE(escapeString("12\\3") == "\"12\\3\"");
}
+TEST_CASE("stringuntils sanitizePath")
+{
+ std::string path;
+ path = "";
+ sanitizePath(path);
+ REQUIRE(path == "");
+ path = "/";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "/\\";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "\\/";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "//";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "///";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "//\\/";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "///\\";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "\\";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "\\\\";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "\\/\\";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "\\\\/";
+ sanitizePath(path);
+ REQUIRE(path == "/");
+ path = "test";
+ sanitizePath(path);
+ REQUIRE(path == "test");
+ path = "./test";
+ sanitizePath(path);
+ REQUIRE(path == "./test");
+ path = "test line";
+ sanitizePath(path);
+ REQUIRE(path == "test line");
+ path = "dir/test";
+ sanitizePath(path);
+ REQUIRE(path == "dir/test");
+ path = "/dir/test";
+ sanitizePath(path);
+ REQUIRE(path == "/dir/test");
+ path = "dir//test";
+ sanitizePath(path);
+ REQUIRE(path == "dir/test");
+ path = "dir///test";
+ sanitizePath(path);
+ REQUIRE(path == "dir/test");
+ path = "dir///\\test";
+ sanitizePath(path);
+ REQUIRE(path == "dir/test");
+ path = "dir/\\//test";
+ sanitizePath(path);
+ REQUIRE(path == "dir/test");
+ path = "dir\\test";
+ sanitizePath(path);
+ REQUIRE(path == "dir/test");
+ path = "dir/test/";
+ sanitizePath(path);
+ REQUIRE(path == "dir/test/");
+ path = "dir/test\\";
+ sanitizePath(path);
+ REQUIRE(path == "dir/test/");
+ path = "/very\\long/dir\\with\\sepa/ra/tors";
+ sanitizePath(path);
+ REQUIRE(path == "/very/long/dir/with/sepa/ra/tors");
+ path = "/very\\long/dir\\\\with\\sepa//ra/tors";
+ sanitizePath(path);
+ REQUIRE(path == "/very/long/dir/with/sepa/ra/tors");
+}
+
TEST_CASE("stringuntils secureChatCommand")
{
std::string str;