-
Notifications
You must be signed in to change notification settings - Fork 1
/
getRealIndex.test.js
52 lines (43 loc) · 1.59 KB
/
getRealIndex.test.js
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
import { getRealIndex } from '../index';
const data = [
[[10, 20, 30], '()', '()'],
[[10, 20, 30], '', ''],
[[10, 20, 30], '1312', '1312'],
[[10, 20, 30], 'sdfs', 'sdfs'],
[[10, 20, 30], '+[]', '+[]'],
[[10, 20, 30], '[0]', 0],
[[10, 20, 30], '[5]', 5],
[[10, 20, 30], '[]', 3],
[[10, 20, 30], '[+]', 3],
[[10, 20, 30], '[+883]', 3],
[[10, 20, 30], '[+sfsfs]', 3],
[[10, 20, 30], '[=]', -1],
[[10, 20, 0], '[=]', -1],
[[10, 20, 30], '[=99]', -1],
[[10, 20, 30], '[=id=1]', -1],
[[10, 20, 30], '[=20]', 1],
[[10, 20, 20], '[=20]', 1],
[[10, 20, 30], '[==20]', 1],
[[10, 20, 20], '[==20]', 1],
[{}, '[=20]', -1],
[null, '[=20]', -1],
['sasda', '[==20]', -1],
[99, '[==20]', -1],
[[10, false, true], '[=false]', 1],
[['false', false, true], '[=false]', 0],
[[10, false, true], '[=true]', 2],
[[0.0, 0.00, 0], '[=0]', 0],
[['0.0', '0.00', '0'], '[=0]', 2],
[[{ id: 10 }, { id: 20 }, { id: 30 }], '[=id=20]', 1],
[[{ id: 10 }, { id: 20 }, { id: 30 }], '[=zzz=20]', -1],
[[{ id: 10 }, { id: 20 }, { id: 30 }], '[=id=99]', -1],
[[{ data: { v: 10 } }, { data: { v: 20 } }, { data: { v: 20 } }], '[=data.v=20]', 1],
[[{ data: { v: 10 } }, { data: { v: 20 } }, { data: { v: 20 } }], '[=data.v=60]', -1],
[[{ data: { v: false } }, { data: { v: true } }, { data: { v: '' } }], '[=data.v=true]', 1],
[[{ data: { v: '' } }, { data: { v: 0 } }, { data: { v: false } }], '[=data.v=false]', 2],
];
describe('getRealIndex', () => {
test.each(data)('getRealIndex(%j, %s) === %j', (data, key, expected) => {
expect(getRealIndex(data, key)).toBe(expected);
});
});