Add typed exception unit tests
This commit is contained in:
		
							
								
								
									
										21
									
								
								unittests/exception_typed.chai
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								unittests/exception_typed.chai
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| auto x = 1 | ||||
| try { | ||||
|   throw(x) | ||||
|   x = 2 | ||||
| } | ||||
| catch(int e) { | ||||
|   x = e + 3 | ||||
| } | ||||
| assert_equal(4, x); | ||||
|  | ||||
| x = 1 | ||||
| try { | ||||
|   throw(x) | ||||
|   x = 2 | ||||
| } | ||||
| catch(string e) { | ||||
| } | ||||
| catch(e) { | ||||
|   x = e + 4 | ||||
| } | ||||
| assert_equal(5, x); | ||||
							
								
								
									
										34
									
								
								unittests/exception_typed_2.chai
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								unittests/exception_typed_2.chai
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| auto results = []; | ||||
|  | ||||
| for (auto i = 2; i < 6; ++i) { | ||||
|   try { | ||||
|     throw(i) | ||||
|   } | ||||
|   catch(int e) : e < 2 { | ||||
|     results.push_back("c1: " + e.to_string()); | ||||
|   } | ||||
|   catch(int e) : e < 4 { | ||||
|     results.push_back("c2: " + e.to_string()); | ||||
|   } | ||||
|   catch(e) { | ||||
|     results.push_back("c3: " + e.to_string()); | ||||
|   } | ||||
|   catch { | ||||
|     // Should never get called | ||||
|     assert_equal(false, true) | ||||
|   } | ||||
| } | ||||
|  | ||||
| try { | ||||
|   throw(3) | ||||
| } | ||||
| catch(int e) : e < 3  | ||||
| { | ||||
|   // Should never get called | ||||
|   assert_equal(false, true); | ||||
| } | ||||
| catch { | ||||
|   results.push_back("defaultcatch"); | ||||
| } | ||||
|  | ||||
| assert_equal(["c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"], results); | ||||
		Reference in New Issue
	
	Block a user
	 Jason Turner
					Jason Turner