diff options
author | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2020-01-28 14:21:10 +0100 |
---|---|---|
committer | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2020-01-31 14:33:12 +0100 |
commit | a87ad432a002614a5cca4d635ead5aedb97ba757 (patch) | |
tree | 5548b48b2be23909c761c2b4673bc72b999d3ea5 /tests/auto/qml/qqmlparser/tst_qqmlparser.cpp | |
parent | 65fa7e795dd67250b8d95f13ebd9924069864866 (diff) |
add annotations to QML
A QML Annotation is a Qml Object declaration prepended with @.
The name of the annotation is restricted to a dot separated list of
non keyword identifiers.
Annotations can be put before an Object definition, or any object
member declaration: bindings, property declarations, function
declarations.
This patch, aside parsing the annotations does absolutely nothing, the
list of annotations is discarded and never touches the AST.
[ChangeLog][QML] Add Qml Annotations
Task-number: QTBUG-81714
Change-Id: I4d79559a0d1fb23acaf482d0ef8f7d106dbf099d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlparser/tst_qqmlparser.cpp')
-rw-r--r-- | tests/auto/qml/qqmlparser/tst_qqmlparser.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp index 76b56bd303..0b88358d4a 100644 --- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp +++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp @@ -65,6 +65,8 @@ private slots: void semicolonPartOfExpressionStatement(); void typeAssertion_data(); void typeAssertion(); + void annotations_data(); + void annotations(); private: QStringList excludedDirs; @@ -521,6 +523,67 @@ void tst_qqmlparser::typeAssertion() QVERIFY(parser.parse()); } +void tst_qqmlparser::annotations_data() +{ + QTest::addColumn<QString>("file"); + QTest::addColumn<QString>("refFile"); + + QString tests = dataDirectory() + "/annotations/"; + QString compare = dataDirectory() + "/noannotations/"; + + QStringList files; + files << findFiles(QDir(tests)); + + QStringList refFiles; + refFiles << findFiles(QDir(compare)); + + for (const QString &file: qAsConst(files)) { + auto fileNameStart = file.lastIndexOf(QDir::separator()); + QStringRef fileName(&file, fileNameStart, file.length()-fileNameStart); + auto ref=std::find_if(refFiles.constBegin(),refFiles.constEnd(), [fileName](const QString &s){ return s.endsWith(fileName); }); + if (ref != refFiles.constEnd()) + QTest::newRow(qPrintable(file)) << file << *ref; + else + QTest::newRow(qPrintable(file)) << file << QString(); + } +} + +void tst_qqmlparser::annotations() +{ + using namespace QQmlJS; + + QFETCH(QString, file); + QFETCH(QString, refFile); + + QString code; + QString refCode; + + QFile f(file); + if (f.open(QFile::ReadOnly)) + code = QString::fromUtf8(f.readAll()); + QFile refF(refFile); + if (!refFile.isEmpty() && refF.open(QFile::ReadOnly)) + refCode = QString::fromUtf8(refF.readAll()); + + const bool qmlMode = true; + + Engine engine; + Lexer lexer(&engine); + lexer.setCode(code, 1, qmlMode); + Parser parser(&engine); + QVERIFY(parser.parse()); + + if (!refCode.isEmpty()) { + Engine engine2; + Lexer lexer2(&engine2); + lexer2.setCode(refCode, 1, qmlMode); + Parser parser2(&engine2); + QVERIFY(parser2.parse()); + + // to do: compare for equality skipping annotations + } +} + QTEST_MAIN(tst_qqmlparser) #include "tst_qqmlparser.moc" |