1
0
Fork 0

Made property member builder tests more specific to ensure that properties are not copied to multiple prototypes

closure/master
Mike Gerwitz 2011-01-20 22:19:06 -05:00
parent a58b7989ee
commit f25ae7cb43
1 changed files with 42 additions and 13 deletions

View File

@ -27,7 +27,7 @@ var common = require( './common' ),
buildProp = common.require( 'member_builder' ).buildProp
// member visibility types are quoted because they are reserved keywords
members = { 'public': {}, 'protected': {}, 'private': {} },
members = {},
meta = {},
// stub values
@ -43,18 +43,47 @@ function buildPropQuick( keywords )
{
keywords = keywords || {};
// clear out the members for a fresh start
members = { 'public': {}, 'protected': {}, 'private': {} };
return buildProp( members, meta, name, value, keywords );
}
/**
* Asserts that the given property exists only in the prototype for the
* requested visibility
*/
function assertOnlyVisibility( vis, name, value, message )
{
var check = [ 'public', 'protected', 'private' ],
i = check.length,
visi = '',
cmp;
// forEach not used for pre-ES5 browser support
while ( i-- )
{
visi = check[ i ];
cmp = ( visi === vis ) ? value : undefined;
assert.equal(
members[ visi ][ name ],
cmp,
message
);
}
}
( function testRecognizesPublicProperty()
{
buildPropQuick( { 'public': true } );
assert.equal(
members[ 'public' ][ name ],
assertOnlyVisibility( 'public',
name,
value,
"Public properties are copied to the public member prototype"
"Public properties are copied only to the public member prototype"
);
} )();
@ -63,10 +92,10 @@ function buildPropQuick( keywords )
{
buildPropQuick( { 'protected': true } );
assert.equal(
members[ 'protected' ][ name ],
assertOnlyVisibility( 'protected',
name,
value,
"Protected properties are copied to the protected member prototype"
"Protected properties are copied only to the protected member prototype"
);
} )();
@ -75,10 +104,10 @@ function buildPropQuick( keywords )
{
buildPropQuick( { 'private': true } );
assert.equal(
members[ 'private' ][ name ],
assertOnlyVisibility( 'private',
name,
value,
"Private properties are copied to the private member prototype"
"Private properties are copied only to the private member prototype"
);
} )();
@ -87,10 +116,10 @@ function buildPropQuick( keywords )
{
buildPropQuick();
assert.equal(
members[ 'public' ][ name ],
assertOnlyVisibility( 'public',
name,
value,
"Properties are copied to the public member prototype by default"
"Properties are copied only to the public member prototype by default"
);
} )();