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