-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
54 lines (49 loc) · 1.57 KB
/
test.js
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
const assert = require("assert");
const https = require("https");
const stream = require("stream");
const linesStream = require("@orisano/lines-stream");
const graphemesplit = require("./");
https.get(
"https://www.unicode.org/Public/15.0.0/ucd/auxiliary/GraphemeBreakTest.txt",
(res) => {
const { statusCode } = res;
if (statusCode !== 200) {
console.error(`failed to http request: ${statusCode}`);
res.resume();
return;
}
res
.pipe(linesStream())
.pipe(
new stream.Transform({
decodeStrings: false,
readableObjectMode: true,
transform(line, encoding, callback) {
callback();
if (line.trim().length === 0) return;
const [body, description] = line.split("#");
const test = body.trim();
if (test.length === 0) return;
const graphemeClusters = test
.split("÷")
.filter((x) => x.length > 0)
.map((x) => {
const codePoints = x
.split("×")
.map((y) => parseInt(y.trim(), 16));
return String.fromCodePoint(...codePoints);
});
this.push({ expected: graphemeClusters, description });
},
})
)
.on("data", ({ expected, description }) => {
const got = graphemesplit(expected.join(""));
assert.deepStrictEqual(
got,
expected,
`unexpected grapheme clusters. expected: ${expected}, but got: ${got} # ${description}`
);
});
}
);