/interpreter/tags/at2-build060407/test/edu/vub/at/AmbientTalkTestCase.java

http://ambienttalk.googlecode.com/ · Java · 82 lines · 46 code · 16 blank · 20 comment · 0 complexity · dd7322f1a32fc5aab6e42ad0163d444a MD5 · raw file

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