File indexing completed on 2023-05-30 09:18:34
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 SPDX-FileCopyrightText: 2021 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 */ 0006 0007 #include "testcommon.h" 0008 0009 #include "common.h" 0010 0011 #include <QTest> 0012 0013 QTEST_GUILESS_MAIN(TestCommon); 0014 0015 void TestCommon::testExtractColorCodes_data() 0016 { 0017 QTest::addColumn<QString>("ircText"); 0018 QTest::addColumn<QString>("expectedColorCodes"); 0019 0020 QTest::newRow("nocode") << QStringLiteral("hello") << QString(); 0021 QTest::newRow("colorfg1") << QStringLiteral("\x03""1hello") << QStringLiteral("\x03""1"); 0022 QTest::newRow("colorfg2") << QStringLiteral("\x03""15hello") << QStringLiteral("\x03""15"); 0023 QTest::newRow("colorfgcomma") << QStringLiteral("\x03""15,hello") << QStringLiteral("\x03""15"); 0024 QTest::newRow("colorfgbg") << QStringLiteral("\x03""15,12hello") << QStringLiteral("\x03""15,12"); 0025 QTest::newRow("colorreset") << QStringLiteral("\x03hello") << QStringLiteral("\x03"); 0026 QTest::newRow("colorresetcomma") << QStringLiteral("\x03,hello") << QStringLiteral("\x03"); 0027 QTest::newRow("colorfgbgreset") << QStringLiteral("\x03""15,12hello\x0f") << QStringLiteral("\x03""15,12\x0f"); 0028 QTest::newRow("biu") << QStringLiteral("\x02he\x1dllo\x1f") << QStringLiteral("\x02\x1d\x1f"); 0029 } 0030 0031 void TestCommon::testExtractColorCodes() 0032 { 0033 QFETCH(QString, ircText); 0034 QFETCH(QString, expectedColorCodes); 0035 0036 const QString colorCodes = Konversation::extractColorCodes(ircText); 0037 QCOMPARE(colorCodes, expectedColorCodes); 0038 } 0039 0040 void TestCommon::testRemoveIrcMarkup_data() 0041 { 0042 QTest::addColumn<QString>("ircText"); 0043 QTest::addColumn<QString>("expectedText"); 0044 0045 QTest::newRow("nocode") << QStringLiteral("hello") << QStringLiteral("hello"); 0046 QTest::newRow("colorfg1") << QStringLiteral("\x03""1hello") << QStringLiteral("hello"); 0047 QTest::newRow("colorfg2") << QStringLiteral("\x03""15hello") << QStringLiteral("hello"); 0048 QTest::newRow("colorfgcomma") << QStringLiteral("\x03""15,hello") << QStringLiteral(",hello"); 0049 QTest::newRow("colorfgbg") << QStringLiteral("\x03""15,12hello") << QStringLiteral("hello"); 0050 QTest::newRow("colorreset") << QStringLiteral("\x03hello") << QStringLiteral("hello"); 0051 QTest::newRow("colorresetcomma") << QStringLiteral("\x03,hello") << QStringLiteral(",hello"); 0052 QTest::newRow("colorfgbgreset") << QStringLiteral("\x03""15,12hello\x0f") << QStringLiteral("hello"); 0053 QTest::newRow("bbmiddle") << QStringLiteral("he\x02ll\x02o") << QStringLiteral("hello"); 0054 QTest::newRow("biu") << QStringLiteral("\x02he\x1dllo\x1f") << QStringLiteral("hello"); 0055 } 0056 0057 void TestCommon::testRemoveIrcMarkup() 0058 { 0059 QFETCH(QString, ircText); 0060 QFETCH(QString, expectedText); 0061 0062 const QString text = Konversation::removeIrcMarkup(ircText); 0063 QCOMPARE(text, expectedText); 0064 } 0065 0066 void TestCommon::testMatchLength_data() 0067 { 0068 QTest::addColumn<QString>("ircText"); 0069 QTest::addColumn<int>("expectedLength"); 0070 0071 QTest::newRow("nocode") << QStringLiteral("hello") << 0; 0072 QTest::newRow("colorfg") << QStringLiteral("\x03""15hello") << 3; 0073 QTest::newRow("colorfgcomma") << QStringLiteral("\x03""15,hello") << 3; 0074 QTest::newRow("colorfgbg") << QStringLiteral("\x03""15,12hello") << 6; 0075 QTest::newRow("colorreset") << QStringLiteral("\x03hello") << 1; 0076 QTest::newRow("colorresetcomma") << QStringLiteral("\x03,hello") << 1; 0077 QTest::newRow("b") << QStringLiteral("\x02hello") << 1; 0078 QTest::newRow("biu") << QStringLiteral("\x02\x1d\x1fhello") << 1; 0079 } 0080 0081 /// Simulates usage of Konversation::colorRegExp in IRCView::adjustUrlRanges() 0082 void TestCommon::testMatchLength() 0083 { 0084 QFETCH(QString, ircText); 0085 QFETCH(int, expectedLength); 0086 0087 int length = 0; 0088 QRegularExpressionMatch match = Konversation::colorRegExp.match(ircText, 0, QRegularExpression::NormalMatch, QRegularExpression::AnchoredMatchOption); 0089 if (match.hasMatch()) { 0090 length = match.capturedLength(); 0091 } 0092 QCOMPARE(length, expectedLength); 0093 }