~bmp/hayom

hayom/test.ts -rw-r--r-- 2.3 KiB
9392a780Benjamin Pollack readme: add build status a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { assertEquals } from "https://deno.land/std@0.145.0/testing/asserts.ts";

import { 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);
});