aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qmldom
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2020-04-06 19:13:39 +0200
committerFawzi Mohamed <fawzi.mohamed@qt.io>2020-11-23 16:44:12 +0100
commitfbba765e2372cf21d8c37b2a78bbbc74f8128331 (patch)
tree121168de6dab63c0018267ca414d30f25280865e /tests/auto/qmldom
parent7b89ae6ef4158dcbd1940e088c84eba747c166bc (diff)
qmldom: Start of the Qml Dom library
The goal of the Dom library is to provide a nicer to use basis for the Qml Code model, to be used by the various QML tools, the designer and the new compiler. This commit just adds some common utilities used by the library, to output strings to a Sink, i.e. a function<void(QStringView). This allows writing without allocations of extra temporary strings. The more interesting parts are added in subsequent commits Task-number: QTBUG-74840 Change-Id: I8fa43d5b622f59c8761b2469551127c0508c23c3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qmldom')
-rw-r--r--tests/auto/qmldom/CMakeLists.txt3
-rw-r--r--tests/auto/qmldom/qmldom.pro4
-rw-r--r--tests/auto/qmldom/stringdumper/CMakeLists.txt20
-rw-r--r--tests/auto/qmldom/stringdumper/stringdumper.pro26
-rw-r--r--tests/auto/qmldom/stringdumper/tst_qmldomstringdumper.cpp115
5 files changed, 168 insertions, 0 deletions
diff --git a/tests/auto/qmldom/CMakeLists.txt b/tests/auto/qmldom/CMakeLists.txt
new file mode 100644
index 0000000000..897069f608
--- /dev/null
+++ b/tests/auto/qmldom/CMakeLists.txt
@@ -0,0 +1,3 @@
+# Generated from qmldom.pro.
+
+add_subdirectory(stringdumper)
diff --git a/tests/auto/qmldom/qmldom.pro b/tests/auto/qmldom/qmldom.pro
new file mode 100644
index 0000000000..6a7b30274c
--- /dev/null
+++ b/tests/auto/qmldom/qmldom.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+
+SUBDIRS += \
+ stringdumper
diff --git a/tests/auto/qmldom/stringdumper/CMakeLists.txt b/tests/auto/qmldom/stringdumper/CMakeLists.txt
new file mode 100644
index 0000000000..c72467caf9
--- /dev/null
+++ b/tests/auto/qmldom/stringdumper/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Generated from stringdumper.pro.
+
+#####################################################################
+## tst_qmldomstringdumper Binary:
+#####################################################################
+
+qt_internal_add_test(tst_qmldomstringdumper
+ SOURCES
+ tst_qmldomstringdumper.cpp
+ DEFINES
+ QT_DEPRECATED_WARNINGS
+ PUBLIC_LIBRARIES
+ Qt::Core
+ Qt::QmlDevToolsPrivate
+ Qt::QmlDomPrivate
+ Qt::Test
+)
+
+## Scopes:
+#####################################################################
diff --git a/tests/auto/qmldom/stringdumper/stringdumper.pro b/tests/auto/qmldom/stringdumper/stringdumper.pro
new file mode 100644
index 0000000000..dc9f1a4257
--- /dev/null
+++ b/tests/auto/qmldom/stringdumper/stringdumper.pro
@@ -0,0 +1,26 @@
+QT = core qmldevtools-private testlib
+TARGET = tst_qmldomstringdumper
+
+
+INCLUDEPATH += ../../../../src/qmldom
+
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+ tst_qmldomstringdumper.cpp
+
+
+load(qt_common)
diff --git a/tests/auto/qmldom/stringdumper/tst_qmldomstringdumper.cpp b/tests/auto/qmldom/stringdumper/tst_qmldomstringdumper.cpp
new file mode 100644
index 0000000000..04b9899d0f
--- /dev/null
+++ b/tests/auto/qmldom/stringdumper/tst_qmldomstringdumper.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**/
+#include <QtQmlDom/private/qqmldomstringdumper_p.h>
+
+#include <QtTest/QtTest>
+#include <QTextStream>
+#include <QDebug>
+
+#include <limits>
+
+QT_BEGIN_NAMESPACE
+namespace QQmlJS {
+namespace Dom {
+
+class TestStringDumper: public QObject
+{
+ Q_OBJECT
+private slots:
+ void testDumperToString() {
+ QCOMPARE(dumperToString(u"bla"), QStringLiteral(u"bla"));
+ QCOMPARE(dumperToString([](Sink s) { s(u"bla"); s(u"bla"); }), QStringLiteral(u"blabla"));
+ }
+
+ void testSinkInt() {
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, 1); }), QStringLiteral(u"1"));
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, 0); }), QStringLiteral(u"0"));
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, -1); }), QStringLiteral(u"-1"));
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, std::numeric_limits<qint32>::max()); }), QStringLiteral(u"2147483647"));
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, std::numeric_limits<qint32>::min()); }), QStringLiteral(u"-2147483648"));
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, std::numeric_limits<quint32>::max()); }), QStringLiteral(u"4294967295"));
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, std::numeric_limits<qint64>::min()); }), QStringLiteral(u"-9223372036854775808"));
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, std::numeric_limits<qint64>::max()); }), QStringLiteral(u"9223372036854775807"));
+ QCOMPARE(dumperToString([](Sink s) { sinkInt(s, std::numeric_limits<quint64>::max()); }), QStringLiteral(u"18446744073709551615"));
+ }
+
+ void testSinkEscaped() {
+ QCOMPARE(dumperToString([](Sink s) { sinkEscaped(s, u""); }), QStringLiteral(u"\"\""));
+ QStringView s1 = u"bla:\"bla\\\""; // uR"(bla:"bla\")";
+ QStringView s1Escaped = u"\"bla:\\\"bla\\\\\\\"\"";
+ QCOMPARE(dumperToString([s1](Sink s) { sinkEscaped(s, s1); }), s1Escaped);
+ QCOMPARE(dumperToString([](Sink s) { sinkEscaped(s, u"", EscapeOptions::NoOuterQuotes); }), QStringLiteral(u""));
+ QStringView s2 = u"bla:\"bla\\\"\n";
+ QStringView s2Escaped = u"bla:\\\"bla\\\\\\\"\\n"; // uR"(bla:\"bla\\\"\n)"
+ QCOMPARE(dumperToString([s2](Sink s) { sinkEscaped(s, s2, EscapeOptions::NoOuterQuotes); }), s2Escaped);
+ }
+
+ void testDevNull() {
+ sinkEscaped(devNull, u"");
+ sinkEscaped(devNull, u"bla:\"bla\\\"\n");
+ }
+
+ void testSinkIndent() {
+ QCOMPARE(dumperToString([](Sink s) { sinkIndent(s, 0); }), QStringLiteral(u""));
+ QCOMPARE(dumperToString([](Sink s) { sinkIndent(s, 1); }), QStringLiteral(u" "));
+ QCOMPARE(dumperToString([](Sink s) { sinkIndent(s, 10); }), QStringLiteral(u" "));
+ QCOMPARE(dumperToString([](Sink s) { sinkIndent(s, 40); }), QStringLiteral(u" ").repeated(4));
+ }
+
+
+ void testSinkNewline(){
+ QCOMPARE(dumperToString([](Sink s) { sinkNewline(s); }), QStringLiteral(u"\n"));
+ QCOMPARE(dumperToString([](Sink s) { sinkNewline(s, 0); }), QStringLiteral(u"\n"));
+ QCOMPARE(dumperToString([](Sink s) { sinkNewline(s, 1); }), QStringLiteral(u"\n "));
+ QCOMPARE(dumperToString([](Sink s) { sinkNewline(s, 10); }), QStringLiteral(u"\n "));
+ QCOMPARE(dumperToString([](Sink s) { sinkNewline(s, 40); }), QStringLiteral(u"\n") + QStringLiteral(u" ").repeated(4));
+ }
+
+ void testDumpErrorLevel(){
+ QCOMPARE(dumperToString([](Sink s) { dumpErrorLevel(s, ErrorLevel::Hint); }), QStringLiteral(u"Hint"));
+ QCOMPARE(dumperToString([](Sink s) { dumpErrorLevel(s, ErrorLevel::Error); }), QStringLiteral(u"Error"));
+ QCOMPARE(dumperToString([](Sink s) { dumpErrorLevel(s, ErrorLevel::Warning); }), QStringLiteral(u"Warning"));
+ }
+};
+
+} // namespace Dom
+} // namespace QQmlJS
+QT_END_NAMESPACE
+
+QTEST_MAIN(QQmlJS::Dom::TestStringDumper)
+#include "tst_qmldomstringdumper.moc"