-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for local function exceptions in cppia
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
enum Status { | ||
Ok; | ||
Error(message:String); | ||
} | ||
|
||
class LocalFunctionExceptions { | ||
static function staticFunction() { | ||
throw 'Thrown from static'; | ||
} | ||
|
||
public static function testLocalCallingStatic():Status { | ||
function localFunction() { | ||
staticFunction(); | ||
throw 'Thrown from local'; | ||
} | ||
|
||
try { | ||
localFunction(); | ||
} catch (e:String) { | ||
if (e == 'Thrown from static') { | ||
return Ok; | ||
} else { | ||
return Error("Incorrect exception caught from local function call"); | ||
} | ||
} | ||
|
||
return Error("No exception caught"); | ||
} | ||
|
||
public static function testCatchWithinLocal():Status { | ||
function localFunction() { | ||
try { | ||
staticFunction(); | ||
} catch (e:String) { | ||
if (e == 'Thrown from static') { | ||
return Ok; | ||
} else { | ||
return Error("Incorrect exception caught from local function call"); | ||
} | ||
} | ||
return Error("Exception from static function not caught"); | ||
} | ||
|
||
return try { | ||
localFunction(); | ||
} catch (e) { | ||
Error('Exception leaked from local function: $e'); | ||
}; | ||
} | ||
|
||
public static function testCatchFromLocal():Status { | ||
function localFunction() { | ||
throw 'Thrown from local'; | ||
} | ||
|
||
try { | ||
localFunction(); | ||
} catch (e:String) { | ||
if (e == 'Thrown from local') { | ||
return Ok; | ||
} else { | ||
return Error("Incorrect exception caught from local function call"); | ||
} | ||
} | ||
|
||
return Error("No exception caught"); | ||
} | ||
} |