This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
76 lines (73 loc) · 1.97 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import test from 'ava';
import m from './';
test(t => {
// https://github.com/iojs/io.js/blob/8bf878d6e5ac0faa3871cddd5dcc423ae4d3d45a/test/parallel/test-buffer-bufIndexof.js
const b = new Buffer('abcdef');
const buf_a = new Buffer('a');
const buf_bc = new Buffer('bc');
const buf_f = new Buffer('f');
const buf_z = new Buffer('z');
const buf_empty = new Buffer('');
t.is(m(b, 'a'), 0);
t.is(m(b, 'a', 1), -1);
t.is(m(b, 'a', -1), -1);
t.is(m(b, 'a', -4), -1);
t.is(m(b, 'a', -b.length), 0);
t.is(m(b, 'a', NaN), 0);
t.is(m(b, 'a', -Infinity), 0);
t.is(m(b, 'a', Infinity), -1);
t.is(m(b, 'bc'), 1);
t.is(m(b, 'bc', 2), -1);
t.is(m(b, 'bc', -1), -1);
t.is(m(b, 'bc', -3), -1);
t.is(m(b, 'bc', -5), 1);
t.is(m(b, 'bc', NaN), 1);
t.is(m(b, 'bc', -Infinity), 1);
t.is(m(b, 'bc', Infinity), -1);
t.is(m(b, 'f'), b.length - 1);
t.is(m(b, 'z'), -1);
t.is(m(b, ''), -1);
t.is(m(b, '', 1), -1);
t.is(m(b, '', b.length + 1), -1);
t.is(m(b, '', Infinity), -1);
t.is(m(b, buf_a), 0);
t.is(m(b, buf_a, 1), -1);
t.is(m(b, buf_a, -1), -1);
t.is(m(b, buf_a, -4), -1);
t.is(m(b, buf_a, -b.length), 0);
t.is(m(b, buf_a, NaN), 0);
t.is(m(b, buf_a, -Infinity), 0);
t.is(m(b, buf_a, Infinity), -1);
t.is(m(b, buf_bc), 1);
t.is(m(b, buf_bc, 2), -1);
t.is(m(b, buf_bc, -1), -1);
t.is(m(b, buf_bc, -3), -1);
t.is(m(b, buf_bc, -5), 1);
t.is(m(b, buf_bc, NaN), 1);
t.is(m(b, buf_bc, -Infinity), 1);
t.is(m(b, buf_bc, Infinity), -1);
t.is(m(b, buf_f), b.length - 1);
t.is(m(b, buf_z), -1);
t.is(m(b, buf_empty), -1);
t.is(m(b, buf_empty, 1), -1);
t.is(m(b, buf_empty, b.length + 1), -1);
t.is(m(b, buf_empty, Infinity), -1);
t.is(m(b, 0x61), 0);
t.is(m(b, 0x61, 1), -1);
t.is(m(b, 0x61, -1), -1);
t.is(m(b, 0x61, -4), -1);
t.is(m(b, 0x61, -b.length), 0);
t.is(m(b, 0x61, NaN), 0);
t.is(m(b, 0x61, -Infinity), 0);
t.is(m(b, 0x61, Infinity), -1);
t.is(m(b, 0x0), -1);
t.throws(() => {
m(b, () => {});
});
t.throws(() => {
m(b, {});
});
t.throws(() => {
m(b, []);
});
});