-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorize_hanzi.test.js
More file actions
33 lines (27 loc) · 910 Bytes
/
Copy pathcolorize_hanzi.test.js
File metadata and controls
33 lines (27 loc) · 910 Bytes
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
c = require('./colorize_hanzi.js');
fixtures = [
["推薦信", "tuījiànxìn", [1, 4, 4]],
["軟體", "ruǎntǐ", [3, 3]],
];
let passed = 0, total = 0;
fixtures.forEach((fixture) => {
let hanzis, pinyin, exceptedTones;
[hanzis, pinyin, exceptedTones] = fixture;
let hanzisList = hanzis.split('');
let expectedHtml = exceptedTones
.map((tone) => {
let hanzi = hanzisList.shift();
return '<span class="tone tone-'+tone+'">'+hanzi+'</span>';
})
.join('');
let result = c.colorHanzi(hanzis, hanzis, pinyin);
let msg = hanzis + '(' + pinyin + ')' + ' tones are not ' + exceptedTones + ': ' + result;
let assertion = result == expectedHtml;
console.assert(assertion, msg);
passed += assertion;
total += 1;
});
console.log('Tests passed: ' + passed + '/' + total);
if (passed == total) {
console.log('All OK.')
}