aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-10 12:31:06 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-10 12:31:06 -0400
commitfb87b1ad69b37e75d1e2e46c91235aa6b44c2980 (patch)
tree1333e24fbf7b015cd987787aa21af1269a6e3b71
parent0b7791c103508e4b23d57717a97644993edf76d5 (diff)
Add tests
-rw-r--r--test/test-japanese.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/test-japanese.js b/test/test-japanese.js
index ca65dde2..ac28a579 100644
--- a/test/test-japanese.js
+++ b/test/test-japanese.js
@@ -394,6 +394,50 @@ function testDistributeFuriganaInflected() {
}
}
+function testCollapseEmphaticSequences() {
+ const data = [
+ [['かこい', false], ['かこい', [1, 1, 1]]],
+ [['かこい', true], ['かこい', [1, 1, 1]]],
+ [['かっこい', false], ['かっこい', [1, 1, 1, 1]]],
+ [['かっこい', true], ['かこい', [2, 1, 1]]],
+ [['かっっこい', false], ['かっこい', [1, 2, 1, 1]]],
+ [['かっっこい', true], ['かこい', [3, 1, 1]]],
+ [['かっっっこい', false], ['かっこい', [1, 3, 1, 1]]],
+ [['かっっっこい', true], ['かこい', [4, 1, 1]]],
+
+ [['こい', false], ['こい', [1, 1]]],
+ [['こい', true], ['こい', [1, 1]]],
+ [['っこい', false], ['っこい', [1, 1, 1]]],
+ [['っこい', true], ['こい', [2, 1]]],
+ [['っっこい', false], ['っこい', [2, 1, 1]]],
+ [['っっこい', true], ['こい', [3, 1]]],
+ [['っっっこい', false], ['っこい', [3, 1, 1]]],
+ [['っっっこい', true], ['こい', [4, 1]]],
+
+ [['', false], ['', []]],
+ [['', true], ['', []]],
+ [['っ', false], ['っ', [1]]],
+ [['っ', true], ['', [1]]],
+ [['っっ', false], ['っ', [2]]],
+ [['っっ', true], ['', [2]]],
+ [['っっっ', false], ['っ', [3]]],
+ [['っっっ', true], ['', [3]]]
+ ];
+
+ for (const [[text, fullCollapse], [expected, expectedSourceMapping]] of data) {
+ const sourceMap = new TextSourceMap(text);
+ const actual1 = jp.collapseEmphaticSequences(text, fullCollapse, null);
+ const actual2 = jp.collapseEmphaticSequences(text, fullCollapse, sourceMap);
+ assert.strictEqual(actual1, expected);
+ assert.strictEqual(actual2, expected);
+ if (typeof expectedSourceMapping !== 'undefined') {
+ console.log('actual', JSON.stringify(actual1), sourceMap);
+ console.log('expected', JSON.stringify(expected), new TextSourceMap(text, expectedSourceMapping));
+ assert.ok(sourceMap.equals(new TextSourceMap(text, expectedSourceMapping)));
+ }
+ }
+}
+
function testIsMoraPitchHigh() {
const data = [
[[0, 0], false],
@@ -463,6 +507,7 @@ function main() {
testConvertAlphabeticToKana();
testDistributeFurigana();
testDistributeFuriganaInflected();
+ testCollapseEmphaticSequences();
testIsMoraPitchHigh();
testGetKanaMorae();
}