Made property member builder tests more specific to ensure that properties are not copied to multiple prototypes
parent
a58b7989ee
commit
f25ae7cb43
|
@ -27,7 +27,7 @@ var common = require( './common' ),
|
||||||
buildProp = common.require( 'member_builder' ).buildProp
|
buildProp = common.require( 'member_builder' ).buildProp
|
||||||
|
|
||||||
// member visibility types are quoted because they are reserved keywords
|
// member visibility types are quoted because they are reserved keywords
|
||||||
members = { 'public': {}, 'protected': {}, 'private': {} },
|
members = {},
|
||||||
meta = {},
|
meta = {},
|
||||||
|
|
||||||
// stub values
|
// stub values
|
||||||
|
@ -43,18 +43,47 @@ function buildPropQuick( keywords )
|
||||||
{
|
{
|
||||||
keywords = keywords || {};
|
keywords = keywords || {};
|
||||||
|
|
||||||
|
// clear out the members for a fresh start
|
||||||
|
members = { 'public': {}, 'protected': {}, 'private': {} };
|
||||||
|
|
||||||
return buildProp( members, meta, name, value, keywords );
|
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()
|
( function testRecognizesPublicProperty()
|
||||||
{
|
{
|
||||||
buildPropQuick( { 'public': true } );
|
buildPropQuick( { 'public': true } );
|
||||||
|
|
||||||
assert.equal(
|
assertOnlyVisibility( 'public',
|
||||||
members[ 'public' ][ name ],
|
name,
|
||||||
value,
|
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 } );
|
buildPropQuick( { 'protected': true } );
|
||||||
|
|
||||||
assert.equal(
|
assertOnlyVisibility( 'protected',
|
||||||
members[ 'protected' ][ name ],
|
name,
|
||||||
value,
|
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 } );
|
buildPropQuick( { 'private': true } );
|
||||||
|
|
||||||
assert.equal(
|
assertOnlyVisibility( 'private',
|
||||||
members[ 'private' ][ name ],
|
name,
|
||||||
value,
|
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();
|
buildPropQuick();
|
||||||
|
|
||||||
assert.equal(
|
assertOnlyVisibility( 'public',
|
||||||
members[ 'public' ][ name ],
|
name,
|
||||||
value,
|
value,
|
||||||
"Properties are copied to the public member prototype by default"
|
"Properties are copied only to the public member prototype by default"
|
||||||
);
|
);
|
||||||
} )();
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue