-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrSubstrCount.test.ts
61 lines (54 loc) · 3.68 KB
/
strSubstrCount.test.ts
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
import { describe, it, expect } from 'vitest';
import strSubstrCount from '../../src/strSubstrCount.js';
describe('str/strSubstrCount', () => {
it('works', () => {
expect(strSubstrCount('This is a string.', ' is')).toEqual(1);
expect(strSubstrCount('This is a string.', 'is ')).toEqual(2);
expect(strSubstrCount('This is a string.', ' is ')).toEqual(1);
expect(strSubstrCount('This is a string.', 'is')).toEqual(2);
expect(strSubstrCount('laravelPHPFramework', 'a')).toEqual(3);
expect(strSubstrCount('laravelPHPFramework', 'z')).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'l', -'PHPFramework'.length)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'l', -'lPHPFramework'.length)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'l', -'elPHPFramework'.length)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'l', -1)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'l', 0)).toEqual(2);
expect(strSubstrCount('laravelPHPFramework', 'l', 1)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'l', 2)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'l', 3)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'l', 4)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'l', 5)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'l', 6)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'l', 7)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'z', 2)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'k', -1)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'r', -2)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'a', 0, 0)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'a', 0, 1)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'a', 0, 2)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'a', 0, 3)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'a', 0, 4)).toEqual(2);
expect(strSubstrCount('laravelPHPFramework', 'a', 1, 0)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'a', 1, 1)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'a', 1, 2)).toEqual(1);
expect(strSubstrCount('laravelPHPFramework', 'a', 1, 3)).toEqual(2);
expect(strSubstrCount('laravelPHPFramework', 'a', 1, 4)).toEqual(2);
expect(strSubstrCount('laravelPHPFramework', 'a', 1, 5)).toEqual(2);
expect(strSubstrCount('laravelPHPFramework', 'a', 1, 'laravelPHPFra'.length)).toEqual(3);
expect(strSubstrCount('laravelPHPFramework', 'a', 1, -2)).toEqual(3);
expect(strSubstrCount('laravelPHPFramework', 'a', -10, -3)).toEqual(1);
});
it('is case sensitive', () => {
expect(strSubstrCount('This is a string.', ' Is')).toEqual(0);
expect(strSubstrCount('This is a string.', ' iS')).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'L', 1)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'L', 2)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'L', 7)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'K', -1)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'R', -2)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'A', 1, 2)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'A', 1, 2)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'A', 1, -2)).toEqual(0);
expect(strSubstrCount('laravelPHPFramework', 'A', -10, -3)).toEqual(0);
});
});