QmlDesigner: Add another test to ConnectionEditor

This covers field expressions with more then two members.

Change-Id: Idccfac607f72ff9aa78ed3b8da560f7d7a8e694d
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
This commit is contained in:
Thomas Hartmann
2023-09-08 16:25:59 +02:00
parent 28933f2d4d
commit 54b0c2d435

View File

@@ -35,6 +35,7 @@ private slots:
void parseConsoleLog();
void parseCallFunction();
void parseEmpty();
void parseComplexCondition();
QByteArray countOne();
private:
@@ -337,6 +338,42 @@ void tst_ConnectionEditor::parseEmpty()
QVERIFY(std::holds_alternative<ConnectionEditorStatements::EmptyBlock>(parsedStatement));
}
void tst_ConnectionEditor::parseComplexCondition()
{
auto result = ConnectionEditorEvaluator::parseStatement(
"{if (someItem.deeper.gothis && thistest.is.getit){someItem.trigger()}}");
auto &matchedCondition = ConnectionEditorStatements::matchedCondition(result);
QCOMPARE(matchedCondition.statements.count(), 2);
auto firstStatement = matchedCondition.statements.first();
QVERIFY(std::holds_alternative<ConnectionEditorStatements::Variable>(firstStatement));
auto variable = std::get<ConnectionEditorStatements::Variable>(firstStatement);
QCOMPARE(variable.nodeId, "someItem");
QCOMPARE(variable.propertyName, "deeper.gothis");
auto lastStatement = matchedCondition.statements.last();
QVERIFY(std::holds_alternative<ConnectionEditorStatements::Variable>(lastStatement));
variable = std::get<ConnectionEditorStatements::Variable>(lastStatement);
QCOMPARE(variable.nodeId, "thistest");
QCOMPARE(variable.propertyName, "is.getit");
matchedCondition.statements.clear();
matchedCondition.tokens.clear();
variable.nodeId = "justId";
variable.propertyName = {};
matchedCondition.statements.append(variable);
const QString source = ConnectionEditorStatements::toJavascript(result);
QVERIFY(source.startsWith("if (justId)"));
}
void tst_ConnectionEditor::test01()
{
QFETCH(QString, statement);