mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-11 14:45:30 +00:00
feat: better regex tests
This commit is contained in:
@@ -18,6 +18,9 @@ describe("trigger", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("text in parantheses", () => {
|
describe("text in parantheses", () => {
|
||||||
|
test("alone", () => {
|
||||||
|
expect(getTriggerText("(capture)", 1)).toEqual(["capture", 1, 8]);
|
||||||
|
});
|
||||||
test("text behind", () => {
|
test("text behind", () => {
|
||||||
expect(getTriggerText("(capture) testing", 1)).toEqual([
|
expect(getTriggerText("(capture) testing", 1)).toEqual([
|
||||||
"capture",
|
"capture",
|
||||||
@@ -53,70 +56,94 @@ describe("trigger", () => {
|
|||||||
13,
|
13,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("text and colon", () => {
|
test("with colon", () => {
|
||||||
expect(getTriggerText("(capture:) testing", 1)).toEqual([
|
expect(getTriggerText("(capture:)", 1)).toEqual(["capture:", 1, 9]);
|
||||||
"capture:",
|
|
||||||
1,
|
|
||||||
9,
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
test("text and double colon", () => {
|
test("with double colon", () => {
|
||||||
expect(getTriggerText("(capture::) testing", 1)).toEqual([
|
expect(getTriggerText("(capture::)", 1)).toEqual([
|
||||||
"capture::",
|
"capture::",
|
||||||
1,
|
1,
|
||||||
10,
|
10,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("metadata field", () => {
|
test("metadata field", () => {
|
||||||
expect(getTriggerText("(capture::Bob) testing", 1)).toEqual([
|
expect(getTriggerText("(capture::Bob)", 1)).toEqual([
|
||||||
"capture::Bob",
|
"capture::Bob",
|
||||||
1,
|
1,
|
||||||
13,
|
13,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("metadata field with whitespace", () => {
|
test("metadata field with whitespace", () => {
|
||||||
expect(getTriggerText("(capture:: Bob) testing", 1)).toEqual([
|
expect(getTriggerText("(capture:: Bob)", 1)).toEqual([
|
||||||
"capture:: Bob",
|
"capture:: Bob",
|
||||||
1,
|
1,
|
||||||
14,
|
14,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("metadata field with more white space", () => {
|
test("metadata field with more white space", () => {
|
||||||
expect(getTriggerText("(capture:: Bob) testing", 1)).toEqual([
|
expect(getTriggerText("(capture:: Bob)", 1)).toEqual([
|
||||||
"capture:: Bob",
|
"capture:: Bob",
|
||||||
1,
|
1,
|
||||||
16,
|
16,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("text with markdown link", () => {
|
test("double field", () => {
|
||||||
expect(getTriggerText("([[test]]) testing", 1)).toEqual([
|
expect(getTriggerText("(capture1)(capture2)", 1)).toEqual([
|
||||||
"[[test]]",
|
"capture1",
|
||||||
1,
|
1,
|
||||||
9,
|
9,
|
||||||
]);
|
]);
|
||||||
});
|
expect(getTriggerText("(capture1)(capture2)", 11)).toEqual([
|
||||||
test("text with aliased markdown link", () => {
|
"capture2",
|
||||||
expect(getTriggerText("([[test|display]]) testing", 1)).toEqual([
|
11,
|
||||||
"[[test|display]]",
|
19,
|
||||||
1,
|
|
||||||
17,
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("text with wiki link", () => {
|
test("wiki link", () => {
|
||||||
expect(
|
expect(getTriggerText("(test [[test]])", 1)).toEqual([
|
||||||
getTriggerText("([[test](https://example.com)]) testing", 1),
|
"test [[test]]",
|
||||||
).toEqual(["[[test](https://example.com)]", 1, 30]);
|
|
||||||
});
|
|
||||||
test("text with wiki link local", () => {
|
|
||||||
expect(getTriggerText("([[test](test)]) testing", 1)).toEqual([
|
|
||||||
"[[test](test)]",
|
|
||||||
1,
|
1,
|
||||||
15,
|
14,
|
||||||
|
]);
|
||||||
|
expect(getTriggerText("(test [[test]])", 14)).toEqual([
|
||||||
|
"test [[test]]",
|
||||||
|
1,
|
||||||
|
14,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
test("aliased wiki link", () => {
|
||||||
|
expect(getTriggerText("(test [[test|display]])", 1)).toEqual([
|
||||||
|
"test [[test|display]]",
|
||||||
|
1,
|
||||||
|
22,
|
||||||
|
]);
|
||||||
|
expect(getTriggerText("(test [[test|display]])", 22)).toEqual([
|
||||||
|
"test [[test|display]]",
|
||||||
|
1,
|
||||||
|
22,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("markdown link", () => {
|
||||||
|
expect(getTriggerText("([test](https://example.com))", 1)).toEqual([
|
||||||
|
"[test](https://example.com)",
|
||||||
|
1,
|
||||||
|
28,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
test("markdown link local", () => {
|
||||||
|
expect(getTriggerText("([test](test))", 1)).toEqual([
|
||||||
|
"[test](test)",
|
||||||
|
1,
|
||||||
|
13,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("text in square brackets", () => {
|
describe("text in square brackets", () => {
|
||||||
|
test("alone", () => {
|
||||||
|
expect(getTriggerText("[capture]", 1)).toEqual(["capture", 1, 8]);
|
||||||
|
});
|
||||||
test("text behind", () => {
|
test("text behind", () => {
|
||||||
expect(getTriggerText("[capture] testing", 1)).toEqual([
|
expect(getTriggerText("[capture] testing", 1)).toEqual([
|
||||||
"capture",
|
"capture",
|
||||||
@@ -152,65 +179,85 @@ describe("trigger", () => {
|
|||||||
13,
|
13,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("text and colon", () => {
|
test("with colon", () => {
|
||||||
expect(getTriggerText("[capture:] testing", 1)).toEqual([
|
expect(getTriggerText("[capture:]", 1)).toEqual(["capture:", 1, 9]);
|
||||||
"capture:",
|
|
||||||
1,
|
|
||||||
9,
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
test("text and double colon", () => {
|
test("with double colon", () => {
|
||||||
expect(getTriggerText("[capture::] testing", 1)).toEqual([
|
expect(getTriggerText("[capture::]", 1)).toEqual([
|
||||||
"capture::",
|
"capture::",
|
||||||
1,
|
1,
|
||||||
10,
|
10,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("metadata field", () => {
|
test("metadata field", () => {
|
||||||
expect(getTriggerText("[capture::Bob] testing", 1)).toEqual([
|
expect(getTriggerText("[capture::Bob]", 1)).toEqual([
|
||||||
"capture::Bob",
|
"capture::Bob",
|
||||||
1,
|
1,
|
||||||
13,
|
13,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("metadata field with whitespace", () => {
|
test("metadata field with whitespace", () => {
|
||||||
expect(getTriggerText("[capture:: Bob] testing", 1)).toEqual([
|
expect(getTriggerText("[capture:: Bob]", 1)).toEqual([
|
||||||
"capture:: Bob",
|
"capture:: Bob",
|
||||||
1,
|
1,
|
||||||
14,
|
14,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("metadata field with more white space", () => {
|
test("metadata field with more white space", () => {
|
||||||
expect(getTriggerText("[capture:: Bob] testing", 1)).toEqual([
|
expect(getTriggerText("[capture:: Bob]", 1)).toEqual([
|
||||||
"capture:: Bob",
|
"capture:: Bob",
|
||||||
1,
|
1,
|
||||||
16,
|
16,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("text with markdown link", () => {
|
test("double field", () => {
|
||||||
expect(getTriggerText("[[[test]]] testing", 1)).toEqual([
|
expect(getTriggerText("[capture1][capture2]", 1)).toEqual([
|
||||||
"[[test]]",
|
"capture1",
|
||||||
1,
|
1,
|
||||||
9,
|
9,
|
||||||
]);
|
]);
|
||||||
});
|
expect(getTriggerText("[capture1][capture2]", 11)).toEqual([
|
||||||
test("text with aliased markdown link", () => {
|
"capture2",
|
||||||
expect(getTriggerText("[[[test|display]]] testing", 1)).toEqual([
|
11,
|
||||||
"[[test|display]]",
|
19,
|
||||||
1,
|
|
||||||
17,
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
test("text with wiki link", () => {
|
test("wiki link", () => {
|
||||||
expect(
|
expect(getTriggerText("[test [[test]]]", 1)).toEqual([
|
||||||
getTriggerText("[[[test](https://example.com)]] testing", 1),
|
"test [[test]]",
|
||||||
).toEqual(["[[test](https://example.com)]", 1, 30]);
|
|
||||||
});
|
|
||||||
test("text with wiki link local", () => {
|
|
||||||
expect(getTriggerText("[[[test](test)]] testing", 1)).toEqual([
|
|
||||||
"[[test](test)]",
|
|
||||||
1,
|
1,
|
||||||
15,
|
14,
|
||||||
|
]);
|
||||||
|
expect(getTriggerText("[test [[test]]]", 14)).toEqual([
|
||||||
|
"test [[test]]",
|
||||||
|
1,
|
||||||
|
14,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
test("aliased wiki link", () => {
|
||||||
|
expect(getTriggerText("[test [[test|display]]]", 1)).toEqual([
|
||||||
|
"test [[test|display]]",
|
||||||
|
1,
|
||||||
|
22,
|
||||||
|
]);
|
||||||
|
expect(getTriggerText("[test [[test|display]]]", 22)).toEqual([
|
||||||
|
"test [[test|display]]",
|
||||||
|
1,
|
||||||
|
22,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
test("markdown link", () => {
|
||||||
|
expect(getTriggerText("[[test](https://example.com)]", 1)).toEqual([
|
||||||
|
"[test](https://example.com)",
|
||||||
|
1,
|
||||||
|
28,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
test("markdown link local", () => {
|
||||||
|
expect(getTriggerText("[[test](test)]", 1)).toEqual([
|
||||||
|
"[test](test)",
|
||||||
|
1,
|
||||||
|
13,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -235,22 +282,20 @@ describe("trigger", () => {
|
|||||||
|
|
||||||
describe("ignore plain markdown links", () => {
|
describe("ignore plain markdown links", () => {
|
||||||
test("cursor in link text", () => {
|
test("cursor in link text", () => {
|
||||||
expect(
|
expect(getTriggerText("[test](https://example.com)", 3)).toEqual(
|
||||||
getTriggerText("test [test](https://example.com)", 8),
|
|
||||||
).toEqual(null);
|
|
||||||
});
|
|
||||||
test("cursor in link url", () => {
|
|
||||||
expect(
|
|
||||||
getTriggerText("test [test](https://example.com)", 15),
|
|
||||||
).toEqual(null);
|
|
||||||
});
|
|
||||||
test("cursor in empty link text", () => {
|
|
||||||
expect(getTriggerText("test [](https://example.com)", 6)).toEqual(
|
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
test("cursor in link url", () => {
|
||||||
|
expect(getTriggerText("[test](https://example.com)", 11)).toEqual(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("cursor in empty link text", () => {
|
||||||
|
expect(getTriggerText("[](https://example.com)", 1)).toEqual(null);
|
||||||
|
});
|
||||||
test("cursor in empty link url", () => {
|
test("cursor in empty link url", () => {
|
||||||
expect(getTriggerText("test [test]()", 12)).toEqual(null);
|
expect(getTriggerText("[test]()", 7)).toEqual(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user