import { assertEquals } from "@std/assert"; import { filterEntries, makeEntry, parseEntries, renderEntry } from "./mod.ts"; Deno.test("make sure we can generate simple entries", () => { const raw = "This is a simple test"; const entry = makeEntry(raw); assertEquals(entry.title, "This is a simple test"); assertEquals(entry.body, ""); }); Deno.test("make sure we can generate entries with a period", () => { const raw = "This is a simple test."; const entry = makeEntry(raw); assertEquals(entry.title, "This is a simple test."); assertEquals(entry.body, ""); }); Deno.test("make sure we can generate complex entries", () => { const raw = "This is a simple test! How can you not understand that?!"; const entry = makeEntry(raw); assertEquals(entry.title, "This is a simple test!"); assertEquals(entry.body, "How can you not understand that?!"); }); Deno.test("test multiline entries", () => { const raw = "This is a simple test?! I guess so.\nBut how can you be sure? What should we\nbe doing?!"; const entry = makeEntry(raw); assertEquals(entry.title, "This is a simple test?!"); assertEquals( entry.body, "I guess so.\nBut how can you be sure? What should we\nbe doing?!", ); }); Deno.test("test multiparse with a single entry", () => { const raw = "This is a simple test?! I guess so.\nBut how can you be sure? What should we\nbe doing?!"; const cleanEntry = makeEntry(raw); const parsedEntry = parseEntries(renderEntry(cleanEntry))[0]; assertEquals(parsedEntry.title, "This is a simple test?!"); assertEquals( parsedEntry.body, "I guess so.\nBut how can you be sure? What should we\nbe doing?!", ); }); Deno.test("round trip of multiple entries", () => { const multiple = `[1999-12-31 23:59] This is it! It's about to be the new century! I can't wait! [2000-01-01 00:00] Oh Cthulhu oh crap oh spaghetti Everything has collapsed, society is imploding. [2000-01-01 00:01] Every man for himself. That means you're on your own, my little hamster. Good luck and godspeed. `; const entries = parseEntries(multiple); assertEquals(entries.length, 3); assertEquals(entries[0].title, "This is it!"); assertEquals( entries[1].body, "Everything has collapsed, society is imploding.", ); assertEquals(entries.map(renderEntry).join("\n"), multiple); }); Deno.test("filter entries with limit returns last N entries", () => { const multiple = `[2000-01-01 00:00] First entry Entry one body [2000-01-02 00:00] Second entry Entry two body [2000-01-03 00:00] Third entry Entry three body [2000-01-04 00:00] Fourth entry Entry four body [2000-01-05 00:00] Fifth entry Entry five body `; const entries = parseEntries(multiple); const filtered = filterEntries(entries, { limit: 2 }); assertEquals(filtered.length, 2); assertEquals(filtered[0].title, "Fourth entry"); assertEquals(filtered[1].title, "Fifth entry"); });