-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsplitSmartBlockArgs.test.ts
More file actions
75 lines (66 loc) · 2.22 KB
/
splitSmartBlockArgs.test.ts
File metadata and controls
75 lines (66 loc) · 2.22 KB
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
import { test, expect } from "@playwright/test";
import splitSmartBlockArgs from "../src/utils/splitSmartBlockArgs";
test("splits nested smartblock commands as a single argument", () => {
expect(
splitSmartBlockArgs("ANYCOMMAND", "one,<%RANDOMNUMBER:1,10%>,two")
).toEqual(["one", "<%RANDOMNUMBER:1,10%>", "two"]);
});
test("preserves commas in daily note page references", () => {
expect(
splitSmartBlockArgs(
"BLOCKMENTIONSDATED",
"10,DONE,[[January 24th, 2023]],[[January 1st, 2023]]"
)
).toEqual(["10", "DONE", "[[January 24th, 2023]]", "[[January 1st, 2023]]"]);
});
test("coalesces month-day-year date tokens for BLOCKMENTIONSDATED", () => {
expect(
splitSmartBlockArgs(
"BLOCKMENTIONSDATED",
"10,DONE,February 1, 2023,February 24, 2023,DESC"
)
).toEqual(["10", "DONE", "February 1, 2023", "February 24, 2023", "DESC"]);
});
test("handles unclosed [[ gracefully by treating rest as single arg", () => {
expect(
splitSmartBlockArgs("BLOCKMENTIONSDATED", "10,DONE,[[January 24th")
).toEqual(["10", "DONE", "[[January 24th"]);
});
test("preserves commas inside nested page references", () => {
expect(
splitSmartBlockArgs(
"BLOCKMENTIONSDATED",
"10,DONE,[[January 24th, 2023]],today"
)
).toEqual(["10", "DONE", "[[January 24th, 2023]]", "today"]);
});
test("coalesces at most two date tokens for BLOCKMENTIONSDATED", () => {
expect(
splitSmartBlockArgs(
"BLOCKMENTIONSDATED",
"10,DONE,January 1, 2023,February 1, 2023,March 1, 2023"
)
).toEqual([
"10",
"DONE",
"January 1, 2023",
"February 1, 2023",
"March 1",
" 2023",
]);
});
test("does not coalesce date tokens for non-BLOCKMENTIONSDATED commands", () => {
expect(
splitSmartBlockArgs("ANYCOMMAND", "January 1, 2023")
).toEqual(["January 1", " 2023"]);
});
test("unclosed [[ in non-BLOCKMENTIONSDATED treats remaining as single arg", () => {
expect(
splitSmartBlockArgs("ANYCOMMAND", "one,[[unclosed,two,three")
).toEqual(["one", "[[unclosed,two,three"]);
});
test("balanced [[ ]] followed by normal args splits correctly", () => {
expect(
splitSmartBlockArgs("ANYCOMMAND", "[[page ref]],normal,arg")
).toEqual(["[[page ref]]", "normal", "arg"]);
});