A command-line journaling application
1import { assertEquals } from "https://deno.land/std@0.219.0/assert/mod.ts";
2
3import { 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});