-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
91 lines (78 loc) · 1.83 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
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
const af = require('./autofurigana');
Array.prototype.equals = function(array) {
if (!array)
return false;
if (this.length != array.length)
return false;
for (var i = 0; i < this.length; i++) {
if (this[i] instanceof Array && array[i] instanceof Array) {
if (!this[i].equals(array[i]))
return false;
} else if (this[i] != array[i]) {
return false;
}
}
return true;
}
const test = (desc, kanji, kana, out) => {
if (typeof test.ct_pass == 'undefined')
test.ct_pass = 0;
if (typeof test.ct_fail == 'undefined')
test.ct_fail = 0;
process.stdout.write("Test: " + desc + "... ");
let res = af.autofurigana(kanji, kana);
if (res.equals(out)) {
process.stdout.write("PASS\n");
test.ct_pass++;
} else {
process.stdout.write("FAIL\n");
console.log(res);
console.log(out);
test.ct_fail++;
}
}
test(
'Single kanji',
'家',
'いえ',
[ [ '家', 'いえ' ] ]
);
test(
'Multiple kanji',
'昨日',
'きのう',
[ [ '昨日', 'きのう' ] ]
);
test(
'Kanji with kana',
'走る',
'はしる',
[ [ '走', 'はし' ], [ 'る', null ] ]
);
test(
'Long mixture',
'走ることについて語るときに僕の語ること',
'はしることについてかたるときにぼくのかたること',
[ [ '走', 'はし' ],
[ 'ることについて', null ],
[ '語', 'かた' ],
[ 'るときに', null ],
[ '僕', 'ぼく' ],
[ 'の', null ],
[ '語', 'かた' ],
[ 'ること', null ] ]
);
test(
'String that could confuse the function',
'息抜き',
'いきぬき',
[ [ '息抜', 'いきぬ' ], [ 'き', null ] ]
);
test(
'Special characters in kanji',
'時々',
'ときどき',
[ [ '時々', 'ときどき' ] ]
);
console.log(test.ct_pass + ' tests passed.');
console.log(test.ct_fail + ' tests failed.');