/interpreter/tags/at2dist030708/test/edu/vub/at/AmbientTalkTestCase.java
Java | 82 lines | 46 code | 16 blank | 20 comment | 0 complexity | dd7322f1a32fc5aab6e42ad0163d444a MD5 | raw file
1package edu.vub.at; 2 3import edu.vub.at.exceptions.InterpreterException; 4import edu.vub.at.exceptions.XParseError; 5import edu.vub.at.objects.ATAbstractGrammar; 6import edu.vub.at.objects.ATClosure; 7import edu.vub.at.objects.ATContext; 8import edu.vub.at.objects.ATObject; 9import edu.vub.at.objects.ATTable; 10import edu.vub.at.objects.mirrors.NativeClosure; 11import edu.vub.at.objects.natives.NATContext; 12import edu.vub.at.objects.natives.NATNumber; 13import edu.vub.at.objects.natives.NATObject; 14import edu.vub.at.objects.natives.NATText; 15import edu.vub.at.objects.natives.grammar.AGSymbol; 16import edu.vub.at.parser.NATParser; 17 18import junit.framework.TestCase; 19 20 21public class AmbientTalkTestCase extends TestCase { 22 23 protected ATContext ctx_ = null; 24 25 protected ATClosure unittest_ = new NativeClosure(null) { 26 public ATObject base_apply(ATTable arguments) throws InterpreterException { 27 ATClosure body = arguments.base_at(NATNumber.ONE).asClosure(); 28 return OBJUnit._INSTANCE_.base_unittest_(body); 29 }; 30 }; 31 32 protected void evaluateInput(String input, ATContext ctx) throws InterpreterException { 33 try { 34 ATAbstractGrammar ag = NATParser._INSTANCE_.base_parse(NATText.atValue(input)); 35 36 // Evaluate the corresponding tree of ATAbstractGrammar objects 37 ag.meta_eval(ctx); 38 } catch(XParseError e) { 39 e.printStackTrace(); 40 fail("exception: "+e); 41 } 42 } 43 44 protected void setUp() throws Exception { 45 ATObject root = new NATObject(); // object with no dyn or lex parent 46 ATObject supr = new NATObject(root); // supr has root as lex parent 47 ATObject self = new NATObject(supr, root, NATObject._SHARES_A_); // self has root as lex parent and supr as dyn parent 48 ATObject scope = new NATObject(self); // scope has no dyn parent and is nested within self 49 50 51 self.meta_defineField(AGSymbol.jAlloc("unittest:"), unittest_); 52 53 self.meta_defineField(AGSymbol.jAlloc("unit"), OBJUnit._INSTANCE_); 54 55 ctx_ = new NATContext(scope, self); 56 } 57 58 protected void tearDown() throws Exception { 59 ctx_ = null; 60 } 61 62// public void testUnitTestFramework() { 63// try { 64// evaluateInput("unit.fail: \"This test should fail.\"", ctx_); 65// } catch (NATException e) { 66// fail("exception : " + e); 67// } catch (AssertionFailedError e) { 68// // ok. this test is supposed to fail 69// } 70// 71// try { 72// evaluateInput("unittest: { self.fail: \"This test should fail.\" }", ctx_); 73// } catch (NATException e) { 74// e.printStackTrace(); 75// fail("exception : " + e); 76// } catch (AssertionFailedError e) { 77// // ok. this test is supposed to fail 78// } 79// 80// } 81 82}