PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at2dist170907/test/edu/vub/at/objects/natives/EscapeTest.java

http://ambienttalk.googlecode.com/
Java | 49 lines | 32 code | 12 blank | 5 comment | 0 complexity | 20acbdb880061d2e08805eda7f8b529b MD5 | raw file
 1package edu.vub.at.objects.natives;
 2
 3import edu.vub.at.AmbientTalkTest;
 4import edu.vub.at.exceptions.XIllegalOperation;
 5
 6/**
 7 * The purpose of this class is to test the escape() primitive method of block closures.
 8 * 
 9 * @author tvcutsem
10 */
11public class EscapeTest extends AmbientTalkTest {
12
13	public static void main(String[] args) {
14		junit.swingui.TestRunner.run(EscapeTest.class);
15	}
16	
17	public void testNominalCase() {
18		evalAndCompareTo("{ |quit| 1 + 2; quit(3 + 4); 1/0 }.escape()", "7");
19	}
20	
21	public void testNominalNilCase() {
22		evalAndCompareTo("{ |quit| 1 + 2; quit(); 1/0 }.escape()", "nil");
23	}
24	
25	public void testNestedCase() {
26		evalAndCompareTo("{ |quit1| 1 + 2; { |quit2| quit1(3 + 4); 1/0 }.escape() ; 1/0 }.escape()", "7");
27	}
28	
29	public void testDeepEscapeCase() {
30		evalAndCompareTo("{ |quit| def foo(q) { bar(q); 1 }; def bar(q) { q(41); 2 }; foo(quit) }.escape() + 1", "42");
31	}
32	
33	public void testNotInvokedCase() {
34		evalAndCompareTo("{ |quit| 1 + 2; 3 + 4; 5 + 6 }.escape()", "11");
35	}
36	
37	public void testFaultyCase() {
38		evalAndTestException("def temp := nil; { |quit| temp := quit }.escape(); temp(5)", XIllegalOperation.class);
39	}
40	
41	public void testFaultySelfEvalCase() {
42		evalAndTestException("({ |quit| quit }.escape())()", XIllegalOperation.class);
43	}
44	
45	public void testFaultyNestedCase() {
46		evalAndTestException("def temp := nil; { |quit| { |quit2| temp := quit2; quit() }.escape() }.escape(); temp()", XIllegalOperation.class);
47	}
48
49}