From 188b4e0202c4e4d5950d440721bdd6ef7c4ecbe3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 13 Jun 2012 13:40:21 +1000 Subject: [PATCH] Add some tests for literal parsing Change-Id: I3f3047cf27b1e5d230db0ed4154bac09e6adf087 Reviewed-by: Chris Adams --- tests/auto/qml/qqmllanguage/data/literals.qml | 24 +++++++++++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 44 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/auto/qml/qqmllanguage/data/literals.qml diff --git a/tests/auto/qml/qqmllanguage/data/literals.qml b/tests/auto/qml/qqmllanguage/data/literals.qml new file mode 100644 index 0000000..3a3e846 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/literals.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +QtObject { + property variant n1: 0xFe32 // hex + property variant n2: 015 // octal + property variant n3: -4.2E11 // floating-point literals + property variant n4: .1e9 + property variant n5: 3e-12 + property variant n6: 3e+12 + property variant n7: 0.1e9 + + property variant c1: "\b" // special characters + property variant c2: "\f" + property variant c3: "\n" + property variant c4: "\r" + property variant c5: "\t" + property variant c6: "\v" + property variant c7: "\'" + property variant c8: "\"" + property variant c9: "\\" + property variant c10: "\251" + property variant c11: "\xA9" + property variant c12: "\u00A9" // unicode +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index d5abef3..6349cd3 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -185,6 +185,8 @@ private slots: void crash2(); void globalEnums(); + void literals_data(); + void literals(); private: QQmlEngine engine; @@ -2787,6 +2789,48 @@ void tst_qqmllanguage::globalEnums() delete o; } +void tst_qqmllanguage::literals_data() +{ + QTest::addColumn("property"); + QTest::addColumn("value"); + + QTest::newRow("hex") << "n1" << QVariant(0xfe32); + // Octal integer literals are deprecated +// QTest::newRow("octal") << "n2" << QVariant(015); + QTest::newRow("fp1") << "n3" << QVariant(-4.2E11); + QTest::newRow("fp2") << "n4" << QVariant(.1e9); + QTest::newRow("fp3") << "n5" << QVariant(3e-12); + QTest::newRow("fp4") << "n6" << QVariant(3e+12); + QTest::newRow("fp5") << "n7" << QVariant(0.1e9); + + QTest::newRow("special1") << "c1" << QVariant(QString("\b")); + QTest::newRow("special2") << "c2" << QVariant(QString("\f")); + QTest::newRow("special3") << "c3" << QVariant(QString("\n")); + QTest::newRow("special4") << "c4" << QVariant(QString("\r")); + QTest::newRow("special5") << "c5" << QVariant(QString("\t")); + QTest::newRow("special6") << "c6" << QVariant(QString("\v")); + QTest::newRow("special7") << "c7" << QVariant(QString("\'")); + QTest::newRow("special8") << "c8" << QVariant(QString("\"")); + QTest::newRow("special9") << "c9" << QVariant(QString("\\")); + // We don't handle octal escape sequences +// QTest::newRow("special10") << "c10" << QVariant(QString("\251")); + QTest::newRow("special11") << "c11" << QVariant(QString::fromLatin1("\xa9")); + QTest::newRow("special12") << "c12" << QVariant(QString::fromUtf8("\u00A9")); +} + +void tst_qqmllanguage::literals() +{ + QFETCH(QString, property); + QFETCH(QVariant, value); + + QQmlComponent component(&engine, TEST_FILE("literals.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property(property.toLatin1()), value); + delete object; +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" -- 2.7.4