|
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 hasSymbols = require( '@stdlib/assert-has-symbol-support' ); |
26 | | -var hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' ); |
27 | | -var isRegExp = require( './../../dist' ); |
28 | | - |
29 | | - |
30 | | -// VARIABLES // |
31 | | - |
32 | | -var opts = { |
33 | | - 'skip': !hasSymbols() |
34 | | -}; |
| 24 | +var main = require( './../../dist' ); |
35 | 25 |
|
36 | 26 |
|
37 | 27 | // TESTS // |
38 | 28 |
|
39 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
40 | 30 | t.ok( true, __filename ); |
41 | | - t.strictEqual( typeof isRegExp, 'function', 'main export is a function' ); |
42 | | - t.end(); |
43 | | -}); |
44 | | - |
45 | | -tape( 'the function returns `true` if provided a regular expression', function test( t ) { |
46 | | - t.strictEqual( isRegExp( /\.+/ ), true, 'returns true' ); |
47 | | - t.strictEqual( isRegExp( new RegExp( '\\.+' ) ), true, 'returns true' ); // eslint-disable-line prefer-regex-literals |
48 | | - t.end(); |
49 | | -}); |
50 | | - |
51 | | -tape( 'if `Symbol.toStringTag` is supported, the function guards against objects masquerading as regular expressions', opts, function test( t ) { |
52 | | - var isRegExp; |
53 | | - var mock; |
54 | | - |
55 | | - isRegExp = proxyquire( './../dist/main.js', { |
56 | | - '@stdlib/assert-has-tostringtag-support': detect |
57 | | - }); |
58 | | - |
59 | | - mock = { |
60 | | - 'toString': toString, |
61 | | - 'exec': exec |
62 | | - }; |
63 | | - if ( hasToStringTag() ) { |
64 | | - mock[ Symbol.toStringTag ] = 'RegExp'; |
65 | | - } |
66 | | - t.strictEqual( isRegExp( mock ), false, 'returns false' ); |
67 | | - |
68 | | - t.end(); |
69 | | - |
70 | | - function detect() { |
71 | | - return true; |
72 | | - } |
73 | | - function toString() { |
74 | | - return '/beep/'; |
75 | | - } |
76 | | - function exec() { |
77 | | - return null; |
78 | | - } |
79 | | -}); |
80 | | - |
81 | | -tape( 'if `Symbol.toStringTag` is supported, the function returns `true` if provided a regular expression', opts, function test( t ) { |
82 | | - var isRegExp = proxyquire( './../dist/main.js', { |
83 | | - '@stdlib/assert-has-tostringtag-support': detect |
84 | | - }); |
85 | | - |
86 | | - t.strictEqual( isRegExp( /beep/ ), true, 'returns true' ); |
87 | | - |
88 | | - t.end(); |
89 | | - |
90 | | - function detect() { |
91 | | - return true; |
92 | | - } |
93 | | -}); |
94 | | - |
95 | | -tape( 'if `Symbol.toStringTag` is not supported, the function attempts to determine the native class', function test( t ) { |
96 | | - var isRegExp = proxyquire( './../dist/main.js', { |
97 | | - '@stdlib/assert-has-tostringtag-support': detect |
98 | | - }); |
99 | | - |
100 | | - t.strictEqual( isRegExp( /beep/ ), true, 'returns true' ); |
101 | | - t.strictEqual( isRegExp( {} ), false, 'returns false' ); |
102 | | - |
103 | | - t.end(); |
104 | | - |
105 | | - function detect() { |
106 | | - return false; |
107 | | - } |
108 | | -}); |
109 | | - |
110 | | -tape( 'the function returns `false` if not provided a regular expression', function test( t ) { |
111 | | - var values; |
112 | | - var i; |
113 | | - |
114 | | - values = [ |
115 | | - '5', |
116 | | - '/.+/', |
117 | | - 5, |
118 | | - NaN, |
119 | | - null, |
120 | | - void 0, |
121 | | - true, |
122 | | - false, |
123 | | - [], |
124 | | - {}, |
125 | | - function noop() {} |
126 | | - ]; |
127 | | - for ( i = 0; i < values.length; i++ ) { |
128 | | - t.strictEqual( isRegExp( values[i] ), false, 'returns false when provided '+values[i] ); |
129 | | - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
130 | 32 | t.end(); |
131 | 33 | }); |
0 commit comments