@@ -17,6 +17,11 @@ var toLowerCase = callBound('String.prototype.toLowerCase');
17
17
var isProto = callBound ( 'Object.prototype.isPrototypeOf' ) ;
18
18
var $test = callBound ( 'RegExp.prototype.test' ) ;
19
19
var 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' ) ;
20
25
21
26
module . exports = Test ;
22
27
@@ -128,7 +133,7 @@ Test.prototype.run = function () {
128
133
Test . prototype . test = function ( name , opts , cb ) {
129
134
var self = this ;
130
135
var t = new Test ( name , opts , cb ) ;
131
- this . _progeny . push ( t ) ;
136
+ $push ( this . _progeny , t ) ;
132
137
this . pendingCount ++ ;
133
138
this . emit ( 'test' , t ) ;
134
139
t . on ( 'prerun' , function ( ) {
@@ -150,8 +155,8 @@ Test.prototype.test = function (name, opts, cb) {
150
155
151
156
Test . prototype . comment = function ( msg ) {
152
157
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 * / , '' ) ) ;
155
160
} ) ;
156
161
} ;
157
162
@@ -191,7 +196,7 @@ Test.prototype._end = function (err) {
191
196
if ( ! this . _cb && ! this . _todo && ! this . _skip ) this . fail ( '# TODO ' + this . name ) ;
192
197
193
198
if ( this . _progeny . length ) {
194
- var t = this . _progeny . shift ( ) ;
199
+ var t = $shift ( this . _progeny ) ;
195
200
t . on ( 'end' , function ( ) { self . _end ( ) ; } ) ;
196
201
t . run ( ) ;
197
202
return ;
@@ -266,7 +271,7 @@ Test.prototype._assert = function assert(ok, opts) {
266
271
267
272
if ( ! ok ) {
268
273
var e = new Error ( 'exception' ) ;
269
- var err = ( e . stack || '' ) . split ( '\n' ) ;
274
+ var err = $split ( e . stack || '' , '\n' ) ;
270
275
var dir = __dirname + path . sep ;
271
276
272
277
for ( var i = 0 ; i < err . length ; i ++ ) {
@@ -306,23 +311,23 @@ Test.prototype._assert = function assert(ok, opts) {
306
311
/((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?/
307
312
*/
308
313
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' ) ;
310
315
var m = re . exec ( lineWithTokens ) ;
311
316
312
317
if ( ! m ) {
313
318
continue ;
314
319
}
315
320
316
321
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 ) ;
318
323
319
- if ( filePath . slice ( 0 , dir . length ) === dir ) {
324
+ if ( $strSlice ( filePath , 0 , dir . length ) === dir ) {
320
325
continue ;
321
326
}
322
327
323
328
// Function call description may not (just) be a function name.
324
329
// 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 ] ;
326
331
res . file = filePath ;
327
332
res . line = Number ( m [ 3 ] ) ;
328
333
if ( m [ 4 ] ) res . column = Number ( m [ 4 ] ) ;
@@ -610,12 +615,12 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
610
615
var keys = Object . keys ( expected ) ;
611
616
// Special handle errors to make sure the name and the message are compared as well.
612
617
if ( expected instanceof Error ) {
613
- keys . push ( 'name' , 'message' ) ;
618
+ $ push( keys , 'name' , 'message' ) ;
614
619
} else if ( keys . length === 0 ) {
615
620
throw new TypeError ( '`throws` validation object must not be empty' ) ;
616
621
}
617
622
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 ] ) ) {
619
624
return true ;
620
625
}
621
626
if ( key in caught . error && deepEqual ( caught . error [ key ] , expected [ key ] , { strict : true } ) ) {
0 commit comments