/interpreter/tags/at_build150307/test/edu/vub/at/AmbientTalkTestCase.java

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