[#25] Began moving test-class_builder-visibility over to new test case format
parent
de78a472f0
commit
48dbfea990
|
@ -32,55 +32,62 @@ var common = require( './common' ),
|
||||||
// dependencies should not be necessary for testing
|
// dependencies should not be necessary for testing
|
||||||
ClassBuilder = common.require( '/ClassBuilder' ),
|
ClassBuilder = common.require( '/ClassBuilder' ),
|
||||||
MethodWrapperFactory = common.require( '/MethodWrapperFactory' ),
|
MethodWrapperFactory = common.require( '/MethodWrapperFactory' ),
|
||||||
wrappers = common.require( '/MethodWrappers' ).standard,
|
wrappers = common.require( '/MethodWrappers' ).standard
|
||||||
|
|
||||||
builder = ClassBuilder(
|
|
||||||
common.require( '/MemberBuilder' )(
|
|
||||||
MethodWrapperFactory( wrappers.wrapNew ),
|
|
||||||
MethodWrapperFactory( wrappers.wrapOverride )
|
|
||||||
),
|
|
||||||
common.require( '/VisibilityObjectFactoryFactory' ).fromEnvironment()
|
|
||||||
)
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
/**
|
require( 'common' ).testCase(
|
||||||
* As discussed in GH#15, there's a bit of an issue when passing around 'this'
|
|
||||||
* from within a method. For example, passing 'this' as an argument or invoking
|
|
||||||
* a method with it as the context will effectively defeat encapsulation.
|
|
||||||
* Unfortunately, there's really no way around that. Maybe a more elegant
|
|
||||||
* solution will arise in the future. For now, not likely.
|
|
||||||
*
|
|
||||||
* We need to provide a means to reference the actual instance. __inst is that
|
|
||||||
* solution.
|
|
||||||
*/
|
|
||||||
( function testSelfPropertyReferencesInstanceRatherThanPropObj()
|
|
||||||
{
|
{
|
||||||
var result = null
|
setUp: function()
|
||||||
ref = null,
|
|
||||||
|
|
||||||
foo = builder.build( {
|
|
||||||
'public __construct': function()
|
|
||||||
{
|
|
||||||
// rather than returning, assign to external var so that we can
|
|
||||||
// rest assured that the return value wasn't manipulated
|
|
||||||
result = this.__inst;
|
|
||||||
ref = this;
|
|
||||||
}
|
|
||||||
} )();
|
|
||||||
|
|
||||||
assert.deepEqual( result, foo,
|
|
||||||
"this.__inst returns reference to actual instance"
|
|
||||||
);
|
|
||||||
|
|
||||||
// the property should be read-only
|
|
||||||
if ( util.definePropertyFallback() === false )
|
|
||||||
{
|
{
|
||||||
assert.equal(
|
this.builder = ClassBuilder(
|
||||||
Object.getOwnPropertyDescriptor( ref, '__inst' ).writable,
|
this.require( '/MemberBuilder' )(
|
||||||
false,
|
MethodWrapperFactory( wrappers.wrapNew ),
|
||||||
"this.__inst is not writable"
|
MethodWrapperFactory( wrappers.wrapOverride )
|
||||||
|
),
|
||||||
|
this.require( '/VisibilityObjectFactoryFactory' ).fromEnvironment()
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
} )();
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As discussed in GH#15, there's a bit of an issue when passing around
|
||||||
|
* 'this' from within a method. For example, passing 'this' as an argument
|
||||||
|
* or invoking a method with it as the context will effectively defeat
|
||||||
|
* encapsulation. Unfortunately, there's really no way around that. Maybe a
|
||||||
|
* more elegant solution will arise in the future. For now, not likely.
|
||||||
|
*
|
||||||
|
* We need to provide a means to reference the actual instance. __inst is
|
||||||
|
* that solution.
|
||||||
|
*/
|
||||||
|
'Self property references instance rather than property object': function()
|
||||||
|
{
|
||||||
|
var result = null
|
||||||
|
ref = null,
|
||||||
|
|
||||||
|
foo = this.builder.build( {
|
||||||
|
'public __construct': function()
|
||||||
|
{
|
||||||
|
// rather than returning, assign to external var so that we can
|
||||||
|
// rest assured that the return value wasn't manipulated
|
||||||
|
result = this.__inst;
|
||||||
|
ref = this;
|
||||||
|
}
|
||||||
|
} )();
|
||||||
|
|
||||||
|
this.assertDeepEqual( result, foo,
|
||||||
|
"this.__inst returns reference to actual instance"
|
||||||
|
);
|
||||||
|
|
||||||
|
// the property should be read-only
|
||||||
|
if ( util.definePropertyFallback() === false )
|
||||||
|
{
|
||||||
|
assert.equal(
|
||||||
|
Object.getOwnPropertyDescriptor( ref, '__inst' ).writable,
|
||||||
|
false,
|
||||||
|
"this.__inst is not writable"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue