From 08cb663833bacc6b09a28f79675702b03d434ee1 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 29 Oct 2011 10:08:08 -0400 Subject: [PATCH] [#25] Refactored quickVisChangeTest to share code between each of the member test cases --- test/MemberBuilderValidator/MethodTest.js | 41 +++++++-------------- test/MemberBuilderValidator/PropertyTest.js | 39 ++++++-------------- test/MemberBuilderValidator/inc-common.js | 41 +++++++++++++++++++++ 3 files changed, 67 insertions(+), 54 deletions(-) diff --git a/test/MemberBuilderValidator/MethodTest.js b/test/MemberBuilderValidator/MethodTest.js index bd3473e..9db0bc5 100644 --- a/test/MemberBuilderValidator/MethodTest.js +++ b/test/MemberBuilderValidator/MethodTest.js @@ -44,34 +44,21 @@ require( 'common' ).testCase( this.quickVisChangeTest = function( start, override, failtest ) { - var name = 'foo', + shared.quickVisChangeTest.call( _self, start, override, failtest, + function( name, startobj, overrideobj ) + { + startobj.virtual = true; + overrideobj.override = true; - startobj = { 'virtual': true }, - overrideobj = { 'override': true } - ; - - startobj[ start ] = true; - overrideobj[ override ] = true; - - var testfun = function() - { - _self.sut.validateMethod( - name, - function() {}, - overrideobj, - { member: function() {} }, - startobj - ); - }; - - if ( failtest ) - { - this.quickFailureTest( name, 'de-escalate', testfun ); - } - else - { - _self.assertDoesNotThrow( testfun, Error ); - } + _self.sut.validateMethod( + name, + function() {}, + overrideobj, + { member: function() {} }, + startobj + ); + } + ); }; }, diff --git a/test/MemberBuilderValidator/PropertyTest.js b/test/MemberBuilderValidator/PropertyTest.js index a297c99..6af3675 100644 --- a/test/MemberBuilderValidator/PropertyTest.js +++ b/test/MemberBuilderValidator/PropertyTest.js @@ -29,6 +29,8 @@ require( 'common' ).testCase( { caseSetUp: function() { + var _self = this; + this.quickFailureTest = shared.quickFailureTest; this.quickKeywordPropTest = function( keywords, identifier, prev ) @@ -40,33 +42,16 @@ require( 'common' ).testCase( this.quickVisChangeTest = function( start, override, failtest ) { - var _self = this, - name = 'foo', - - startobj = {}, - overrideobj = {} - ; - - startobj[ start ] = true; - overrideobj[ override ] = true; - - var testfun = function() - { - _self.sut.validateProperty( - name, 'bar', overrideobj, - { member: 'foo' }, - startobj - ); - }; - - if ( failtest ) - { - this.quickFailureTest( name, 'de-escalate', testfun ); - } - else - { - _self.assertDoesNotThrow( testfun, Error ); - } + shared.quickVisChangeTest.call( _self, start, override, failtest, + function( name, startobj, overrideobj ) + { + _self.sut.validateProperty( + name, 'bar', overrideobj, + { member: 'foo' }, + startobj + ); + } + ); }; }, diff --git a/test/MemberBuilderValidator/inc-common.js b/test/MemberBuilderValidator/inc-common.js index 27adc0c..ec0e612 100644 --- a/test/MemberBuilderValidator/inc-common.js +++ b/test/MemberBuilderValidator/inc-common.js @@ -147,3 +147,44 @@ exports.visEscalationTest = function( test ) } }; + +/** + * Performs a simple visibility change test using access modifiers + * + * Important: invoke within the context of the test case. + * + * @param {string} start start keyword + * @param {string} override overriding keyword + * @param {bool} failtest whether the assertion should test for failure + * + * @param {function()} func test function + * + * @return {undefined} + */ +exports.quickVisChangeTest = function( start, override, failtest, func ) +{ + var _self = this, + name = 'foo', + + startobj = {}, + overrideobj = {} + ; + + startobj[ start ] = true; + overrideobj[ override ] = true; + + var testfun = function() + { + func( name, startobj, overrideobj ); + }; + + if ( failtest ) + { + this.quickFailureTest( name, 'de-escalate', testfun ); + } + else + { + _self.assertDoesNotThrow( testfun, Error ); + } +}; +