forked from qt-creator/qt-creator
Add local lookup tests for QmlLookupContext.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import Qt 4.6
|
||||
|
||||
// Try to look up root, parentItem, foo, child and childChild
|
||||
// in all symbol contexts. It should always get the right item.
|
||||
|
||||
Item {
|
||||
id: root
|
||||
Script {
|
||||
function root() {}
|
||||
function parentItem() {}
|
||||
function foo() {}
|
||||
function child() {}
|
||||
function childChild() {}
|
||||
}
|
||||
property var root: "wrong";
|
||||
property var parentItem: "wrong";
|
||||
property var foo: "wrong";
|
||||
property var child: "wrong";
|
||||
property var childChild: "wrong";
|
||||
Item {
|
||||
id: parentItem
|
||||
property var root: "wrong";
|
||||
property var parentItem: "wrong";
|
||||
property var foo: "wrong";
|
||||
property var child: "wrong";
|
||||
property var childChild: "wrong";
|
||||
Item {
|
||||
id: foo
|
||||
property var root: "wrong";
|
||||
property var parentItem: "wrong";
|
||||
property var foo: "wrong";
|
||||
property var child: "wrong";
|
||||
property var childChild: "wrong";
|
||||
Item {
|
||||
id: child
|
||||
property var root: "wrong";
|
||||
property var parentItem: "wrong";
|
||||
property var foo: "wrong";
|
||||
property var child: "wrong";
|
||||
property var childChild: "wrong";
|
||||
Item {
|
||||
id: childChild
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import Qt 4.6
|
||||
|
||||
// Try to look up prop in child.
|
||||
// It should get the root's prop.
|
||||
|
||||
Item {
|
||||
id: theRoot
|
||||
property var prop
|
||||
Item {
|
||||
id: theParent
|
||||
property var prop
|
||||
Item {
|
||||
id: theChild
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import Qt 4.6
|
||||
|
||||
// Try to look up prop in all symbol contexts.
|
||||
// It should always get the local one.
|
||||
|
||||
Item {
|
||||
id: theRoot
|
||||
property var prop
|
||||
Item {
|
||||
id: theParent
|
||||
property var prop
|
||||
Item {
|
||||
id: theChild
|
||||
property var prop
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import Qt 4.6
|
||||
|
||||
// Try to look up rootFunc, parentFunc, childFunc
|
||||
// in all symbol contexts. It should always get the function.
|
||||
|
||||
Item {
|
||||
id: theRoot
|
||||
Script {
|
||||
function rootFunc() {}
|
||||
}
|
||||
property var rootFunc: "wrong";
|
||||
property var parentFunc: "wrong";
|
||||
property var childFunc: "wrong";
|
||||
Item {
|
||||
id: theParent
|
||||
Script {
|
||||
function parentFunc() {}
|
||||
}
|
||||
property var rootFunc: "wrong";
|
||||
property var parentFunc: "wrong";
|
||||
property var childFunc: "wrong";
|
||||
Item {
|
||||
id: theChild
|
||||
Script {
|
||||
function childFunc() {}
|
||||
}
|
||||
property var rootFunc: "wrong";
|
||||
property var parentFunc: "wrong";
|
||||
property var childFunc: "wrong";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,3 +12,4 @@ SOURCES += tst_lookup.cpp \
|
||||
$$EDITOR_DIR/qmllookupcontext.cpp
|
||||
|
||||
HEADERS += $$EDITOR_DIR/qmllookupcontext.h
|
||||
RESOURCES += testfiles.qrc
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<RCC>
|
||||
<qresource prefix="/" >
|
||||
<file>data/localIdLookup.qml</file>
|
||||
<file>data/localScriptMethodLookup.qml</file>
|
||||
<file>data/localScopeLookup.qml</file>
|
||||
<file>data/localRootLookup.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <QDebug>
|
||||
#include <QtTest>
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qml/parser/qmljsast_p.h>
|
||||
@@ -26,6 +27,10 @@ public:
|
||||
private Q_SLOTS:
|
||||
void basicSymbolTest();
|
||||
void basicLookupTest();
|
||||
void localIdLookup();
|
||||
void localScriptMethodLookup();
|
||||
void localScopeLookup();
|
||||
void localRootLookup();
|
||||
|
||||
protected:
|
||||
QmlDocument::Ptr basicSymbolTest(const QString &input) const
|
||||
@@ -164,5 +169,134 @@ void tst_Lookup::basicLookupTest()
|
||||
QVERIFY(fontPropFound);
|
||||
}
|
||||
|
||||
void tst_Lookup::localIdLookup()
|
||||
{
|
||||
QFile input(":/data/localIdLookup.qml");
|
||||
QVERIFY(input.open(QIODevice::ReadOnly));
|
||||
|
||||
QmlDocument::Ptr doc = basicSymbolTest(input.readAll());
|
||||
QVERIFY(doc->isParsedCorrectly());
|
||||
|
||||
QStringList symbolNames;
|
||||
symbolNames.append("root");
|
||||
symbolNames.append("parentItem");
|
||||
symbolNames.append("foo");
|
||||
symbolNames.append("child");
|
||||
symbolNames.append("childChild");
|
||||
|
||||
// check symbol existence
|
||||
foreach (const QString &symbolName, symbolNames) {
|
||||
QVERIFY(doc->ids()[symbolName]);
|
||||
}
|
||||
|
||||
// try lookup
|
||||
QStack<QmlSymbol *> scopes;
|
||||
foreach (const QString &contextSymbolName, symbolNames) {
|
||||
scopes.push_back(doc->ids()[contextSymbolName]);
|
||||
QmlLookupContext context(scopes, doc, snapshot(doc), typeSystem());
|
||||
|
||||
foreach (const QString &lookupSymbolName, symbolNames) {
|
||||
QCOMPARE(context.resolve(lookupSymbolName), doc->ids()[lookupSymbolName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Lookup::localScriptMethodLookup()
|
||||
{
|
||||
QFile input(":/data/localScriptMethodLookup.qml");
|
||||
QVERIFY(input.open(QIODevice::ReadOnly));
|
||||
|
||||
QmlDocument::Ptr doc = basicSymbolTest(input.readAll());
|
||||
QVERIFY(doc->isParsedCorrectly());
|
||||
|
||||
QStringList symbolNames;
|
||||
symbolNames.append("theRoot");
|
||||
symbolNames.append("theParent");
|
||||
symbolNames.append("theChild");
|
||||
|
||||
QStringList functionNames;
|
||||
functionNames.append("rootFunc");
|
||||
functionNames.append("parentFunc");
|
||||
functionNames.append("childFunc");
|
||||
|
||||
// check symbol existence
|
||||
foreach (const QString &symbolName, symbolNames) {
|
||||
QVERIFY(doc->ids()[symbolName]);
|
||||
}
|
||||
|
||||
// try lookup
|
||||
QStack<QmlSymbol *> scopes;
|
||||
foreach (const QString &contextSymbolName, symbolNames) {
|
||||
scopes.push_back(doc->ids()[contextSymbolName]);
|
||||
QmlLookupContext context(scopes, doc, snapshot(doc), typeSystem());
|
||||
|
||||
foreach (const QString &functionName, functionNames) {
|
||||
QmlSymbol *symbol = context.resolve(functionName);
|
||||
QVERIFY(symbol && !symbol->isProperty());
|
||||
// verify that it's a function
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Lookup::localScopeLookup()
|
||||
{
|
||||
QFile input(":/data/localScopeLookup.qml");
|
||||
QVERIFY(input.open(QIODevice::ReadOnly));
|
||||
|
||||
QmlDocument::Ptr doc = basicSymbolTest(input.readAll());
|
||||
QVERIFY(doc->isParsedCorrectly());
|
||||
|
||||
QStringList symbolNames;
|
||||
symbolNames.append("theRoot");
|
||||
symbolNames.append("theParent");
|
||||
symbolNames.append("theChild");
|
||||
|
||||
// check symbol existence
|
||||
foreach (const QString &symbolName, symbolNames) {
|
||||
QVERIFY(doc->ids()[symbolName]);
|
||||
}
|
||||
|
||||
// try lookup
|
||||
QStack<QmlSymbol *> scopes;
|
||||
foreach (const QString &contextSymbolName, symbolNames) {
|
||||
scopes.push_back(doc->ids()[contextSymbolName]);
|
||||
QmlLookupContext context(scopes, doc, snapshot(doc), typeSystem());
|
||||
|
||||
QmlSymbol *symbol = context.resolve("prop");
|
||||
QVERIFY(symbol);
|
||||
QVERIFY(symbol->isPropertyDefinitionSymbol());
|
||||
QVERIFY(doc->ids()[contextSymbolName]->members().contains(symbol));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Lookup::localRootLookup()
|
||||
{
|
||||
QFile input(":/data/localRootLookup.qml");
|
||||
QVERIFY(input.open(QIODevice::ReadOnly));
|
||||
|
||||
QmlDocument::Ptr doc = basicSymbolTest(input.readAll());
|
||||
QVERIFY(doc->isParsedCorrectly());
|
||||
|
||||
QStringList symbolNames;
|
||||
symbolNames.append("theRoot");
|
||||
symbolNames.append("theParent");
|
||||
symbolNames.append("theChild");
|
||||
|
||||
// check symbol existence and build scopes
|
||||
QStack<QmlSymbol *> scopes;
|
||||
foreach (const QString &symbolName, symbolNames) {
|
||||
QmlSymbol *symbol = doc->ids()[symbolName];
|
||||
QVERIFY(symbol);
|
||||
scopes.push_back(symbol);
|
||||
}
|
||||
|
||||
// try lookup
|
||||
QmlLookupContext context(scopes, doc, snapshot(doc), typeSystem());
|
||||
QmlSymbol *symbol = context.resolve("prop");
|
||||
QVERIFY(symbol);
|
||||
QVERIFY(symbol->isPropertyDefinitionSymbol());
|
||||
QVERIFY(doc->ids()[symbolNames[0]]->members().contains(symbol));
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_Lookup)
|
||||
#include "tst_lookup.moc"
|
||||
|
||||
Reference in New Issue
Block a user