edu.vub.at.objects.natives
Class NATObjectClosureTest

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byedu.vub.at.AmbientTalkTest
              extended byedu.vub.at.objects.natives.NATObjectClosureTest
All Implemented Interfaces:
junit.framework.Test

public class NATObjectClosureTest
extends AmbientTalkTest

AmbientTalk/2 is a dually scoped programming language, providing access to both the lexical scope methods and objects are defined in, as well as a dynamic scope which follows the parent chain of an object. Moreover, the language features the notion of closures and methods which have important semantic differences, and a few additional concepts. This test suite documents the proper binding semantics for variables, self and super inside methods and closures.

Author:
smostinc

Nested Class Summary
private  class NATObjectClosureTest.AGScopeTest
          This class is a special statement class used to test the correct scoping of method invocation from the java level, rather than by executing ambienttalk code directly.
 
Nested classes inherited from class edu.vub.at.AmbientTalkTest
AmbientTalkTest.Actorscript
 
Field Summary
 
Fields inherited from class edu.vub.at.AmbientTalkTest
ctx_
 
Fields inherited from class junit.framework.TestCase
 
Constructor Summary
NATObjectClosureTest()
           
 
Method Summary
static void main(java.lang.String[] args)
           
 void testDelegatedMethodInvocation()
          NATIVE TEST: Tests the validity of the various scope pointers in a context object when applying a method in a simple hierarchy of objects
 void testDelegatedMethodScope()
          AmbientTalk introduces first class delegation using the ^ symbol.
 void testExtend()
          NATIVE TEST: Makes a simple extension of an orphan object using a closure.
 void testExternalDefinitionOnIsolates()
          Since external definitions inherently are equipped access to their lexical scope, and isolates are prohibited access to any form of lexical scope so that they can be copied between actors, these mechanisms are irreconcilable.
 void testExternalMethodBindings()
          NATIVE TEST: Tests whether the definition of an external method refers to the correct bindings for: - lexically accessed variables - the value of 'self' - the value of 'super'
 void testExternalMethodScope()
          Methods can be added to an object using external method definitions.
 void testInvokeLexicallyVisibleMethod()
          When objects are lexically nested, the nested object has lexical access to the methods of the enclosing object.
 void testIsolateScope()
          Isolates are objects which have no access to variables in their lexical scope (hence their name).
 void testLexicallyInvokeInheritedMethod()
          The previous test illustrated that it is possible to perform a lexical invocation of methods in an enclosing object.
 void testMethodInvocation()
          NATIVE TEST: Tests the validity of the various scope pointers in a context object when applying a method defined in and invoked upon an orphan object
 void testNestedClosureScope()
          Closures are created when defining a function inside an object's method as well.
 void testOrphanObjectScope()
          When defining an object, the programmer can choose to create either a method or a closure.
 void testParentObjectScope()
          When defining an object, the programmer can choose to create either a method or a closure.
 
Methods inherited from class edu.vub.at.AmbientTalkTest
actorTest, evalActor, evalAndCompareTo, evalAndCompareTo, evalAndReturn, evalAndTestException, evalInActor, evalSnippet, printedEquals
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NATObjectClosureTest

public NATObjectClosureTest()
Method Detail

main

public static void main(java.lang.String[] args)

testOrphanObjectScope

public void testOrphanObjectScope()
When defining an object, the programmer can choose to create either a method or a closure. In the context of an object which is not part of a dynamic hierarchy, there is no scoping difference between both solutions: both prefer the definitions in the object to the outer lexical scope, and in this particular case, their self and super bindings are identical. Note that the next test illustrates the esential difference between closures (who capture self and super) and methods (who leave them late bound).


testParentObjectScope

public void testParentObjectScope()
When defining an object, the programmer can choose to create either a method or a closure. The fundamental difference between both is the way they treat self and super. A closure will create bindings for these variables upon creation, whereas a method leaves them late bound. This implies that the binding for self in a closure is never late bound, as this test illustrates. Note that super is statically bound in both cases.


testNestedClosureScope

public void testNestedClosureScope()
Closures are created when defining a function inside an object's method as well. This test illustrates that these closures also capture their self and super bindings at creation time. In this case, note that the closure is created only when the method is executed, yielding behaviour somewhat similar to late binding.


testInvokeLexicallyVisibleMethod

public void testInvokeLexicallyVisibleMethod()
When objects are lexically nested, the nested object has lexical access to the methods of the enclosing object. This test method illustrates that such a lexical invocation is equivalent to a direct invocation on the enclosing object, with respect to the bindings for the self and super variables. Design Principle : through lexical access the self binding cannot be set to objects which are not part of the dynamic object chain.


testLexicallyInvokeInheritedMethod

public void testLexicallyInvokeInheritedMethod()
The previous test illustrated that it is possible to perform a lexical invocation of methods in an enclosing object. This test tries to perform a similar feat, yet calls a method which is not defined by the enclosing object, but by its parent. This invocation will fail. Design Principle : lexical invocation is strictly limited to methods and closures which are lexically visible.


testDelegatedMethodScope

public void testDelegatedMethodScope()
AmbientTalk introduces first class delegation using the ^ symbol. This feature ensures that the self of a message is late bound. This test illustrates the late binding of self for delegated invocations, as opposed to oridinary invocations.


testExternalMethodScope

public void testExternalMethodScope()
Methods can be added to an object using external method definitions. These definitions provide access to the dynamic parent chain of objects, as any normal method would. The difference is that the external method has access to its own lexical scope and not to the one of the object it is being inserted to. Design Principle: self and super in an external methods are confined to the dynamich inheritance chain of the object they are being inserted to, and are subject to the same constraints as those bindings in internal methods. Design Principle: Methods (including external ones) have unqualified access to their surrounding lexical scope, and to this scope only.


testIsolateScope

public void testIsolateScope()
Isolates are objects which have no access to variables in their lexical scope (hence their name). This kind of object can thus be safely passed by copy to another actor. This test method illustrates that isolates have no access to their lexical but that they can access copies of outlying variables using ad hoc syntax.


testExternalDefinitionOnIsolates

public void testExternalDefinitionOnIsolates()
Since external definitions inherently are equipped access to their lexical scope, and isolates are prohibited access to any form of lexical scope so that they can be copied between actors, these mechanisms are irreconcilable. Design Principle: Isolates are sealed and can not be extended with externnaly defined fields or methods.


testMethodInvocation

public void testMethodInvocation()
NATIVE TEST: Tests the validity of the various scope pointers in a context object when applying a method defined in and invoked upon an orphan object. - covers meta_invoke & meta_select for method lookup - covers closure creation in meta_select - covers context initialisation at closure creation - covers closure application


testDelegatedMethodInvocation

public void testDelegatedMethodInvocation()
NATIVE TEST: Tests the validity of the various scope pointers in a context object when applying a method in a simple hierarchy of objects. - covers meta_invoke & meta_select for method lookup with dynamic chains - covers proper self semantics at closure creation - covers super semantics during method application


testExtend

public void testExtend()
NATIVE TEST: Makes a simple extension of an orphan object using a closure. Tests the correct scoping of methods with objects created using meta_extend - covers meta_extend for object extension. - covers method definition using AGDefMethod


testExternalMethodBindings

public void testExternalMethodBindings()
                                throws InterpreterException
NATIVE TEST: Tests whether the definition of an external method refers to the correct bindings for: - lexically accessed variables - the value of 'self' - the value of 'super'

Throws:
InterpreterException