Changeset View
Changeset View
Standalone View
Standalone View
tests/auto/qmljsc/testpurejavascriptgenerator.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include <QtTest/QTest> | 21 | #include <QtTest/QTest> | ||
22 | 22 | | |||
23 | #include <private/qqmljsast_p.h> | 23 | #include <private/qqmljsast_p.h> | ||
24 | #include <private/qqmljsgrammar_p.h> | 24 | #include <private/qqmljsgrammar_p.h> | ||
25 | #include <private/qqmljslexer_p.h> | 25 | #include <private/qqmljslexer_p.h> | ||
26 | 26 | | |||
27 | #include "../../../src/qmljsc/utils/error.h" | 27 | #include "../../../src/qmljsc/utils/error.h" | ||
28 | #include "../../../src/qmljsc/purejavascriptgenerator.h" | 28 | #include "../../../src/qmljsc/codegeneration/purejavascriptgenerator.h" | ||
29 | 29 | | |||
30 | #define TEST_VISIT_PUTS_ON_STACK(className, testSituation, expectedStackContent, instance) \ | 30 | #define TEST_VISIT_PUTS_ON_STACK(className, testSituation, expectedStackContent, instance) \ | ||
31 | void test_visit_ ## className ## _ ## testSituation ## _returnsTrue() { \ | 31 | void test_visit_ ## className ## _ ## testSituation ## _returnsTrue() { \ | ||
32 | QCOMPARE(m_generator->visit(&instance), true); \ | 32 | QCOMPARE(m_generator->visit(&instance), true); \ | ||
33 | } \ | 33 | } \ | ||
34 | void test_ ## visit ## _ ## className ## _ ## testSituation ## _putsOnStack() { \ | 34 | void test_ ## visit ## _ ## className ## _ ## testSituation ## _putsOnStack() { \ | ||
35 | m_generator->visit(&instance); \ | 35 | m_generator->visit(&instance); \ | ||
36 | QCOMPARE(asPureJSGen(m_generator)->m_outputStack.top(), QStringLiteral(expectedStackContent)); \ | 36 | QCOMPARE(asPureJSGen(m_generator)->m_outputStack.top(), QStringLiteral(expectedStackContent)); \ | ||
Show All 28 Lines | 63 | void test_endVisit_ ## className ## _ ## scenarioName ## _reducesStack() { \ | |||
65 | m_generator->endVisit(&instance); \ | 65 | m_generator->endVisit(&instance); \ | ||
66 | QCOMPARE(asPureJSGen(m_generator)->m_outputStack.top(), QStringLiteral(expectedTopOfStack)); \ | 66 | QCOMPARE(asPureJSGen(m_generator)->m_outputStack.top(), QStringLiteral(expectedTopOfStack)); \ | ||
67 | QCOMPARE(asPureJSGen(m_generator)->m_outputStack.count(), 1); \ | 67 | QCOMPARE(asPureJSGen(m_generator)->m_outputStack.count(), 1); \ | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | 70 | | |||
71 | using namespace QQmlJS; | 71 | using namespace QQmlJS; | ||
72 | 72 | | |||
73 | namespace QmlJSc { | ||||
74 | | ||||
73 | class TestPureJavaScriptGenerator | 75 | class TestPureJavaScriptGenerator | ||
74 | : public QObject | 76 | : public QObject | ||
75 | { | 77 | { | ||
76 | Q_OBJECT | 78 | Q_OBJECT | ||
77 | 79 | | |||
78 | public: | 80 | public: | ||
79 | TestPureJavaScriptGenerator() | 81 | TestPureJavaScriptGenerator() | ||
80 | : m_someLabel("ALabel") | 82 | : m_someLabel("ALabel") | ||
▲ Show 20 Lines • Show All 343 Lines • ▼ Show 20 Line(s) | 421 | void test_getGeneratedCode_getsTopOfStack() { | |||
424 | QCOMPARE(asPureJSGen(m_generator)->getGeneratedCode(), QStringLiteral("1")); | 426 | QCOMPARE(asPureJSGen(m_generator)->getGeneratedCode(), QStringLiteral("1")); | ||
425 | } | 427 | } | ||
426 | 428 | | |||
427 | void test_getGeneratedCode_throwsError_OnStackSizeGreaterThanOne() { | 429 | void test_getGeneratedCode_throwsError_OnStackSizeGreaterThanOne() { | ||
428 | // Prepare | 430 | // Prepare | ||
429 | asPureJSGen(m_generator)->m_outputStack << "1" << "2"; | 431 | asPureJSGen(m_generator)->m_outputStack << "1" << "2"; | ||
430 | 432 | | |||
431 | // Verify | 433 | // Verify | ||
432 | QVERIFY_EXCEPTION_THROWN(asPureJSGen(m_generator)->getGeneratedCode(), QmlJSc::Error); | 434 | QVERIFY_EXCEPTION_THROWN(asPureJSGen(m_generator)->getGeneratedCode(), QmlJSc::Error *); | ||
433 | } | 435 | } | ||
434 | 436 | | |||
435 | TEST_VISIT_DEFAULT_IMPL_(Block , m_block) | 437 | TEST_VISIT_DEFAULT_IMPL_(Block , m_block) | ||
436 | TEST_VISIT_PUTS_ON_STACK(BreakStatement , WithLabel , "break ALabel;" , m_breakStatementWithLabel) | 438 | TEST_VISIT_PUTS_ON_STACK(BreakStatement , WithLabel , "break ALabel;" , m_breakStatementWithLabel) | ||
437 | TEST_VISIT_PUTS_ON_STACK(BreakStatement , WithoutLabel , "break;" , m_breakStatementWithoutLabel) | 439 | TEST_VISIT_PUTS_ON_STACK(BreakStatement , WithoutLabel , "break;" , m_breakStatementWithoutLabel) | ||
438 | TEST_VISIT_DEFAULT_IMPL_(CaseBlock , m_caseBlock) | 440 | TEST_VISIT_DEFAULT_IMPL_(CaseBlock , m_caseBlock) | ||
439 | TEST_VISIT_PUTS_ON_STACK(CaseClause , AnyCase , "case" , m_caseClause1) | 441 | TEST_VISIT_PUTS_ON_STACK(CaseClause , AnyCase , "case" , m_caseClause1) | ||
440 | TEST_VISIT_DEFAULT_IMPL_(CaseClauses , m_twoCaseClauses) | 442 | TEST_VISIT_DEFAULT_IMPL_(CaseClauses , m_twoCaseClauses) | ||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | |||||
595 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(Lt, "<") | 597 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(Lt, "<") | ||
596 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(Le, "<=") | 598 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(Le, "<=") | ||
597 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(And, "&&") | 599 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(And, "&&") | ||
598 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(Or, "||") | 600 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(Or, "||") | ||
599 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(In, " in ") | 601 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(In, " in ") | ||
600 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(InstanceOf, " instanceof ") | 602 | TEST_VISIT_BINARYOP_PUTS_ON_STACK(InstanceOf, " instanceof ") | ||
601 | }; | 603 | }; | ||
602 | 604 | | |||
603 | QTEST_MAIN(TestPureJavaScriptGenerator) | 605 | } // namespace QmlJSc | ||
606 | | ||||
607 | QTEST_MAIN(QmlJSc::TestPureJavaScriptGenerator) | ||||
604 | #include "testpurejavascriptgenerator.moc" | 608 | #include "testpurejavascriptgenerator.moc" |