RegressionTests__JavaScriptTests.st
changeset 1368 f284431e7168
parent 1367 f356e0666d36
child 1447 2351db93aa5b
--- a/RegressionTests__JavaScriptTests.st	Wed Mar 23 18:40:41 2016 +0100
+++ b/RegressionTests__JavaScriptTests.st	Wed Mar 23 18:59:07 2016 +0100
@@ -503,25 +503,36 @@
 !
 
 testComments01
-    self 
-        execute:'
-                  testComments() {
-                      // Unicode is allowed in comments
-                      // This is a comment \u0410\u0406\u0414\u0419
-                      /* Another comment \u05D0\u2136\u05d3\u05d7 */
-
-                      /**/ // Tiny comment
-                      /***/ // Also valid
-
-                      // Need to test string literals and identifiers
-                      println("All is well in Javascript");
-                      return null;
-                  }
-                 '
-        for:JavaScriptEnvironment new
-        arguments:#(  )
-        expect:nil
-
+    |savedTranscript collector expected|
+
+    savedTranscript := Smalltalk at:#Transcript.     
+    [
+        Smalltalk at:#Transcript put:(collector := '' writeStream).
+        self 
+            execute:'
+                      testComments() {
+                          // Unicode is allowed in comments
+                          // This is a comment \u0410\u0406\u0414\u0419
+                          /* Another comment \u05D0\u2136\u05d3\u05d7 */
+
+                          /**/ // Tiny comment
+                          /***/ // Also valid
+
+                          // Need to test string literals and identifiers
+                          println("All is well in Javascript");
+                          return null;
+                      }
+                     '
+            for:JavaScriptEnvironment new
+            arguments:#(  )
+            expect:nil
+    ] ensure:[
+        Smalltalk at:#Transcript put:savedTranscript
+    ].
+
+    expected := String streamContents:[:s | s showCR:'All is well in Javascript'].
+    self assert:(collector contents = expected).
+    
     "
      self run:#testComments01
      self new testComments01  
@@ -965,16 +976,27 @@
 !
 
 testFor05
-    self 
-        execute:'test(arg) {
-                    for (var n = 0; n < arg; n++) {
-                        Transcript.showCR(n);
-                    }
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:nil
-
+    |savedTranscript collector expected|
+
+    savedTranscript := Smalltalk at:#Transcript.     
+    [
+        Smalltalk at:#Transcript put:(collector := '' writeStream).
+        self 
+            execute:'test(arg) {
+                        for (var n = 0; n < arg; n++) {
+                            Transcript.showCR(n);
+                        }
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:nil
+    ] ensure:[
+        Smalltalk at:#Transcript put:savedTranscript
+    ].
+    
+    expected := String streamContents:[:s | 0 to:4 do:[:n | s showCR:n]].
+    self assert:(collector contents = expected).
+    
     "
      self run:#testFor05
      self new testFor05  
@@ -1359,8 +1381,14 @@
 
 testInnerFunctionWithForLoop
 
-    self 
-        execute:'
+    |savedTranscript collector expected|
+
+    savedTranscript := Smalltalk at:#Transcript.     
+    [
+        Smalltalk at:#Transcript put:(collector := '' writeStream).
+
+        self 
+            execute:'
 execute() {
     function foo()
     {
@@ -1419,10 +1447,27 @@
     test();
 }
 '
-        for:nil
-        arguments:#()
-        expect:nil
-
+            for:nil
+            arguments:#()
+            expect:nil
+    ] ensure:[
+        Smalltalk at:#Transcript put:savedTranscript
+    ].
+
+    expected := String streamContents:[:s | 
+                    s showCR:'foo called'.
+                    s showCR:'bar called'.
+                    9 timesRepeat:[
+                        s showCR:'bla called'.
+                        s showCR:'bla called'.
+                        s showCR:'bla called'.
+                        s showCR:'bla called'.
+                        s showCR:'hello'.
+                    ].
+                    s showCR:'bbb'.
+                ].
+    self assert:(collector contents = expected).
+    
     "
      self run:#testVarDeclaration08
      self new testVarDeclaration08
@@ -4899,23 +4944,36 @@
 !
 
 testTryCatchExceptionInfo
-    self 
-        execute:'test(arg) {
-                    var handlerWasCalled = false;
-
-                    function failingMethod() {  return 10 / arg; };
-
-                    try {
-                        failingMethod();
-                    } catch (Error e) {
-                        println(e.description());
-                        handlerWasCalled = true;
-                    }
-                    return handlerWasCalled;    
-                 }'
-        for:JavaScriptEnvironment new
-        arguments:#(0)
-        expect:true
+    |savedTranscript collector expected|
+
+    savedTranscript := Smalltalk at:#Transcript.     
+    [
+        Smalltalk at:#Transcript put:(collector := '' writeStream).
+
+        self 
+            execute:'
+test(arg) {
+    var handlerWasCalled = false;
+
+    function failingMethod() {  return 10 / arg; };
+
+    try {
+        failingMethod();
+    } catch (Error e) {
+        println(e.description());
+        handlerWasCalled = true;
+    }
+    return handlerWasCalled;    
+}'
+            for:JavaScriptEnvironment new
+            arguments:#(0)
+            expect:true.
+    ] ensure:[
+        Smalltalk at:#Transcript put:savedTranscript
+    ].
+
+    expected := String streamContents:[:s | s showCR:'division by zero'].
+    self assert:(collector contents = expected).
 
     "
      self run:#testTryCatchExceptionInfo
