Browse Source

Edge-case test.

Herby Vojčík 4 years ago
parent
commit
9a5863100a
2 changed files with 46 additions and 0 deletions
  1. 39 0
      lang/src/Compiler-Tests.js
  2. 7 0
      lang/src/Compiler-Tests.st

+ 39 - 0
lang/src/Compiler-Tests.js

@@ -1009,6 +1009,45 @@ return self;
 }; }),
 $globals.AbstractCompilerTest);
 
+$core.addMethod(
+$core.method({
+selector: "testNonLocalReturnWithCatch",
+protocol: "tests",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testNonLocalReturnWithCatch\x0a\x09self should: 'foo [ ^ 1 ] on: Error do: [ 2 ]' return: 1.\x0a\x09self should: 'foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ 2 ]' return: 1.\x0a\x09self should: 'foo [ ^ 1 ] on: Error do: [ ^ 2 ]' return: 1.\x0a\x09self should: 'foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ ^ 2 ]' return: 1.",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["should:return:"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+[$self._should_return_("foo [ ^ 1 ] on: Error do: [ 2 ]",(1))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["should:return:"]=1
+//>>excludeEnd("ctx");
+][0];
+[$self._should_return_("foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ 2 ]",(1))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["should:return:"]=2
+//>>excludeEnd("ctx");
+][0];
+[$self._should_return_("foo [ ^ 1 ] on: Error do: [ ^ 2 ]",(1))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["should:return:"]=3
+//>>excludeEnd("ctx");
+][0];
+$self._should_return_("foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ ^ 2 ]",(1));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturnWithCatch",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.AbstractCompilerTest);
+
 $core.addMethod(
 $core.method({
 selector: "testPascalCaseGlobal",

+ 7 - 0
lang/src/Compiler-Tests.st

@@ -236,6 +236,13 @@ testNonLocalReturn
 	self should: 'foo [ :x | ^ x + x ] value: 4. ^ 2' return: 8
 !
 
+testNonLocalReturnWithCatch
+	self should: 'foo [ ^ 1 ] on: Error do: [ 2 ]' return: 1.
+	self should: 'foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ 2 ]' return: 1.
+	self should: 'foo [ ^ 1 ] on: Error do: [ ^ 2 ]' return: 1.
+	self should: 'foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ ^ 2 ]' return: 1.
+!
+
 testPascalCaseGlobal
 	self should: 'foo ^Object' return: (Smalltalk globals at: 'Object').
 	self should: 'foo ^NonExistent' return: nil