Changeset View
Changeset View
Standalone View
Standalone View
autotests/definition_test.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2018 Christoph Cullmann <cullmann@kde.org> | ||||
3 | | ||||
4 | Permission is hereby granted, free of charge, to any person obtaining | ||||
5 | a copy of this software and associated documentation files (the | ||||
6 | "Software"), to deal in the Software without restriction, including | ||||
7 | without limitation the rights to use, copy, modify, merge, publish, | ||||
8 | distribute, sublicense, and/or sell copies of the Software, and to | ||||
9 | permit persons to whom the Software is furnished to do so, subject to | ||||
10 | the following conditions: | ||||
11 | | ||||
12 | The above copyright notice and this permission notice shall be included | ||||
13 | in all copies or substantial portions of the Software. | ||||
14 | | ||||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||||
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||||
18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||||
19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||||
20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||||
21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||
22 | */ | ||||
23 | | ||||
24 | #include <definition.h> | ||||
25 | | ||||
26 | #include <QObject> | ||||
27 | #include <qtest.h> | ||||
28 | | ||||
29 | using namespace KSyntaxHighlighting; | ||||
30 | | ||||
31 | class DefinitionTest : public QObject | ||||
32 | { | ||||
33 | Q_OBJECT | ||||
34 | private Q_SLOTS: | ||||
35 | void testDefinitionDefault() | ||||
36 | { | ||||
37 | // check some default definition properties | ||||
38 | Definition defDefinition; | ||||
39 | QVERIFY(!defDefinition.isValid()); | ||||
40 | QVERIFY(defDefinition.extensions().isEmpty()); | ||||
41 | QVERIFY(defDefinition.extensionsAsRegularExpression().pattern().isEmpty()); | ||||
42 | } | ||||
43 | | ||||
44 | void test_convertExtensionsToRegularExpressionMatch_data() | ||||
45 | { | ||||
46 | QTest::addColumn<QString>("extensions"); | ||||
47 | QTest::addColumn<QString>("name"); | ||||
48 | | ||||
49 | QTest::newRow("test.c") << "*.c;*.h" << "test.c"; | ||||
50 | QTest::newRow("Makefile") << "Makefil?" << "Makefile"; | ||||
51 | QTest::newRow("foobar.foo") << "*.*" << "foobar.foo"; | ||||
52 | QTest::newRow("empty") << "*" << ""; | ||||
53 | } | ||||
54 | | ||||
55 | void test_convertExtensionsToRegularExpressionMatch() | ||||
56 | { | ||||
57 | QFETCH(QString, extensions); | ||||
58 | QFETCH(QString, name); | ||||
59 | | ||||
60 | // construct regex and test it | ||||
61 | QVector<QString> extensionsVector; | ||||
62 | foreach (const auto &ext, extensions.split(QLatin1Char(';'), QString::SkipEmptyParts)) | ||||
63 | extensionsVector.push_back(ext); | ||||
64 | const QRegularExpression regex = Definition::convertExtensionsToRegularExpression(QVector<QString>() << extensionsVector); | ||||
65 | QVERIFY(regex.match(name).hasMatch()); | ||||
66 | } | ||||
67 | | ||||
68 | void test_convertExtensionsToRegularExpressionNoMatch_data() | ||||
69 | { | ||||
70 | QTest::addColumn<QString>("extensions"); | ||||
71 | QTest::addColumn<QString>("name"); | ||||
72 | | ||||
73 | QTest::newRow("test.cpp") << "*.c;*.h" << "test.cpp"; | ||||
74 | QTest::newRow("test") << "test?" << "test"; | ||||
75 | QTest::newRow("empty") << "*.*" << ""; | ||||
76 | QTest::newRow("empty2") << "?" << ""; | ||||
77 | } | ||||
78 | | ||||
79 | void test_convertExtensionsToRegularExpressionNoMatch() | ||||
80 | { | ||||
81 | QFETCH(QString, extensions); | ||||
82 | QFETCH(QString, name); | ||||
83 | | ||||
84 | // construct regex and test it | ||||
85 | QVector<QString> extensionsVector; | ||||
86 | foreach (const auto &ext, extensions.split(QLatin1Char(';'), QString::SkipEmptyParts)) | ||||
87 | extensionsVector.push_back(ext); | ||||
88 | const QRegularExpression regex = Definition::convertExtensionsToRegularExpression(QVector<QString>() << extensionsVector); | ||||
89 | QVERIFY(!regex.match(name).hasMatch()); | ||||
90 | } | ||||
91 | }; | ||||
92 | | ||||
93 | QTEST_GUILESS_MAIN(DefinitionTest) | ||||
94 | | ||||
95 | #include "definition_test.moc" |