-
Notifications
You must be signed in to change notification settings - Fork 4
/
clippy_deprecated_test.ts
100 lines (92 loc) · 2.48 KB
/
clippy_deprecated_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
import { assertEquals } from "./deps_test.ts";
import { path } from "./deps.ts";
import { readAll } from "./deps_deprecated.ts";
import { clipboard as fallback } from "./platform/mod.ts";
import {
read_image,
read_text,
write_image,
write_text,
} from "./clippy_deprecated.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("image: write to/read from clipboard", async (t) => {
await t.step("write", async () => {
const file = path.join("testdata", "out.png");
const f = await Deno.open(file);
await write_image(f);
f.close();
});
await t.step("read", async () => {
const got = await readAll(await read_image());
assertImage(got);
});
});
Deno.test("text: write to/read from clipboard", async (t) => {
const text = "hello world";
await t.step("write", async () => {
await write_text(text);
});
await t.step("read", async () => {
const got = await read_text();
assertEquals(got, text);
});
});
Deno.test("check compatibility between fallback functions and dylib functions", async (t) => {
await t.step({
name: "text: write: fallback, read: dylib",
ignore: Deno.build.os == "linux",
fn: async () => {
const text = "hello clippy";
await fallback.writeText(text);
const got = await read_text();
assertEquals(got, text);
},
});
await t.step({
name: "text: write: dylib, read: fallback",
ignore: Deno.build.os == "linux",
fn: async () => {
const text = "hello clippy";
await write_text(text);
const got = await fallback.readText();
assertEquals(got, text);
},
});
await t.step({
name: "iamge: write: fallback, read: dylib",
ignore: Deno.build.os == "linux",
fn: async () => {
const file = path.join("testdata", "out.png");
const f = await Deno.open(file);
await fallback.writeImage(await readAll(f));
f.close();
const got = await readAll(await read_image());
assertImage(got);
},
});
await t.step({
name: "image write: dylib, read: fallback",
ignore: Deno.build.os == "linux",
fn: async () => {
const file = path.join("testdata", "out.png");
const f = await Deno.open(file);
await write_image(f);
f.close();
const got = await fallback.readImage();
assertImage(got);
},
});
});