@@ -17,6 +17,11 @@ var toLowerCase = callBound('String.prototype.toLowerCase');
1717var isProto = callBound ( 'Object.prototype.isPrototypeOf' ) ;
1818var $test = callBound ( 'RegExp.prototype.test' ) ;
1919var objectToString = callBound ( 'Object.prototype.toString' ) ;
20+ var $split = callBound ( 'String.prototype.split' ) ;
21+ var $replace = callBound ( 'String.prototype.replace' ) ;
22+ var $strSlice = callBound ( 'String.prototype.slice' ) ;
23+ var $push = callBound ( 'Array.prototype.push' ) ;
24+ var $shift = callBound ( 'Array.prototype.shift' ) ;
2025
2126module . exports = Test ;
2227
@@ -128,7 +133,7 @@ Test.prototype.run = function () {
128133Test . prototype . test = function ( name , opts , cb ) {
129134 var self = this ;
130135 var t = new Test ( name , opts , cb ) ;
131- this . _progeny . push ( t ) ;
136+ $push ( this . _progeny , t ) ;
132137 this . pendingCount ++ ;
133138 this . emit ( 'test' , t ) ;
134139 t . on ( 'prerun' , function ( ) {
@@ -150,8 +155,8 @@ Test.prototype.test = function (name, opts, cb) {
150155
151156Test . prototype . comment = function ( msg ) {
152157 var that = this ;
153- forEach ( trim ( msg ) . split ( '\n' ) , function ( aMsg ) {
154- that . emit ( 'result' , trim ( aMsg ) . replace ( / ^ # \s * / , '' ) ) ;
158+ forEach ( $split ( trim ( msg ) , '\n' ) , function ( aMsg ) {
159+ that . emit ( 'result' , $replace ( trim ( aMsg ) , / ^ # \s * / , '' ) ) ;
155160 } ) ;
156161} ;
157162
@@ -191,7 +196,7 @@ Test.prototype._end = function (err) {
191196 if ( ! this . _cb && ! this . _todo && ! this . _skip ) this . fail ( '# TODO ' + this . name ) ;
192197
193198 if ( this . _progeny . length ) {
194- var t = this . _progeny . shift ( ) ;
199+ var t = $shift ( this . _progeny ) ;
195200 t . on ( 'end' , function ( ) { self . _end ( ) ; } ) ;
196201 t . run ( ) ;
197202 return ;
@@ -266,7 +271,7 @@ Test.prototype._assert = function assert(ok, opts) {
266271
267272 if ( ! ok ) {
268273 var e = new Error ( 'exception' ) ;
269- var err = ( e . stack || '' ) . split ( '\n' ) ;
274+ var err = $split ( e . stack || '' , '\n' ) ;
270275 var dir = __dirname + path . sep ;
271276
272277 for ( var i = 0 ; i < err . length ; i ++ ) {
@@ -306,23 +311,23 @@ Test.prototype._assert = function assert(ok, opts) {
306311 /((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?/
307312 */
308313 var re = / ^ (?: [ ^ \s ] * \s * \b a t \s + ) (?: ( .* ) \s + \( ) ? ( (?: \/ | [ a - z A - Z ] : \\ ) [ ^ : ) ] + : ( \d + ) (?: : ( \d + ) ) ? ) \) ? $ / ;
309- var lineWithTokens = err [ i ] . replace ( process . cwd ( ) , '/$CWD' ) . replace ( __dirname , '/$TEST' ) ;
314+ var lineWithTokens = $replace ( $replace ( err [ i ] , process . cwd ( ) , '/$CWD' ) , __dirname , '/$TEST' ) ;
310315 var m = re . exec ( lineWithTokens ) ;
311316
312317 if ( ! m ) {
313318 continue ;
314319 }
315320
316321 var callDescription = m [ 1 ] || '<anonymous>' ;
317- var filePath = m [ 2 ] . replace ( '/$CWD' , process . cwd ( ) ) . replace ( '/$TEST' , __dirname ) ;
322+ var filePath = $replace ( $replace ( m [ 2 ] , '/$CWD' , process . cwd ( ) ) , '/$TEST' , __dirname ) ;
318323
319- if ( filePath . slice ( 0 , dir . length ) === dir ) {
324+ if ( $strSlice ( filePath , 0 , dir . length ) === dir ) {
320325 continue ;
321326 }
322327
323328 // Function call description may not (just) be a function name.
324329 // Try to extract function name by looking at first "word" only.
325- res . functionName = callDescription . split ( / \s + / ) [ 0 ] ;
330+ res . functionName = $ split( callDescription , / \s + / ) [ 0 ] ;
326331 res . file = filePath ;
327332 res . line = Number ( m [ 3 ] ) ;
328333 if ( m [ 4 ] ) res . column = Number ( m [ 4 ] ) ;
@@ -610,12 +615,12 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
610615 var keys = Object . keys ( expected ) ;
611616 // Special handle errors to make sure the name and the message are compared as well.
612617 if ( expected instanceof Error ) {
613- keys . push ( 'name' , 'message' ) ;
618+ $ push( keys , 'name' , 'message' ) ;
614619 } else if ( keys . length === 0 ) {
615620 throw new TypeError ( '`throws` validation object must not be empty' ) ;
616621 }
617622 passed = keys . every ( function ( key ) {
618- if ( typeof caught . error [ key ] === 'string' && isRegExp ( expected [ key ] ) && expected [ key ] . test ( caught . error [ key ] ) ) {
623+ if ( typeof caught . error [ key ] === 'string' && isRegExp ( expected [ key ] ) && $test ( expected [ key ] , caught . error [ key ] ) ) {
619624 return true ;
620625 }
621626 if ( key in caught . error && deepEqual ( caught . error [ key ] , expected [ key ] , { strict : true } ) ) {
0 commit comments