summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-17 00:41:16 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-17 00:41:16 +0300
commitcaf2e3c4fb749561c37eaff324de86a9edf83808 (patch)
treec20d8b2a5863c0366f0804fe7a4361ccfc16a927 /src/utils
parent0ad55dae62f1c8295517bf87844368575a813d57 (diff)
downloadmv-caf2e3c4fb749561c37eaff324de86a9edf83808.tar.gz
mv-caf2e3c4fb749561c37eaff324de86a9edf83808.tar.bz2
mv-caf2e3c4fb749561c37eaff324de86a9edf83808.tar.xz
mv-caf2e3c4fb749561c37eaff324de86a9edf83808.zip
Add unit tests for links replace function.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/stringutils_unittest.cc184
1 files changed, 184 insertions, 0 deletions
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index 74427f163..e2db8eed1 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -22,6 +22,10 @@
#include "utils/stringutils.h"
+#include "resources/iteminfo.h"
+
+#include "resources/db/itemdb.h"
+
#include <list>
#include <string>
#include <vector>
@@ -588,3 +592,183 @@ TEST_CASE("stringuntils isDigit")
REQUIRE_FALSE(isDigit("1.23"));
REQUIRE_FALSE(isDigit("12-34"));
}
+
+TEST_CASE("stringuntils replaceItemLinks")
+{
+ ItemDB::NamedItemInfos &infos = ItemDB::getNamedItemInfosTest();
+ ItemInfo *info = new ItemInfo;
+ info->setId(123456);
+ info->setName("test name 1");
+ infos["test name 1"] = info;
+
+ info = new ItemInfo;
+ info->setId(123);
+ info->setName("test name 2");
+ infos["test name 2"] = info;
+
+ std::string str;
+
+ SECTION("empty")
+ {
+ str = "test line";
+ replaceItemLinks(str);
+ REQUIRE(str == "test line");
+
+ str = "";
+ replaceItemLinks(str);
+ REQUIRE(str == "");
+
+ str = "[]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[]");
+
+ str = "[qqq]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[qqq]");
+ }
+
+ SECTION("simple")
+ {
+ str = "[test name 1]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[@@123456|test name 1@@]");
+
+ str = "text1 [test name 1] text2";
+ replaceItemLinks(str);
+ REQUIRE(str == "text1 [@@123456|test name 1@@] text2");
+
+ str = "[test name 1][test name 1]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[@@123456|test name 1@@][@@123456|test name 1@@]");
+
+ str = "[test name 1] [test name 1]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[@@123456|test name 1@@] [@@123456|test name 1@@]");
+
+ str = "test1 [test name 1]test2[test name 1] test3";
+ replaceItemLinks(str);
+ REQUIRE(str == "test1 [@@123456|test name 1@@]test2"
+ "[@@123456|test name 1@@] test3");
+
+ str = "[test name 1] [no link]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[@@123456|test name 1@@] [no link]");
+ }
+
+ SECTION("broken")
+ {
+ str = "[";
+ replaceItemLinks(str);
+ REQUIRE(str == "[");
+
+ str = "]";
+ replaceItemLinks(str);
+ REQUIRE(str == "]");
+
+ str = "][";
+ replaceItemLinks(str);
+ REQUIRE(str == "][");
+
+ str = "]]";
+ replaceItemLinks(str);
+ REQUIRE(str == "]]");
+
+ str = "]t";
+ replaceItemLinks(str);
+ REQUIRE(str == "]t");
+
+ str = "t[";
+ replaceItemLinks(str);
+ REQUIRE(str == "t[");
+
+ str = "t]";
+ replaceItemLinks(str);
+ REQUIRE(str == "t]");
+
+ str = "[[[";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[[");
+
+ str = "[[]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[]");
+
+ str = "[[t";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[t");
+
+ str = "[][";
+ replaceItemLinks(str);
+ REQUIRE(str == "[][");
+
+ str = "[]]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[]]");
+
+ str = "[]t";
+ replaceItemLinks(str);
+ REQUIRE(str == "[]t");
+
+ str = "[t[";
+ replaceItemLinks(str);
+ REQUIRE(str == "[t[");
+
+ str = "[t]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[t]");
+
+ str = "t[[";
+ replaceItemLinks(str);
+ REQUIRE(str == "t[[");
+
+ str = "t[]";
+ replaceItemLinks(str);
+ REQUIRE(str == "t[]");
+
+ str = "t[[";
+ replaceItemLinks(str);
+ REQUIRE(str == "t[[");
+
+ str = "]]]";
+ replaceItemLinks(str);
+ REQUIRE(str == "]]]");
+ }
+
+ SECTION("broken2")
+ {
+ str = "[][]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[][]");
+
+ str = "[[]]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[]]");
+
+ str = "][[]";
+ replaceItemLinks(str);
+ REQUIRE(str == "][[]");
+ }
+
+ SECTION("broken3")
+ {
+ str = "[[test name 1]]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[@@123456|test name 1@@]]");
+
+ str = "[[test name 1]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[@@123456|test name 1@@]");
+
+ str = "[[test] name 1]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[test] name 1]");
+
+ str = "[[test name 1]test name 1]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[@@123456|test name 1@@]test name 1]");
+
+ str = "[[test name 1[]test name 1]";
+ replaceItemLinks(str);
+ REQUIRE(str == "[[test name 1[]test name 1]");
+ }
+}