1+ import { isGeneratorFunction , isDefaultGeneratorFunction , isAsyncGeneratorFunction } from '@/generators'
2+ import { isGeneratorObject , isDefaultGeneratorObject , isAsyncGeneratorObject } from '@/generators'
3+
4+
5+ function standardFunction ( ) {
6+ return 'foo'
7+ }
8+
9+
10+ function * generatorFunction ( ) {
11+ yield 'data'
12+ }
13+
14+
15+ async function * asyncGeneratorFunction ( )
16+ {
17+ yield 'data 1'
18+ }
19+
20+
21+ describe ( 'isDefaultGeneratorFunction' , ( ) => {
22+
23+ it ( 'returns `true` when a GeneratorFunction is provided' , ( ) => {
24+
25+ expect ( isDefaultGeneratorFunction ( generatorFunction ) )
26+ . toBe ( true )
27+
28+ } )
29+
30+
31+ it ( 'returns `false` when a standard function is provided' , ( ) => {
32+
33+ expect ( isDefaultGeneratorFunction ( standardFunction ) )
34+ . toBe ( false )
35+
36+ } )
37+
38+
39+ it ( 'returns `false` when a non-function reference data is provided' , ( ) => {
40+
41+ expect ( isDefaultGeneratorFunction ( 'non-function reference data' ) )
42+ . toBe ( false )
43+ expect ( isDefaultGeneratorFunction ( 1 ) )
44+ . toBe ( false )
45+ expect ( isDefaultGeneratorFunction ( true ) )
46+ . toBe ( false )
47+ expect ( isDefaultGeneratorFunction ( undefined ) )
48+ . toBe ( false )
49+ expect ( isDefaultGeneratorFunction ( null ) )
50+ . toBe ( false )
51+ expect ( isDefaultGeneratorFunction ( { prop : 'value' } ) )
52+ . toBe ( false )
53+ expect ( isDefaultGeneratorFunction ( [ ] ) )
54+ . toBe ( false )
55+
56+ } )
57+
58+
59+ it ( 'returns `false` when a Generator or AsyncGenerator is provided' , ( ) => {
60+
61+ expect ( isDefaultGeneratorFunction ( generatorFunction ( ) ) )
62+ . toBe ( false )
63+ expect ( isDefaultGeneratorFunction ( asyncGeneratorFunction ( ) ) )
64+ . toBe ( false )
65+
66+ } )
67+
68+
69+ it ( 'returns `false` when an AsyncGeneratorFunction is provided' , ( ) => {
70+
71+ expect ( isDefaultGeneratorFunction ( asyncGeneratorFunction ) )
72+ . toBe ( false )
73+
74+ } )
75+
76+ } )
77+
78+
79+ describe ( 'isAsyncGeneratorFunction' , ( ) => {
80+
81+ it ( 'returns `true` when an AsyncGeneratorFunction is provided' , ( ) => {
82+
83+ expect ( isAsyncGeneratorFunction ( asyncGeneratorFunction ) )
84+ . toBe ( true )
85+
86+ } )
87+
88+
89+ it ( 'returns `false` when a standard function is provided' , ( ) => {
90+
91+ expect ( isAsyncGeneratorFunction ( standardFunction ) )
92+ . toBe ( false )
93+
94+ } )
95+
96+
97+ it ( 'returns `false` when a non-function reference data is provided' , ( ) => {
98+
99+ expect ( isAsyncGeneratorFunction ( 'non-function reference data' ) )
100+ . toBe ( false )
101+ expect ( isAsyncGeneratorFunction ( 1 ) )
102+ . toBe ( false )
103+ expect ( isAsyncGeneratorFunction ( true ) )
104+ . toBe ( false )
105+ expect ( isAsyncGeneratorFunction ( undefined ) )
106+ . toBe ( false )
107+ expect ( isAsyncGeneratorFunction ( null ) )
108+ . toBe ( false )
109+ expect ( isAsyncGeneratorFunction ( { prop : 'value' } ) )
110+ . toBe ( false )
111+ expect ( isAsyncGeneratorFunction ( [ ] ) )
112+ . toBe ( false )
113+
114+ } )
115+
116+
117+ it ( 'returns `false` when a Generator or AsyncGenerator is provided' , ( ) => {
118+
119+ expect ( isAsyncGeneratorFunction ( generatorFunction ( ) ) )
120+ . toBe ( false )
121+ expect ( isAsyncGeneratorFunction ( asyncGeneratorFunction ( ) ) )
122+ . toBe ( false )
123+
124+ } )
125+
126+
127+ it ( 'returns `false` when a GeneratorFunction is provided' , ( ) => {
128+
129+ expect ( isAsyncGeneratorFunction ( generatorFunction ) )
130+ . toBe ( false )
131+
132+ } )
133+
134+ } )
135+
136+
137+ describe ( 'isGeneratorFunction' , ( ) => {
138+
139+ it ( 'returns `true` when a GeneratorFunction is provided' , ( ) => {
140+
141+ expect ( isGeneratorFunction ( generatorFunction ) )
142+ . toBe ( true )
143+
144+ } )
145+
146+
147+ it ( 'returns `true` when an AsyncGeneratorFunction is provided' , ( ) => {
148+
149+ expect ( isGeneratorFunction ( asyncGeneratorFunction ) )
150+ . toBe ( true )
151+
152+ } )
153+
154+
155+ it ( 'returns `false` when a standard function is provided' , ( ) => {
156+
157+ expect ( isGeneratorFunction ( standardFunction ) )
158+ . toBe ( false )
159+
160+ } )
161+
162+
163+ it ( 'returns `false` when a non-function reference data is provided' , ( ) => {
164+
165+ expect ( isGeneratorFunction ( 'non-function reference data' ) )
166+ . toBe ( false )
167+ expect ( isGeneratorFunction ( 1 ) )
168+ . toBe ( false )
169+ expect ( isGeneratorFunction ( true ) )
170+ . toBe ( false )
171+ expect ( isGeneratorFunction ( undefined ) )
172+ . toBe ( false )
173+ expect ( isGeneratorFunction ( null ) )
174+ . toBe ( false )
175+ expect ( isGeneratorFunction ( { prop : 'value' } ) )
176+ . toBe ( false )
177+ expect ( isGeneratorFunction ( [ ] ) )
178+ . toBe ( false )
179+
180+ } )
181+
182+
183+ it ( 'returns `false` when a Generator or AsyncGenerator is provided' , ( ) => {
184+
185+ expect ( isGeneratorFunction ( generatorFunction ( ) ) )
186+ . toBe ( false )
187+ expect ( isGeneratorFunction ( asyncGeneratorFunction ( ) ) )
188+ . toBe ( false )
189+
190+ } )
191+
192+ } )
193+
194+
195+
196+
197+ describe ( 'isDefaultGeneratorObject' , ( ) => {
198+
199+ it ( 'returns `true` when a Generator is provided' , ( ) => {
200+ expect ( isDefaultGeneratorObject ( generatorFunction ( ) ) )
201+ . toBe ( true )
202+ } )
203+
204+
205+ it ( 'returns `false` when a non-object reference data is provided' , ( ) => {
206+
207+ expect ( isDefaultGeneratorObject ( 'non-object reference data' ) )
208+ . toBe ( false )
209+ expect ( isDefaultGeneratorObject ( 1 ) )
210+ . toBe ( false )
211+ expect ( isDefaultGeneratorObject ( true ) )
212+ . toBe ( false )
213+ expect ( isDefaultGeneratorObject ( undefined ) )
214+ . toBe ( false )
215+ expect ( isDefaultGeneratorObject ( null ) )
216+ . toBe ( false )
217+ expect ( isDefaultGeneratorObject ( { prop : 'value' } ) )
218+ . toBe ( false )
219+ expect ( isDefaultGeneratorObject ( [ ] ) )
220+ . toBe ( false )
221+ expect ( isDefaultGeneratorObject ( ( ) => { } ) )
222+ . toBe ( false )
223+
224+ } )
225+
226+
227+ it ( 'returns `false` when a GeneratorFunction or AsyncGeneratorFunction is provided' , ( ) => {
228+
229+ expect ( isDefaultGeneratorObject ( generatorFunction ) )
230+ . toBe ( false )
231+ expect ( isDefaultGeneratorObject ( asyncGeneratorFunction ) )
232+ . toBe ( false )
233+
234+ } )
235+
236+
237+ it ( 'returns `false` when an AsyncGenerator is provided' , ( ) => {
238+
239+ expect ( isDefaultGeneratorObject ( asyncGeneratorFunction ( ) ) )
240+ . toBe ( false )
241+
242+ } )
243+
244+ } )
245+
246+
247+ describe ( 'isAsyncGeneratorObject' , ( ) => {
248+
249+ it ( 'returns `true` when an AsyncGenerator is provided' , ( ) => {
250+ expect ( isAsyncGeneratorObject ( asyncGeneratorFunction ( ) ) )
251+ . toBe ( true )
252+ } )
253+
254+
255+ it ( 'returns `false` when a non-object reference data is provided' , ( ) => {
256+
257+ expect ( isAsyncGeneratorObject ( 'non-object reference data' ) )
258+ . toBe ( false )
259+ expect ( isAsyncGeneratorObject ( 1 ) )
260+ . toBe ( false )
261+ expect ( isAsyncGeneratorObject ( true ) )
262+ . toBe ( false )
263+ expect ( isAsyncGeneratorObject ( undefined ) )
264+ . toBe ( false )
265+ expect ( isAsyncGeneratorObject ( null ) )
266+ . toBe ( false )
267+ expect ( isAsyncGeneratorObject ( { prop : 'value' } ) )
268+ . toBe ( false )
269+ expect ( isAsyncGeneratorObject ( [ ] ) )
270+ . toBe ( false )
271+ expect ( isAsyncGeneratorObject ( ( ) => { } ) )
272+ . toBe ( false )
273+
274+ } )
275+
276+
277+ it ( 'returns `false` when a GeneratorFunction or AsyncGeneratorFunction is provided' , ( ) => {
278+
279+ expect ( isAsyncGeneratorObject ( generatorFunction ) )
280+ . toBe ( false )
281+ expect ( isAsyncGeneratorObject ( asyncGeneratorFunction ) )
282+ . toBe ( false )
283+
284+ } )
285+
286+
287+ it ( 'returns `false` when a Generator is provided' , ( ) => {
288+
289+ expect ( isAsyncGeneratorObject ( generatorFunction ( ) ) )
290+ . toBe ( false )
291+
292+ } )
293+
294+ } )
295+
296+
297+ describe ( 'isGeneratorObject' , ( ) => {
298+
299+ it ( 'returns `true` when a Generator is provided' , ( ) => {
300+
301+ expect ( isGeneratorObject ( generatorFunction ( ) ) )
302+ . toBe ( true )
303+
304+ } )
305+
306+
307+ it ( 'returns `true` when an AsyncGenerator is provided' , ( ) => {
308+
309+ expect ( isGeneratorObject ( asyncGeneratorFunction ( ) ) )
310+ . toBe ( true )
311+
312+ } )
313+
314+
315+ it ( 'returns `false` when a non-object reference data is provided' , ( ) => {
316+
317+ expect ( isGeneratorObject ( 'non-object reference data' ) )
318+ . toBe ( false )
319+ expect ( isGeneratorObject ( 1 ) )
320+ . toBe ( false )
321+ expect ( isGeneratorObject ( true ) )
322+ . toBe ( false )
323+ expect ( isGeneratorObject ( undefined ) )
324+ . toBe ( false )
325+ expect ( isGeneratorObject ( null ) )
326+ . toBe ( false )
327+ expect ( isGeneratorObject ( { prop : 'value' } ) )
328+ . toBe ( false )
329+ expect ( isGeneratorObject ( [ ] ) )
330+ . toBe ( false )
331+ expect ( isGeneratorObject ( ( ) => { } ) )
332+ . toBe ( false )
333+
334+ } )
335+
336+
337+ it ( 'returns `false` when a GeneratorFunction or AsyncGeneratorFunction is provided' , ( ) => {
338+
339+ expect ( isGeneratorObject ( generatorFunction ) )
340+ . toBe ( false )
341+ expect ( isGeneratorObject ( asyncGeneratorFunction ) )
342+ . toBe ( false )
343+
344+ } )
345+
346+ } )
0 commit comments