1
0
Fork 0

[#25] Refactored MemberBuilder/VisibilityTest basic tests into reusable functions for upcoming tests in other access levels

closure/master
Mike Gerwitz 2011-10-21 10:12:58 -04:00
parent bb9eb16fd3
commit f7700f93e5
1 changed files with 80 additions and 47 deletions

View File

@ -22,8 +22,15 @@
* @package test * @package test
*/ */
function buildStubMethod( name, val, visibility )
require( 'common' ).testCase(
{ {
caseSetUp: function()
{
this.buildStubMethod = function( name, val, visibility )
{
var keywords = {}; var keywords = {};
// set visibility level using access modifier // set visibility level using access modifier
@ -38,32 +45,70 @@ function buildStubMethod( name, val, visibility )
1, 1,
{} {}
); );
} };
function buildStubProp( name, val, visibility ) this.buildStubProp = function( name, val, visibility )
{ {
var keywords = {}; var keywords = {};
// set visibility level using access modifier // set visibility level using access modifier
keywords[ visibility ] = true; keywords[ visibility ] = true;
this.sut.buildProp( this.members, {}, name, val, keywords, {} ); this.sut.buildProp( this.members, {}, name, val, keywords, {} );
}
require( 'common' ).testCase(
{
caseSetUp: function()
{
this.buildStubMethod = function()
{
buildStubMethod.apply( this, arguments );
}; };
this.buildStubProp = function()
this.assertOnlyIn = function( vis, name )
{ {
buildStubProp.apply( this, arguments ); var found = false;
for ( level in this.members )
{
if ( typeof this.members[ level ][ name ] === 'undefined' )
{
continue;
}
// we found it; ensure it's in the expected visibility level
found = true;
if ( level !== vis )
{
this.fail( name + " should only be accessible in: " + vis );
}
}
found || this.fail(
"Did not find '" + name + "' in level: " + vis
);
};
this.basicVisPropTest = function( vis )
{
var name = 'pub',
val = 'val';
this.buildStubProp( name, val, vis );
this.assertEqual( this.members[ vis ][ name ][ 0 ], val );
this.assertOnlyIn( vis, name, this.members );
};
this.basicVisMethodTest = function( vis )
{
var name = 'pub',
val = 'val';
this.buildStubMethod( name, val, vis );
this.assertEqual(
this.members[ vis ][ name ](),
val
);
this.assertOnlyIn( vis, name, this.members );
}; };
}, },
@ -83,26 +128,14 @@ require( 'common' ).testCase(
}, },
'Public properties are accessible via the public interface': function() 'Public properties are accessible only via the public interface': function()
{ {
var name = 'pub', this.basicVisPropTest( 'public' );
val = 'val';
this.buildStubProp( name, val, 'public' );
this.assertEqual( this.members[ 'public' ][ name ][ 0 ], val );
}, },
'Public methods are accessible via the public interface': function() 'Public methods are accessible only via the public interface': function()
{ {
var name = 'pub', this.basicVisMethodTest( 'public' );
val = 'val';
this.buildStubMethod( name, val, 'public' );
this.assertEqual(
this.members[ 'public' ][ name ](),
val
);
}, },
} ); } );