一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
37 行
1.5 KiB
TypeScript
37 行
1.5 KiB
TypeScript
import { EditorSelection } from '@codemirror/state';
|
|
import createTestEditor from '../testing/createTestEditor';
|
|
import findPositionMatchingLink from './findPositionMatchingLink';
|
|
|
|
describe('findPositionMatchingLink', () => {
|
|
test.each([
|
|
// Should match headings
|
|
['# Heading\n', '#heading', '# Heading'.length],
|
|
['# Heading', '#heading', '# Heading'.length],
|
|
['## Heading', '#heading', '## Heading'.length],
|
|
['### Heading', '#heading', '### Heading'.length],
|
|
// Should match headings not on the first line
|
|
['\n### Heading', '#heading', '\n### Heading'.length],
|
|
['# Test\n\n### Heading', '#heading', '# Test\n\n### Heading'.length],
|
|
['# Test\n\n### Heading\n\ntest', '#heading', '# Test\n\n### Heading'.length],
|
|
// Should return null when there are no matches
|
|
['# Heading', '#missing-heading', null],
|
|
|
|
// Should match footnotes
|
|
['[^1]: Footnote!\n', '[^1]', '[^1]: Footnote!'.length],
|
|
['[^1]: Footnote!\n[^2]: Other footnote.', '[^1]', '[^1]: Footnote!'.length],
|
|
['# ^1\n[^1]: Footnote!\n[^2]: Other footnote.', '[^1]', '# ^1\n[^1]: Footnote!'.length],
|
|
['# ^1\n[^1]: Footnote!\n[^2]: Other footnote.', '[^not a footnote]', null],
|
|
|
|
// Should not process http:// links
|
|
['# Test', 'http://example.com', null],
|
|
|
|
])('should correctly find lines matching the given link (doc: %j, link: %j) (case %#)', async (
|
|
doc, link, expectedMatchingLine,
|
|
) => {
|
|
const editor = await createTestEditor(doc, EditorSelection.cursor(0), []);
|
|
expect(
|
|
findPositionMatchingLink(link, editor.state) ?? null,
|
|
).toBe(expectedMatchingLine);
|
|
});
|
|
});
|