1/**
2 * Tests for the LinkWizard class
3 *
4 * This is a simple self-contained test suite until we introduce a proper way to run JavaScript tests
5 * in DokuWiki.
6 *
7 * Needs to be run manually as:
8 *
9 * cat linkwiz.js linkwiz.test.js | node
10 */
11
12function runLinkWizardTests() {
13    const testCases = [
14        { ref: 'a:b:c', id: 'a:b:d', expected: 'd' },
15        { ref: 'a:b:c', id: 'a:b:c:d:e', expected: '.:c:d:e' },
16        { ref: 'a:b:c', id: 'a:b:c:d:e', expected: '.:c:d:e' },
17        { ref: 'a', id: 'a:b:c', expected: 'a:b:c' },
18        { ref: 'a:b', id: 'c:d', expected: 'c:d' },
19        { ref: 'a:b:c', id: 'a:d:e', expected: '..:d:e' },
20        { ref: 'a:b:c:d', id: 'a:d:e', expected: '..:..:d:e' },
21        { ref: 'a:b', id: 'c', expected: ':c' },
22    ];
23
24    testCases.forEach(({ ref, id, expected }, index) => {
25        const result = LinkWizard.createRelativeID(ref, id);
26        if (result === expected) {
27            console.log(`Test ${index + 1} passed`);
28        } else {
29            console.log(`Test ${index + 1} failed: expected ${expected}, got ${result}`);
30        }
31    });
32}
33
34// Run the tests
35runLinkWizardTests();
36