update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Tests der reinen Module: gjs -m dev/tests/run.js
|
||||
import * as D from '../../desktop@marha.de/dates.js';
|
||||
import {renderMarkdown} from '../../desktop@marha.de/markdown.js';
|
||||
import {continueList, renderMarkdown} from '../../desktop@marha.de/markdown.js';
|
||||
import {batches, fileStamp, planPull, planPush, stampToSeconds} from '../../desktop@marha.de/files.js';
|
||||
|
||||
let failed = 0;
|
||||
function eq(actual, expected, name) {
|
||||
@@ -61,6 +62,33 @@ eq(renderMarkdown('---'), '<span foreground="#666666">────────
|
||||
eq(renderMarkdown('~~weg~~'), '<s>weg</s>', 'md strike');
|
||||
eq(renderMarkdown('a\n\nb'), 'a\n\nb', 'md leere Zeile bleibt');
|
||||
|
||||
eq(continueList('- eins'), '- ', 'Liste: nächster Punkt');
|
||||
eq(continueList(' * eins'), ' * ', 'Liste: Einrückung und Marker bleiben');
|
||||
eq(continueList('- [x] fertig'), '- [ ] ', 'Liste: Checkbox leer weiter');
|
||||
eq(continueList('3. drei'), '4. ', 'Liste: Nummer zählt hoch');
|
||||
eq(continueList('- '), '', 'Liste: leerer Punkt beendet');
|
||||
eq(continueList('2. '), '', 'Liste: leerer nummerierter Punkt beendet');
|
||||
eq(continueList('nur Text'), null, 'Liste: kein Marker');
|
||||
eq(continueList('---'), null, 'Liste: Trennlinie ist keine Liste');
|
||||
|
||||
const H = 3600, NOW = 1_800_000_000;
|
||||
eq(fileStamp(NOW), '2027-01-15T08:00:00.000Z', 'fileStamp');
|
||||
eq(stampToSeconds('2027-01-15T08:00:00.000Z'), NOW, 'stampToSeconds');
|
||||
const local = new Map([['a/s.jsonl', NOW - 2 * H], ['a/frisch.jsonl', NOW - 10], ['m/MEMORY.md', NOW - 3 * H]]);
|
||||
eq(planPush(local, {'m/MEMORY.md': fileStamp(NOW - 3 * H), 'weg.md': fileStamp(NOW - 5 * H), 'alt.md': null}, NOW, H),
|
||||
{upload: [{id: 'a/s.jsonl', updated: fileStamp(NOW - 2 * H)}], remove: ['weg.md']},
|
||||
'planPush: nur ruhende, geänderte Dateien hoch, Verschwundene als Tombstone, Gemeldete nicht nochmal');
|
||||
eq(planPull([
|
||||
{id: 'a/s.jsonl', updated: fileStamp(NOW - 1 * H), content: 'x'},
|
||||
{id: 'a/s.jsonl', updated: fileStamp(NOW - 3 * H), content: 'x'},
|
||||
{id: 'neu.md', updated: fileStamp(NOW), content: 'y'},
|
||||
{id: 'm/MEMORY.md', updated: fileStamp(NOW), deleted: true},
|
||||
{id: 'nie.md', updated: fileStamp(NOW), deleted: true},
|
||||
], local).map(p => `${p.file.id}:${p.action}`),
|
||||
['a/s.jsonl:write', 'a/s.jsonl:skip', 'neu.md:write', 'm/MEMORY.md:delete', 'nie.md:skip'], 'planPull: neuer schreibt, älter überspringt, Tombstone löscht');
|
||||
eq(batches([1, 2, 3, 4], n => n, 5), [[1, 2], [3], [4]], 'batches nach Größe');
|
||||
eq(batches([], n => n, 5), [], 'batches leer');
|
||||
|
||||
print(failed ? `\n${failed} FEHLER` : '\nalle Tests ok');
|
||||
if (failed)
|
||||
imports.system.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user