forked from justjavac/zhihu-trending-hot-questions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.test.ts
80 lines (71 loc) · 2.34 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
74
75
76
77
78
79
80
#!/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 { Question } from "./types.ts";
import {
createArchive,
createList,
createReadme,
mergeQuestions,
} from "./utils.ts";
Deno.test("mergeQuestions", function (): void {
const words1: Question[] = [];
const words2: Question[] = [{ title: "foo", url: "bar" }];
const words3: Question[] = [{ title: "foo", url: "hello" }];
const words4: Question[] = [{ title: "hello", url: "world" }];
const words5: Question[] = [
{ title: "foo", url: "bar" },
{ title: "hello", url: "world" },
];
assertEquals(mergeQuestions(words1, words2), words2);
assertEquals(mergeQuestions(words1, words5), words5);
assertEquals(mergeQuestions(words2, words2), words2);
assertEquals(
mergeQuestions(words2, words3),
[
{ title: "foo", url: "bar" },
{ title: "foo", url: "hello" },
],
);
assertEquals(mergeQuestions(words4, words5), [
{ title: "hello", url: "world" },
{ title: "foo", url: "bar" },
]);
assertEquals(
mergeQuestions(words3, words5),
[
{ title: "foo", url: "hello" },
{ title: "foo", url: "bar" },
{ title: "hello", url: "world" },
],
);
});
Deno.test("createList", function (): void {
const words: Question[] = [
{ 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: Question[] = [
{ 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: Question[] = [
{ title: "foo", url: "bar" },
{ title: "hello", url: "world" },
];
assertStringIncludes(await createReadme(words), "知乎");
assertStringIncludes(
await createReadme(words),
"zhihu-trending-hot-questions",
);
});