generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpandToDate.test.ts
62 lines (47 loc) · 1.73 KB
/
expandToDate.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
import { tryExpandPosToMachADate, ObjType } from './expandToDate';
describe('tryExpandPosToMachADate', () => {
it('should return true and modify from and to if pos is on a date', () => {
const parObj: ObjType = {
curLine: 'Lorem ipsum dolor sit amet, 2022-01-01 consectetur adipiscing elit 2023-04-10.',
fromPos: 33,
toPos: 35,
};
const result = tryExpandPosToMachADate(parObj);
expect(result).toBe(true);
expect(parObj.fromPos).toBe(28);
expect(parObj.toPos).toBe(38);
});
it('should return true and modify from and to if pos is on a second date', () => {
const parObj: ObjType = {
curLine: 'Lorem ipsum dolor sit amet, 2022-01-01 consectetur adipiscing elit 2023-04-10.',
fromPos: 70,
toPos: 72,
};
const result = tryExpandPosToMachADate(parObj);
expect(result).toBe(true);
expect(parObj.fromPos).toBe(67);
expect(parObj.toPos).toBe(77);
});
it('should return false and not modify from and to if pos is not on the date', () => {
const parObj: ObjType = {
curLine: 'Lorem ipsum dolor sit amet, 2022-01-01 consectetur adipiscing elit.',
fromPos: 3,
toPos: 5,
};
const result = tryExpandPosToMachADate(parObj);
expect(result).toBe(false);
expect(parObj.fromPos).toBe(3);
expect(parObj.toPos).toBe(5);
});
it('should return false and not modify from and to if no date is found around position', () => {
const parObj: ObjType = {
curLine: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
fromPos: 10,
toPos: 15,
};
const result = tryExpandPosToMachADate(parObj);
expect(result).toBe(false);
expect(parObj.fromPos).toBe(10);
expect(parObj.toPos).toBe(15);
});
});