-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck.js
47 lines (40 loc) · 1.05 KB
/
check.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
// @ts-check
import fs from 'fs';
import { 音韻地位 } from 'tshet-uinh';
const hanPattern =
/[\u3006\u3007\u4e00-\u9fff\u3400-\u4dbf\u{20000}-\u{2a6df}\u{2a700}-\u{2b73f}\u{2b740}-\u{2b81f}\u{2b820}-\u{2ceaf}\u{2ceb0}-\u{2ebef}\u{30000}-\u{3134f}]/u;
const data = fs.readFileSync('index.txt').toString();
const it = data[Symbol.iterator]();
for (;;) {
let res = it.next();
if (res.done) {
break;
}
const 字 = res.value;
if (!hanPattern.test(字)) {
continue;
}
res = it.next();
if (res.done || res.value !== '(') {
throw new Error(`expect '(' after ${字}`);
}
const chs = [];
for (;;) {
const { value, done } = it.next();
if (done) {
throw new Error(`expect ')' after ${字}`);
}
if (value === ')') {
break;
}
chs.push(value);
}
const 描述 = chs.join('');
const 地位 = 音韻地位.from描述(描述);
if (地位.描述 !== 描述) {
throw new Error(
`non-identical 地位 created from 描述: ${描述} -> ${地位.描述}`,
);
}
}
console.log('Test passed!');