File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 5
5
* @param {Function } fn The function to stringify
6
6
*/
7
7
function normalizedFunctionString ( fn ) {
8
- return fn . toString ( ) . replace ( ' function(' , 'function (' ) ;
8
+ return fn . toString ( ) . replace ( / f u n c t i o n ( . * ) \( / , 'function (' ) ;
9
9
}
10
10
11
11
module . exports = {
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ var Buffer = require('buffer').Buffer,
22
22
vm = require ( 'vm' ) ;
23
23
24
24
var createBSON = require ( '../utils' ) ;
25
+ const normalizedFunctionString = require ( '../../lib/bson/parser/utils' ) . normalizedFunctionString ;
25
26
26
27
// for tests
27
28
BSON . BSON_BINARY_SUBTYPE_DEFAULT = 0 ;
@@ -2346,4 +2347,17 @@ describe('BSON', function() {
2346
2347
2347
2348
expect ( bufferRaw ) . to . deep . equal ( uint8ArrayRaw ) ;
2348
2349
} ) ;
2350
+
2351
+ it ( 'Should normalize variations of the same function to the same string' , function ( ) {
2352
+ const testObj = { test : function ( ) { } , test2 : function test2 ( ) { } } ;
2353
+ const testFuncs = [
2354
+ function ( ) { } ,
2355
+ function func ( ) { } ,
2356
+ function fUnCtIoN ( ) { } ,
2357
+ testObj [ 'test' ] ,
2358
+ testObj [ 'test2' ]
2359
+ ] ;
2360
+ const expectedString = 'function () {}' ;
2361
+ testFuncs . forEach ( fn => expect ( normalizedFunctionString ( fn ) ) . to . equal ( expectedString ) ) ;
2362
+ } ) ;
2349
2363
} ) ;
You can’t perform that action at this time.
0 commit comments