-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharrayIndexOf.test.ts
More file actions
23 lines (20 loc) · 1.01 KB
/
arrayIndexOf.test.ts
File metadata and controls
23 lines (20 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { describe, expect, it } from 'vitest';
import { arrayIndexOf } from '../arrayIndexOf.ts';
describe('arrayIndexOf', () => {
it('should find the index pointing to the begining of the found string in array', () => {
const whole = new Uint8Array([0x61, 0x6d, 0x6f, 0x67, 0x75, 0x73]);
const sandwiched = new Uint8Array([
0x41, 0x61, 0x6d, 0x6f, 0x67, 0x75, 0x73, 0x75, 0x73,
]);
const notIn = new Uint8Array([0x61, 0x6d, 0x6f, 0x67]);
const testString = new Uint8Array([0x61, 0x6d, 0x6f, 0x67, 0x75, 0x73]);
const singleTest = new Uint8Array([0x2e]);
const repeaTest = new Uint8Array([0x5d, 0x5d, 0x3e]);
const repeats = new Uint8Array([0x5d, 0x5d, 0x5d, 0x5d, 0x3e, 0x5d]);
expect(arrayIndexOf(whole, testString)).toBe(0);
expect(arrayIndexOf(sandwiched, testString)).toBe(1);
expect(arrayIndexOf(notIn, testString)).toBe(-1);
expect(arrayIndexOf(new Uint8Array([49, 46, 51, 52]), singleTest)).toBe(1);
expect(arrayIndexOf(repeats, repeaTest)).toBe(2);
});
});