@@ -4925,26 +4983,27 @@
 
 testTryCatchFinally01
     self 
-        execute:'test(arg) {
-                    var handlerWasCalled = false;
-                    var finallyExecuted = false;
-
-                    function failingMethod() {  return 10 / arg; };
-                    function exceptionRaised() {  handlerWasCalled =  true; };
-
-                    try {
-                        failingMethod();
-                    } catch (Error e) {
-                        exceptionRaised();
-                    } finally {
-                        finallyExecuted = true;
-                    }
-                    return handlerWasCalled && finallyExecuted;    
-                 }'
-        for:nil
-        arguments:#(0)
-        expect:true
-
+            execute:
+'test(arg) {
+    var handlerWasCalled = false;
+    var finallyExecuted = false;
+
+    function failingMethod() {  return 10 / arg; };
+    function exceptionRaised() {  handlerWasCalled =  true; };
+
+    try {
+        failingMethod();
+    } catch (Error e) {
+        exceptionRaised();
+    } finally {
+        finallyExecuted = true;
+    }
+    return handlerWasCalled && finallyExecuted;    
+}'
+            for:nil
+            arguments:#(0)
+            expect:true.
+    
     "
      self run:#testTryCatchFinally01
      self new testTryCatchFinally01
@@ -4952,34 +5011,54 @@
 !
 
 testTryFinally01
-    self 
-        execute:'test(arg) {
-                    var handlerWasCalled = false;
-
-                    println("1");
-                    try {    
-                        function dummy () {
-                            println("2a");
-                            try {
-                                println("2b");
-                                return 10 / arg;
-                            } finally {
-                                println("2c");
-                                handlerWasCalled = true;
-                            }
-                        };
-
-                        println("2");
-                        dummy();
-                        println("3");
-                    } catch(Error);
-
-                    println("4");
-                    return handlerWasCalled;
-                 }'
-        for:JavaScriptEnvironment new
-        arguments:#(0)
-        expect:true
+    |savedTranscript collector expected|
+
+    savedTranscript := Smalltalk at:#Transcript.     
+    [
+        Smalltalk at:#Transcript put:(collector := '' writeStream).
+        self 
+            execute:
+'test(arg) {
+    var handlerWasCalled = false;
+
+    println("1");
+    try {    
+        function dummy () {
+            println("2a");
+            try {
+                println("2b");
+                return 10 / arg;
+            } finally {
+                println("2c");
+                handlerWasCalled = true;
+            }
+        };
+
+        println("2");
+        dummy();
+        println("3");
+    } catch(Error);
+
+    println("4");
+    return handlerWasCalled;
+ }'
+            for:JavaScriptEnvironment new
+            arguments:#(0)
+            expect:true
+
+    ] ensure:[
+        Smalltalk at:#Transcript put:savedTranscript
+    ].
+
+    expected := String streamContents:[:s | 
+                    s showCR:'1'.
+                    s showCR:'2'.
+                    s showCR:'2a'.
+                    s showCR:'2b'.
+                    s showCR:'2c'.
+                    s showCR:'4'.
+                ].
+    self assert:(collector contents = expected).
 
     "
      self run:#testTryFinally01