-
Notifications
You must be signed in to change notification settings - Fork 1
/
silicon_test.ts
103 lines (94 loc) · 1.88 KB
/
silicon_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import {
assertEquals,
assertNotEquals,
assertThrows,
path,
} from "./deps_test.ts";
import { generate, themeList } from "./silicon.ts";
function assertImage(data: Uint8Array) {
const header = data.slice(0, 8);
const pngHeader = new Uint8Array([
0x89,
0x50,
0x4e,
0x47,
0x0d,
0x0a,
0x1a,
0x0a,
]);
assertEquals(header, pngHeader);
}
Deno.test({
name: "get theme list",
fn: () => {
const got = themeList();
assertNotEquals(got.length, 0);
},
});
Deno.test({
name: "generate image",
fn: () => {
const code = `package main
import {
"fmt"
}
func main() {
fmt.Println("Hello World")
}`;
const got = generate(code, "go");
assertImage(got);
},
});
Deno.test({
name: "generate image with options",
fn: async () => {
const code = new TextDecoder().decode(
await Deno.readFile(path.join("testdata", "main.rs")),
);
const got = generate(code, "rs", {
no_line_number: true,
no_round_corner: false,
no_window_controls: true,
background_color: "#CCCCCC",
highlight_lines: "5-7",
line_offset: 1,
line_pad: 2,
pad_horiz: 50,
pad_vert: 50,
shadow_blur_radius: 10.5,
shadow_offset_x: 10,
shadow_offset_y: 10,
shadow_color: "#003399",
tab_width: 10,
theme: "Solarized (dark)",
});
assertImage(got);
},
});
Deno.test({
name: "invalid options",
fn: () => {
assertThrows(
() => {
generate("", "rs", { theme: "hoge" });
},
Error,
"unsupported theme",
);
assertThrows(
() => {
generate("", "rs", { background_color: "hoge" });
},
Error,
"cannot generate image: invalid color",
);
assertThrows(
() => {
generate("", "rs", { highlight_lines: "1;" });
},
Error,
"cannot parse integer from empty string",
);
},
});