A command-line journaling application
at main 90 lines 2.9 kB view raw
1import { assertEquals } from "@std/assert"; 2 3import { filterEntries, makeEntry, parseEntries, renderEntry } from "./mod.ts"; 4 5Deno.test("make sure we can generate simple entries", () => { 6 const raw = "This is a simple test"; 7 const entry = makeEntry(raw); 8 assertEquals(entry.title, "This is a simple test"); 9 assertEquals(entry.body, ""); 10}); 11 12Deno.test("make sure we can generate entries with a period", () => { 13 const raw = "This is a simple test."; 14 const entry = makeEntry(raw); 15 assertEquals(entry.title, "This is a simple test."); 16 assertEquals(entry.body, ""); 17}); 18 19Deno.test("make sure we can generate complex entries", () => { 20 const raw = "This is a simple test! How can you not understand that?!"; 21 const entry = makeEntry(raw); 22 assertEquals(entry.title, "This is a simple test!"); 23 assertEquals(entry.body, "How can you not understand that?!"); 24}); 25 26Deno.test("test multiline entries", () => { 27 const raw = 28 "This is a simple test?! I guess so.\nBut how can you be sure? What should we\nbe doing?!"; 29 const entry = makeEntry(raw); 30 assertEquals(entry.title, "This is a simple test?!"); 31 assertEquals( 32 entry.body, 33 "I guess so.\nBut how can you be sure? What should we\nbe doing?!", 34 ); 35}); 36 37Deno.test("test multiparse with a single entry", () => { 38 const raw = 39 "This is a simple test?! I guess so.\nBut how can you be sure? What should we\nbe doing?!"; 40 const cleanEntry = makeEntry(raw); 41 const parsedEntry = parseEntries(renderEntry(cleanEntry))[0]; 42 assertEquals(parsedEntry.title, "This is a simple test?!"); 43 assertEquals( 44 parsedEntry.body, 45 "I guess so.\nBut how can you be sure? What should we\nbe doing?!", 46 ); 47}); 48 49Deno.test("round trip of multiple entries", () => { 50 const multiple = `[1999-12-31 23:59] This is it! 51It's about to be the new century! I can't wait! 52 53[2000-01-01 00:00] Oh Cthulhu oh crap oh spaghetti 54Everything has collapsed, society is imploding. 55 56[2000-01-01 00:01] Every man for himself. 57That means you're on your own, my little hamster. Good luck and godspeed. 58`; 59 const entries = parseEntries(multiple); 60 assertEquals(entries.length, 3); 61 assertEquals(entries[0].title, "This is it!"); 62 assertEquals( 63 entries[1].body, 64 "Everything has collapsed, society is imploding.", 65 ); 66 assertEquals(entries.map(renderEntry).join("\n"), multiple); 67}); 68 69Deno.test("filter entries with limit returns last N entries", () => { 70 const multiple = `[2000-01-01 00:00] First entry 71Entry one body 72 73[2000-01-02 00:00] Second entry 74Entry two body 75 76[2000-01-03 00:00] Third entry 77Entry three body 78 79[2000-01-04 00:00] Fourth entry 80Entry four body 81 82[2000-01-05 00:00] Fifth entry 83Entry five body 84`; 85 const entries = parseEntries(multiple); 86 const filtered = filterEntries(entries, { limit: 2 }); 87 assertEquals(filtered.length, 2); 88 assertEquals(filtered[0].title, "Fourth entry"); 89 assertEquals(filtered[1].title, "Fifth entry"); 90});