LeechCraft 0.6.70-19424-g027e980fd1
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
tagsutiltest.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "tagsutiltest.h"
10#include <QTest>
11#include <util/sll/qtutil.h>
12#include "util.h"
13
14QTEST_APPLESS_MAIN (LC::Util::TagsUtilTest)
15
16namespace LC::Util
17{
18 void TagsUtilTest::testGetTagsDelimiter_data ()
19 {
20 QTest::addColumn<QString> ("separator");
21 QTest::addColumn<QString> ("expected");
22
23 QTest::newRow ("default") << GetDefaultTagsSeparator () << ";"_qs;
24 QTest::newRow ("spaces around") << " / "_qs << "/"_qs;
25 QTest::newRow ("bare") << "|"_qs << "|"_qs;
26 QTest::newRow ("whitespace only") << " "_qs << " "_qs;
27 }
28
29 void TagsUtilTest::testGetTagsDelimiter ()
30 {
31 QFETCH (QString, separator);
32 QFETCH (QString, expected);
33
34 QCOMPARE (GetTagsDelimiter (separator), expected);
35 }
36
37 void TagsUtilTest::testSplitTags_data ()
38 {
39 QTest::addColumn<QString> ("text");
40 QTest::addColumn<QString> ("separator");
41 QTest::addColumn<QStringList> ("expected");
42
43 const auto sep = "; "_qs;
44 const auto a = "a"_qs;
45 const auto b = "b"_qs;
46
47 QTest::newRow ("canonical") << "a; b"_qs << sep << QStringList { a, b };
48 QTest::newRow ("single") << a << sep << QStringList { a };
49 QTest::newRow ("empty") << QString {} << sep << QStringList {};
50 QTest::newRow ("no space after separator") << "a;b"_qs << sep << QStringList { a, b };
51 QTest::newRow ("whitespace around") << " a ; b "_qs << sep << QStringList { a, b };
52 QTest::newRow ("empty parts") << "a;; ;b;"_qs << sep << QStringList { a, b };
53 QTest::newRow ("whitespace inside kept") << "a b; c\td"_qs << sep << QStringList { "a b"_qs, "c\td"_qs };
54 QTest::newRow ("whitespace separator") << "a b"_qs << " "_qs << QStringList { a, b };
55 QTest::newRow ("any whitespace for a whitespace separator") << "a \t b"_qs << " "_qs << QStringList { a, b };
56 QTest::newRow ("regex metachar separator") << "left|right"_qs << "|"_qs << QStringList { "left"_qs, "right"_qs };
57 }
58
59 void TagsUtilTest::testSplitTags ()
60 {
61 QFETCH (QString, text);
62 QFETCH (QString, separator);
63 QFETCH (QStringList, expected);
64
65 QCOMPARE (SplitTags (text, separator), expected);
66 }
67}
QStringList SplitTags(QStringView text, const QString &separator)
Splits a string with tags into the tags.
Definition util.cpp:25
QString GetDefaultTagsSeparator()
Definition util.cpp:14
QString GetTagsDelimiter(const QString &separator)
Returns the delimiter the tags are split by for the given separator they are joined with.
Definition util.cpp:19