|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2018 The Stdlib Authors. |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
5 | 5 | *
|
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | 7 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | // MODULES //
|
22 | 22 |
|
23 | 23 | var tape = require( 'tape' );
|
24 |
| -var proxyquire = require( 'proxyquire' ); |
25 |
| -var Int8Array = require( '@stdlib/array-int8' ); |
26 |
| -var Buffer = require( '@stdlib/buffer-ctor' ); |
27 |
| -var Number = require( '@stdlib/number-ctor' ); |
28 |
| -var Boolean = require( '@stdlib/boolean-ctor' ); |
29 |
| -var Fcn = require( '@stdlib/function-ctor' ); |
30 |
| -var functionName = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
31 | 25 |
|
32 | 26 |
|
33 | 27 | // TESTS //
|
34 | 28 |
|
35 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
36 | 30 | t.ok( true, __filename );
|
37 |
| - t.strictEqual( typeof functionName, 'function', 'export is a function' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
38 | 32 | t.end();
|
39 | 33 | });
|
40 |
| - |
41 |
| -tape( 'if not provided a function, the function will throw a type error', function test( t ) { |
42 |
| - var values; |
43 |
| - var i; |
44 |
| - |
45 |
| - values = [ |
46 |
| - 'beep', |
47 |
| - 5, |
48 |
| - NaN, |
49 |
| - null, |
50 |
| - true, |
51 |
| - void 0, |
52 |
| - [], |
53 |
| - {} |
54 |
| - ]; |
55 |
| - |
56 |
| - for ( i = 0; i < values.length; i++ ) { |
57 |
| - t.throws( badValue( values[i] ), TypeError, 'throws a TypeError when provided '+values[i] ); |
58 |
| - } |
59 |
| - t.end(); |
60 |
| - |
61 |
| - function badValue( value ) { |
62 |
| - return function badValue() { |
63 |
| - functionName( value ); |
64 |
| - }; |
65 |
| - } |
66 |
| -}); |
67 |
| - |
68 |
| -tape( 'the function returns a function\'s name', function test( t ) { |
69 |
| - function beep() { |
70 |
| - return 'boop'; |
71 |
| - } |
72 |
| - t.equal( functionName( beep ), 'beep', 'returns beep' ); |
73 |
| - t.equal( functionName( Date ), 'Date', 'returns Date' ); |
74 |
| - t.equal( functionName( Buffer ), 'Buffer', 'returns Buffer' ); |
75 |
| - t.equal( functionName( Number ), 'Number', 'returns Number' ); |
76 |
| - t.equal( functionName( Math.sqrt ), 'sqrt', 'returns sqrt'<
A3E2
/span> ); // eslint-disable-line stdlib/no-builtin-math |
77 |
| - t.equal( functionName( Int8Array ), 'Int8Array', 'returns Int8Array' ); |
78 |
| - t.equal( functionName( Boolean ), 'Boolean', 'returns Boolean' ); |
79 |
| - t.equal( functionName( String ), 'String', 'returns String' ); |
80 |
| - t.equal( functionName( Fcn ), 'Function', 'returns Function' ); |
81 |
| - t.end(); |
82 |
| -}); |
83 |
| - |
84 |
| -tape( 'if provided an anonymous function, the function returns an empty string or "anonymous" (ES2015 and some browsers)', function test( t ) { |
85 |
| - var name; |
86 |
| - |
87 |
| - /* |
88 |
| - * See |
89 |
| - * - http://www.2ality.com/2015/09/function-names-es6.html |
90 |
| - * - https://bugs.webkit.org/show_bug.cgi?id=7726 |
91 |
| - * - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name (which claims that functions created using the `Function` constructor should have an empty string as a name) |
92 |
| - * - "Functions created with the syntax new Function(...) or just Function(...) have their name property set to an empty string." |
93 |
| - * |
94 |
| - * In Node.js <v6.0, the returned name is an empty string. For Node.js v6.0, the returned name when using the `Function` constructor is `"anonymous"`. |
95 |
| - */ |
96 |
| - |
97 |
| - name = functionName( function () {} ); // eslint-disable-line func-names |
98 |
| - t.equal( check( name ), true, 'returns an empty string (or "anonymous")' ); |
99 |
| - |
100 |
| - name = functionName( new Fcn('a', 'b', 'return') ); |
101 |
| - t.equal( check( name ), true, 'returns an empty string (or "anonymous")' ); |
102 |
| - |
103 |
| - t.end(); |
104 |
| - |
105 |
| - function check() { |
106 |
| - if ( name === '' || name === 'anonymous' ) { |
107 |
| - return true; |
108 |
| - } |
109 |
| - return false; |
110 |
| - } |
111 |
| -}); |
112 |
| - |
113 |
| -tape( 'the function supports returning a function name in ES5 and earlier environments', function test( t ) { |
114 |
| - var functionName = proxyquire( './../dist/main.js', { |
115 |
| - '@stdlib/assert-has-function-name-support': stub |
116 |
| - }); |
117 |
| - t.equal( functionName( beep ), 'beep', 'returns beep' ); |
118 |
| - t.end(); |
119 |
| - |
120 |
| - function beep() { |
121 |
| - return 'boop'; |
122 |
| - } |
123 |
| - |
124 |
| - // Earlier environments did not have a `name` property: |
125 |
| - function stub() { |
126 |
| - return false; |
127 |
| - } |
128 |
| -}); |
0 commit comments