#QUALITY by cg
authorClaus Gittinger <cg@exept.de>
Thu, 26 Apr 2018 06:52:58 +0200
changeset 1914 1c6845cf22c3
parent 1913 0b020197090b
child 1915 af63d419f526
#QUALITY by cg class: RegressionTests::JavaScriptTests added: #testConst01 #testConst02 #test_04_parse_object #test_05_parse_object
RegressionTests__JavaScriptTests.st
--- a/RegressionTests__JavaScriptTests.st	Wed Apr 25 07:11:49 2018 +0200
+++ b/RegressionTests__JavaScriptTests.st	Thu Apr 26 06:52:58 2018 +0200
@@ -622,6 +622,57 @@
     "
 !
 
+testConst01
+    "
+    Tests parsing of a const
+    "
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self
+            execute:'test(arg) {
+                        const n = 10;
+
+                        return n;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:10
+    ].
+
+    "
+     self run:#testConst01
+     self new testConst01
+    "
+!
+
+testConst02
+    "
+    Tests parsing of a const
+    "
+    |output|
+
+    self skipIf:true description:'skipped until const is fully implemented'.
+
+    output := self outputToTranscriptOf:[
+        self
+            execute:'test(arg) {
+                        const n = 10;
+
+                        n = 11;
+                        return n;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:#ParseError
+    ].
+
+    "
+     self run:#testConst02
+     self new testConst02
+    "
+!
+
 testDoWhile01
     |output|
 
@@ -5884,6 +5935,93 @@
     "
 !
 
+test_04_parse_object
+    "complex object parsing (example from alexa's nodejs)"
+
+    |code|
+
+code := '
+function test() {
+    const startGameHandlers = Alexa.CreateStateHandler("ASKMODE", {
+        "AMAZON.YesIntent": function () {
+            this.emitWithState("AskQuestionIntent");
+        },
+        "AskQuestionIntent": function() {
+            this.handler.state = "ANSWERMODE";
+
+            const randomQuestion = getRandomQuestion();
+            this.attributes.questions[randomQuestion.id] = null;  // maintain questions within the same session
+            this.attributes.questionId = randomQuestion.id;
+            this.emit(":ask", randomQuestion.display);
+        },
+        "FinishIntent": function() {
+            this.emit(":tell", "All your answers are correct. Thanks for playing");
+        },
+    });
+    return startGameHandlers;
+}
+'.
+    JavaScriptParser parseStatementBlockBody:code.
+
+"/    self
+"/        execute:code
+"/        for:nil
+"/        arguments:#(  )
+"/        expect:#().
+
+    "
+     self run:#test_04_parse_object
+     self new test_04_parse_object
+    "
+!
+
+test_05_parse_object
+    "complex object parsing (example from alexa's nodejs)"
+
+    |code result dummyAlexa|
+
+code := '
+function test(Alexa) {
+    const startGameHandlers = Alexa.CreateStateHandler("ASKMODE", {
+        "AMAZON.YesIntent": function () {
+            this.emitWithState("AskQuestionIntent");
+        },
+        "AskQuestionIntent": function() {
+            this.handler.state = "ANSWERMODE";
+
+            const randomQuestion = getRandomQuestion();
+            this.attributes.questions[randomQuestion.id] = null;  // maintain questions within the same session
+            this.attributes.questionId = randomQuestion.id;
+            this.emit(":ask", randomQuestion.display);
+        },
+        "FinishIntent": function() {
+            this.emit(":tell", "All your answers are correct. Thanks for playing");
+        },
+    });
+    return startGameHandlers;
+}
+'.
+
+    dummyAlexa := Plug new
+                    respondTo:#'CreateStateHandler:_:'
+                    with:[:a1 :a2 | a2].
+    result := self execute:code for:nil arguments:{dummyAlexa}.
+    self assert:(result at:#'AMAZON.YesIntent') isBlock.
+    self assert:(result at:#'AskQuestionIntent') isBlock.
+    self assert:(result at:#'FinishIntent') isBlock.
+
+"/    self
+"/        execute:code
+"/        for:nil
+"/        arguments:#(  )
+"/        expect:#().
+
+    "
+     self run:#test_05_parse_object
+     self new test_05_parse_object
+    "
+!
+
 test_10_parse_expression1
     |spec|