1
0
Fork 0

[#25] Began converting test-class_builder-const to test case

- Not yet renaming, as the conversion is not yet complete
closure/master
Mike Gerwitz 2011-11-02 19:11:12 -04:00
parent a0ba2feb33
commit 110d937838
1 changed files with 112 additions and 107 deletions

View File

@ -23,56 +23,60 @@
*/ */
var common = require( './common' ), var common = require( './common' ),
assert = require( 'assert' ),
// XXX: get rid of this disgusting mess; we're mid-refactor and all these // XXX: get rid of this disgusting mess; we're mid-refactor and all these
// 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( require( 'common' ).testCase(
common.require( '/MemberBuilder' )( {
setUp: function()
{
this.builder = ClassBuilder(
this.require( '/MemberBuilder' )(
MethodWrapperFactory( wrappers.wrapNew ), MethodWrapperFactory( wrappers.wrapNew ),
MethodWrapperFactory( wrappers.wrapOverride ) MethodWrapperFactory( wrappers.wrapOverride )
), ),
common.require( '/VisibilityObjectFactoryFactory' ).fromEnvironment() this.require( '/VisibilityObjectFactoryFactory' ).fromEnvironment()
) )
; },
/** /**
* The const keyword should result in a static property. The rationale for this * The const keyword should result in a static property. The rationale for this
* is that, if a value is constant, then instances do not make sense. * is that, if a value is constant, then instances do not make sense.
*/ */
( function testConstKeywordDeclaresPropertiesAsStatic() 'const keyword declares properties as static': function()
{ {
var val = 'baz', var val = 'baz',
Foo = builder.build( Foo = this.builder.build(
{ {
'const foo': val, 'const foo': val,
} ) } )
; ;
assert.equal( val, Foo.$('foo'), this.assertEqual( val, Foo.$('foo'),
"Const keyword should declare properties as static" "Const keyword should declare properties as static"
); );
} )(); },
/** /**
* As the name implies, constant properties should not be writable. * As the name implies, constant properties should not be writable.
*/ */
( function testConstKeywordCreatesImmutableProperty() 'const keyword creates immutable property': function()
{ {
try try
{ {
// this should fail (trying to alter const prop foo) // this should fail (trying to alter const prop foo)
builder.build( { 'const foo': 'bar' } ).$( 'foo', 'baz' ); this.builder.build( { 'const foo': 'bar' } ).$( 'foo', 'baz' );
} }
catch ( e ) catch ( e )
{ {
assert.ok( this.assertOk(
e.message.search( 'foo' ) !== -1, e.message.search( 'foo' ) !== -1,
"Const modification error should contain name of property" "Const modification error should contain name of property"
); );
@ -80,20 +84,20 @@ var common = require( './common' ),
return; return;
} }
assert.fail( "Constant properties should not be writable" ); this.fail( "Constant properties should not be writable" );
} )(); },
/** /**
* Unlike other languages such as PHP, the const keyword can have different * Unlike other languages such as PHP, the const keyword can have different
* levels of visibility. * levels of visibility.
*/ */
( function testVisibilityModifiersArePermittedWithConstKeyword() 'Access modifiers are permitted with const keyword': function()
{ {
var protval = 'bar', var protval = 'bar',
privval = 'baz', privval = 'baz',
Foo = builder.build( Foo = this.builder.build(
{ {
'protected const prot': protval, 'protected const prot': protval,
'private const priv': privval, 'private const priv': privval,
@ -111,7 +115,7 @@ var common = require( './common' ),
// be sure to override each method to ensure we're checking references // be sure to override each method to ensure we're checking references
// on the subtype, *not* the parent type // on the subtype, *not* the parent type
SubFoo = builder.build( Foo, SubFoo = this.builder.build( Foo,
{ {
'public static getProt': function() 'public static getProt': function()
{ {
@ -125,28 +129,29 @@ var common = require( './common' ),
} ) } )
; ;
assert.equal( Foo.$('prot'), undefined, this.assertEqual( Foo.$('prot'), undefined,
"Protected constants are not available publicly" "Protected constants are not available publicly"
); );
assert.equal( Foo.$('priv'), undefined, this.assertEqual( Foo.$('priv'), undefined,
"Private constants are not available publicly" "Private constants are not available publicly"
); );
assert.equal( Foo.getProt(), protval, this.assertEqual( Foo.getProt(), protval,
"Protected constants are available internally" "Protected constants are available internally"
); );
assert.equal( Foo.getPriv(), privval, this.assertEqual( Foo.getPriv(), privval,
"Private constants are available internally" "Private constants are available internally"
); );
assert.equal( SubFoo.getProt(), protval, this.assertEqual( SubFoo.getProt(), protval,
"Protected constants are available to subtypes internally" "Protected constants are available to subtypes internally"
); );
assert.equal( SubFoo.getPriv(), undefined, this.assertEqual( SubFoo.getPriv(), undefined,
"Private constants are NOT available to subtypes internally" "Private constants are NOT available to subtypes internally"
); );
} )(); },
} );