forked from justjavac/weibo-trending-hot-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.test.ts
73 lines (64 loc) · 2.19 KB
/
utils.test.ts
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
68
69
70
71
72
73
#!/usr/bin/env -S deno run --unstable --allow-net --allow-read --allow-write --import-map=import_map.json
import { assertEquals, assertStringIncludes } from "std/testing/asserts.ts";
import type { Word } from "./types.ts";
import { createArchive, createList, createReadme, mergeWords } from "./utils.ts";
Deno.test("mergeWords", function (): void {
const words1: Word[] = [];
const words2: Word[] = [{ title: "foo", url: "bar" }];
const words3: Word[] = [{ title: "foo", url: "hello" }];
const words4: Word[] = [{ title: "hello", url: "world" }];
const words5: Word[] = [
{ title: "foo", url: "bar" },
{ title: "hello", url: "world" },
];
assertEquals(mergeWords(words1, words2), words2);
assertEquals(mergeWords(words1, words5), words5);
assertEquals(mergeWords(words2, words2), words2);
assertEquals(
mergeWords(words2, words3),
[
{ title: "foo", url: "hello" },
],
);
assertEquals(mergeWords(words4, words5), [
{ title: "hello", url: "world" },
{ title: "foo", url: "bar" },
]);
assertEquals(
mergeWords(words3, words5),
[
{ title: "foo", url: "bar" },
{ title: "hello", url: "world" },
],
);
});
Deno.test("createList", function (): void {
const words: Word[] = [
{ title: "foo", url: "bar" },
{ title: "hello", url: "world" },
];
assertStringIncludes(createList(words), "<!-- BEGIN -->");
assertStringIncludes(createList(words), "<!-- END -->");
assertStringIncludes(createList(words), "foo");
assertStringIncludes(createList(words), "world");
assertStringIncludes(createList(words), "hello");
});
Deno.test("createArchive", function (): void {
const words: Word[] = [
{ title: "foo", url: "bar" },
{ title: "hello", url: "world" },
];
assertStringIncludes(createArchive(words, "2020-02-02"), "# 2020-02-02");
assertStringIncludes(createArchive(words, "2020-02-02"), "共 2 条");
});
Deno.test("createReadme", async function (): Promise<void> {
const words: Word[] = [
{ title: "foo", url: "bar" },
{ title: "hello", url: "world" },
];
assertStringIncludes(await createReadme(words), "微博");
assertStringIncludes(
await createReadme(words),
"weibo-trending-hot-search",
);
});