-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathArguments.spec.ts
More file actions
111 lines (98 loc) · 4.28 KB
/
Arguments.spec.ts
File metadata and controls
111 lines (98 loc) · 4.28 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import test from 'ava';
import { Arg } from '../src';
import { Argument } from 'src/Arguments';
const testObject = { "foo": "bar" };
const testArray = ["a", 1, true];
const parent = {} as any;
parent.child = parent;
const root = {} as any;
root.path = { to: { nested: root } };
const testFunc = () => { };
test('should match any argument(s) using Arg.all', t => {
t.true(Arg.all().matches([]));
t.true(Arg.all().matches([0]));
t.true(Arg.all().matches([1]));
t.true(Arg.all().matches(['string']));
t.true(Arg.all().matches([true]));
t.true(Arg.all().matches([false]));
t.true(Arg.all().matches(null));
t.true(Arg.all().matches(undefined));
t.true(Arg.all().matches([1, 2]));
t.true(Arg.all().matches(['string1', 'string2']));
})
test('should match any argument using Arg.any', t => {
t.true(Arg.any().matches('hi'));
t.true(Arg.any().matches(1));
t.true(Arg.any().matches(0));
t.true(Arg.any().matches(false));
t.true(Arg.any().matches(true));
t.true(Arg.any().matches(null));
t.true(Arg.any().matches(undefined));
t.true(Arg.any().matches(testObject));
t.true(Arg.any().matches(testArray));
t.true(Arg.any().matches(testFunc));
t.true(Arg.any().matches());
t.true(Arg.any().matches(parent));
t.true(Arg.any().matches(root));
t.true(Arg.any().matches(parent));
t.true(Arg.any().matches(root));
});
test('should not match any argument using Arg.any.not', t => {
t.false(Arg.any.not().matches('hi'));
t.false(Arg.any.not().matches(1));
t.false(Arg.any.not().matches(0));
t.false(Arg.any.not().matches(false));
t.false(Arg.any.not().matches(true));
t.false(Arg.any.not().matches(null));
t.false(Arg.any.not().matches(undefined));
t.false(Arg.any.not().matches(testObject));
t.false(Arg.any.not().matches(testArray));
t.false(Arg.any.not().matches(testFunc));
t.false(Arg.any.not().matches());
t.false(Arg.any.not().matches(parent));
t.false(Arg.any.not().matches(root));
t.false(Arg.any.not().matches(parent));
t.false(Arg.any.not().matches(root));
});
test('should match the type of the argument using Arg.any', t => {
t.true(Arg.any('string').matches('foo'));
t.true(Arg.any('number').matches(1));
t.true(Arg.any('boolean').matches(true));
t.true(Arg.any('symbol').matches(Symbol()));
t.true((<Argument<unknown>>Arg.any('undefined')).matches(undefined));
t.true(Arg.any('object').matches(testObject));
t.true(Arg.any('array').matches(testArray));
t.true(Arg.any('function').matches(testFunc));
t.true(Arg.any('object').matches(parent));
t.true(Arg.any('object').matches(root));
t.false((<Argument<unknown>>Arg.any('string')).matches(1));
t.false((<Argument<unknown>>Arg.any('number')).matches('string'));
t.false(Arg.any('boolean').matches(null));
t.false((<Argument<unknown>>Arg.any('object')).matches('foo'));
t.false((<Argument<unknown>>Arg.any('array')).matches('bar'));
t.false((<Argument<unknown>>Arg.any('function')).matches('foo'));
});
test('should not match the type of the argument using Arg.any.not', t => {
t.false(Arg.any.not('string').matches('123'));
t.false(Arg.any.not('number').matches(123));
t.false(Arg.any.not('boolean').matches(true));
t.false(Arg.any.not('symbol').matches(Symbol()));
t.false((<Argument<unknown>>Arg.any.not('undefined')).matches(undefined));
t.false(Arg.any.not('object').matches(testObject));
t.false(Arg.any.not('array').matches(testArray));
t.false(Arg.any.not('function').matches(testFunc));
t.false(Arg.any.not('object').matches(parent));
t.false(Arg.any.not('object').matches(root));
});
test('should match the argument with the predicate function using Arg.is', t => {
t.true(Arg.is<string>(x => x === 'foo').matches('foo'));
t.true(Arg.is<number>(x => x % 2 == 0).matches(4));
t.false(Arg.is<string>(x => x === 'foo').matches('bar'));
t.false(Arg.is<number>(x => x % 2 == 0).matches(3));
});
test('should not match the argument with the predicate function using Arg.is.not', t => {
t.false(Arg.is.not<string>(x => x === 'foo').matches('foo'));
t.false(Arg.is.not<number>(x => x % 2 == 0).matches(4));
t.true(Arg.is.not<string>(x => x === 'foo').matches('bar'));
t.true(Arg.is.not<number>(x => x % 2 == 0).matches(3));
});