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