aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2024-04-05 11:04:22 +0200
committerSami Shalayel <sami.shalayel@qt.io>2024-04-23 20:33:38 +0200
commitc2a65fbe04bbcac066a8bf1527d064d4866efbfe (patch)
treea9fc4a62c2d3aa64a35bc15afa9c270528135af7 /tests/auto/qml
parent0559256ddea974d43f971b05c62e61ad76437697 (diff)
qqmljsscope: add ownModuleName
Allow qqmljsscopes of QML components to have "own" module names, and add a helper method moduleName() that helps retrieve the module name of some (possibly non QML component) qqmljsscope by iterating over its parents. That is required for the renaming of qmlcomponents and allows to check if the qml element to be renamed is defined in the same module as the current module. (It is not allowed to rename a QML component from another module). Task-number: QTBUG-114993 Change-Id: I09d57ec87cfc64de31859b2af6334264c4fa6912 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qqmljsscope/data/ownModuleName.qml10
-rw-r--r--tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp29
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmljsscope/data/ownModuleName.qml b/tests/auto/qml/qqmljsscope/data/ownModuleName.qml
new file mode 100644
index 0000000000..6e43ce6b05
--- /dev/null
+++ b/tests/auto/qml/qqmljsscope/data/ownModuleName.qml
@@ -0,0 +1,10 @@
+import QtQuick
+
+Item {
+ Item { id: child }
+ component IC: Item {
+ Item {
+ id: childInIC
+ }
+ }
+}
diff --git a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
index 22aacc01b0..4dacc17f94 100644
--- a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
+++ b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
@@ -71,6 +71,7 @@ class tst_qqmljsscope : public QQmlDataTest
logger.setCode(sourceCode);
logger.setSilent(expectErrorsOrWarnings);
QQmlJSScope::Ptr target = QQmlJSScope::create();
+ target->setOwnModuleName(u"HelloModule"_s);
QQmlJSImportVisitor visitor(target, &m_importer, &logger, dataDirectory());
QQmlJSTypeResolver typeResolver { &m_importer };
typeResolver.init(&visitor, document->program);
@@ -108,6 +109,7 @@ private Q_SLOTS:
void extensions();
void emptyBlockBinding();
void hasOwnEnumerationKeys();
+ void ownModuleName();
void resolvedNonUniqueScopes();
void compilationUnitsAreCompatible();
void attachedTypeResolution_data();
@@ -709,6 +711,33 @@ void tst_qqmljsscope::hasOwnEnumerationKeys()
QVERIFY(!extended->hasOwnEnumerationKey(u"ThisIsTheFlagFromExtension"_s));
}
+void tst_qqmljsscope::ownModuleName()
+{
+ const QString moduleName = u"HelloModule"_s;
+ QQmlJSScope::ConstPtr root = run(u"ownModuleName.qml"_s);
+ QVERIFY(root);
+ QCOMPARE(root->moduleName(), moduleName);
+ QCOMPARE(root->ownModuleName(), moduleName);
+
+ QCOMPARE(root->childScopes().size(), 2);
+ QQmlJSScope::ConstPtr child = root->childScopes().front();
+ QVERIFY(child);
+ // only root and inline components have own module names, but the child should be able to query
+ // its component's module Name via moduleName()
+ QCOMPARE(child->ownModuleName(), QString());
+ QCOMPARE(child->moduleName(), moduleName);
+
+ QQmlJSScope::ConstPtr ic = root->childScopes()[1];
+ QVERIFY(ic);
+ QCOMPARE(ic->ownModuleName(), moduleName);
+ QCOMPARE(ic->moduleName(), moduleName);
+
+ QQmlJSScope::ConstPtr icChild = ic->childScopes().front();
+ QVERIFY(icChild);
+ QCOMPARE(icChild->ownModuleName(), QString());
+ QCOMPARE(icChild->moduleName(), moduleName);
+}
+
void tst_qqmljsscope::resolvedNonUniqueScopes()
{
QQmlJSScope::ConstPtr root = run(u"resolvedNonUniqueScope.qml"_s);