-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-utils.js
More file actions
77 lines (55 loc) · 2.03 KB
/
Copy pathtest-utils.js
File metadata and controls
77 lines (55 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Nothing, Just } from './src/index.js';
/* globals Promise, Symbol, Int8Array, Map, Set */
/* eslint-disable no-magic-numbers */
const testValue = (val, strVal, fn, exp) => {
if (exp === Nothing) {
test(`${fn.name}(${strVal}) = Nothing`, () =>
expect(fn(val)).toBe(Nothing)
);
} else if (exp === Just) {
test(`${fn.name}(${strVal}) = Just(${strVal})`, () =>
expect(fn(val).get()).toBe(val)
);
} else {
throw new Error('Invalid expected value');
}
};
/* NaN, ±Infinity, undefined, null */
export const _nan = (fn, exp) =>
testValue(NaN, 'NaN', fn, exp);
export const _plusInfinity = (fn, exp) =>
testValue(Infinity, 'Infinity', fn, exp);
export const _minusInfinity = (fn, exp) =>
testValue(-Infinity, '-Infinity', fn, exp);
export const _undefined = (fn, exp) =>
testValue(undefined, 'undefined', fn, exp);
export const _null = (fn, exp) =>
testValue(null, 'null', fn, exp);
/* Boolean, Function, Number, Object, String, Symbol, Integer */
export const _true = (fn, exp) =>
testValue(true, 'true', fn, exp);
export const _false = (fn, exp) =>
testValue(false, 'false', fn, exp);
export const _function = (fn, exp) =>
testValue(() => undefined, '() => undefined', fn, exp);
export const _number = (fn, exp) =>
testValue(0.1, '0.1', fn, exp);
export const _object = (fn, exp) =>
testValue({}, '{}', fn, exp);
export const _string = (fn, exp) =>
testValue('', '\'\'', fn, exp);
export const _symbol = (fn, exp) =>
testValue(Symbol('desc'), 'Symbol()', fn, exp);
export const _integer = (fn, exp) =>
testValue(0, '0', fn, exp);
/* Promise, Array, TypedArray, Map, Set */
export const _promise = (fn, exp) =>
testValue(Promise.resolve(0), 'Promise', fn, exp);
export const _array = (fn, exp) =>
testValue([], '[]', fn, exp);
export const _typedArray = (fn, exp) =>
testValue(new Int8Array(2), '<TypedArray>', fn, exp);
export const _map = (fn, exp) =>
testValue(new Map([[0, 'zero']]), '<Map>', fn, exp);
export const _set = (fn, exp) =>
testValue(new Set([0]), '<Set>', fn, exp);