1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | |
30 | #include <QtTest/QtTest> |
31 | |
32 | #include "tokenizers/basic/basic.h" |
33 | #include "tokenizers/basicNamespace/basicNamespace.h" |
34 | #include "tokenizers/boilerplate/boilerplate.h" |
35 | #include "tokenizers/noToString/noToString.h" |
36 | |
37 | /*! |
38 | \class tst_QTokenAutomaton |
39 | \internal |
40 | \brief Tests the QTokenAutomaton generator. |
41 | |
42 | TODO: |
43 | - Verify high Unicode codepoints |
44 | - Verify that signatures are static. |
45 | */ |
46 | class tst_QTokenAutomaton : public QObject |
47 | { |
48 | Q_OBJECT |
49 | |
50 | private Q_SLOTS: |
51 | void tokenizerBasic() const; |
52 | }; |
53 | |
54 | void tst_QTokenAutomaton::tokenizerBasic() const |
55 | { |
56 | typedef QPair<Basic::Token, QString> TokenPair; |
57 | typedef QList<TokenPair> TokenPairList; |
58 | |
59 | /* Tokenizer basic. */ |
60 | { |
61 | /* All the tokens matching tokens. */ |
62 | { |
63 | TokenPairList tokens; |
64 | tokens.append(t: qMakePair(x: Basic::_, y: QString::fromLatin1(str: "abc" ))); |
65 | tokens.append(t: qMakePair(x: Basic::_111, y: QString::fromLatin1(str: "def" ))); |
66 | tokens.append(t: qMakePair(x: Basic::wobbly, y: QString::fromLatin1(str: "ghi" ))); |
67 | tokens.append(t: qMakePair(x: Basic::FFFF, y: QString::fromLatin1(str: "FFFF" ))); |
68 | tokens.append(t: qMakePair(x: Basic::FFFG, y: QString::fromLatin1(str: "FFFG" ))); |
69 | tokens.append(t: qMakePair(x: Basic::FFGG, y: QString::fromLatin1(str: "FFGG" ))); |
70 | tokens.append(t: qMakePair(x: Basic::FFGF, y: QString::fromLatin1(str: "FFGF" ))); |
71 | tokens.append(t: qMakePair(x: Basic::FFLM, y: QString::fromLatin1(str: "FFLM" ))); |
72 | tokens.append(t: qMakePair(x: Basic::AReallyLongTokenIFreakinMeanItUKnowUKnowKnow, y: QString::fromLatin1(str: "aReallyLongTokenIFreakinMeanItUKnowUKnowKnow" ))); |
73 | tokens.append(t: qMakePair(x: Basic::WeHaveDashes, y: QString::fromLatin1(str: "we-have-dashes" ))); |
74 | tokens.append(t: qMakePair(x: Basic::WeHaveDashes2, y: QString::fromLatin1(str: "we-have-dashes-" ))); |
75 | |
76 | /* toToken(). */ |
77 | for(int i = 0; i < tokens.count(); ++i) |
78 | { |
79 | const TokenPair &at = tokens.at(i); |
80 | /* QString. */ |
81 | QCOMPARE(Basic::toToken(at.second), at.first); |
82 | |
83 | /* const QChar *, int. */ |
84 | QCOMPARE(Basic::toToken(at.second.constData(), at.second.length()), at.first); |
85 | |
86 | /* QStringRef. */ |
87 | const QStringRef ref(&at.second); |
88 | QCOMPARE(Basic::toToken(ref), at.first); |
89 | } |
90 | |
91 | /* toString(). */ |
92 | for(int i = 0; i < tokens.count(); ++i) |
93 | { |
94 | const TokenPair &at = tokens.at(i); |
95 | QCOMPARE(Basic::toString(at.first), at.second); |
96 | } |
97 | } |
98 | |
99 | /* Tokens that we don't recognize. */ |
100 | { |
101 | QStringList tokens; |
102 | tokens.append(t: QLatin1String("NO-MATCH" )); |
103 | tokens.append(t: QLatin1String("NoKeyword" )); |
104 | tokens.append(t: QString()); |
105 | |
106 | for(int i = 0; i < tokens.count(); ++i) |
107 | QCOMPARE(Basic::toToken(tokens.at(i)), Basic::NoKeyword); |
108 | } |
109 | |
110 | /* Weird values for toToken(). */ |
111 | { |
112 | QCOMPARE(Basic::toString(Basic::Token(5000)), QString()); |
113 | QCOMPARE(Basic::toString(Basic::NoKeyword), QString()); |
114 | } |
115 | |
116 | } |
117 | } |
118 | |
119 | QTEST_MAIN(tst_QTokenAutomaton) |
120 | |
121 | #include "tst_qtokenautomaton.moc" |
122 | |