File indexing completed on 2024-12-29 04:54:51
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "lineeditvalidatortest.h" 0008 #include "../lineeditvalidator.h" 0009 #include <QTest> 0010 0011 QTEST_MAIN(LineEditValidatorTest) 0012 0013 LineEditValidatorTest::LineEditValidatorTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 LineEditValidatorTest::~LineEditValidatorTest() = default; 0019 0020 void LineEditValidatorTest::shouldHaveDefaultValue() 0021 { 0022 KSieveUi::LineEditValidator lineedit; 0023 QVERIFY(lineedit.text().isEmpty()); 0024 } 0025 0026 void LineEditValidatorTest::shouldAssignRegularExpression_data() 0027 { 0028 QTest::addColumn<QString>("regularExpression"); 0029 QTest::addColumn<bool>("success"); 0030 QTest::newRow("Empty") << QString() << true; 0031 QTest::newRow("error") << QStringLiteral("\\u2029") << false; 0032 } 0033 0034 void LineEditValidatorTest::shouldAssignRegularExpression() 0035 { 0036 QFETCH(QString, regularExpression); 0037 QFETCH(bool, success); 0038 0039 KSieveUi::LineEditValidator lineedit; 0040 QCOMPARE(lineedit.setRegularExpressionPattern(regularExpression), success); 0041 } 0042 0043 void LineEditValidatorTest::shouldValidateText_data() 0044 { 0045 QTest::addColumn<QString>("input"); 0046 QTest::addColumn<QString>("output"); 0047 QTest::newRow("Empty") << QString() << QString(); 0048 QTest::newRow("normal") << QStringLiteral("foo") << QStringLiteral("foo"); 0049 QTest::newRow("exclu-quote") << QStringLiteral("foo\"") << QStringLiteral("foo"); 0050 QTest::newRow("exclu-quote2") << QStringLiteral(" \"foo\"") << QStringLiteral(" foo"); 0051 QTest::newRow("exclu-quote3") << QStringLiteral("loo@kde.org \"foo\" foo \"toto\" s") << QStringLiteral("loo@kde.org foo foo toto s"); 0052 } 0053 0054 void LineEditValidatorTest::shouldValidateText() 0055 { 0056 QFETCH(QString, input); 0057 QFETCH(QString, output); 0058 KSieveUi::LineEditValidator lineedit; 0059 QTest::keyClicks(&lineedit, input); 0060 QCOMPARE(lineedit.text(), output); 0061 } 0062 0063 #include "moc_lineeditvalidatortest.cpp"