-
Notifications
You must be signed in to change notification settings - Fork 855
/
Copy pathtransliterator_ja_spec.ts
105 lines (91 loc) · 6.37 KB
/
transliterator_ja_spec.ts
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
Copyright (c) 2012, Guillaume Marty
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
'use strict'
import { TransliterateJa as transliterateJa } from 'lib/natural'
describe('transliterateJa', function () {
it('should transliterate hiragana', function () {
expect(transliterateJa('あいうえお かきくけこ')).toEqual('aiueo kakikukeko')
expect(transliterateJa('さしすせそ たちつてと')).toEqual('sashisuseso tachitsuteto')
})
it('should transliterate katakana', function () {
expect(transliterateJa('アイウエオ カキクケコ')).toEqual('aiueo kakikukeko')
expect(transliterateJa('サシスセソ タチツテト')).toEqual('sashisuseso tachitsuteto')
})
it('should transliterate small tsu differently depending on context', function () {
expect(transliterateJa('まっか ざっし たった はっぱ')).toEqual('makka zasshi tatta happa')
expect(transliterateJa('マッカ ザッシ タッタ ハッパ')).toEqual('makka zasshi tatta happa')
})
it('should transliterate final small tsu', function () {
expect(transliterateJa('ああっ')).toEqual('aat')
expect(transliterateJa('アアッ')).toEqual('aat')
})
it('should transliterate n differently depending on context', function () {
expect(transliterateJa('まんと ばんび ほんや')).toEqual("manto bambi hon'ya")
expect(transliterateJa('マント バンビ ホンヤ')).toEqual("manto bambi hon'ya")
})
it('should transliterate long vowels', function () {
expect(transliterateJa('ああ いい うう ええ おお おう')).toEqual('aa ii ū ee oo ō')
expect(transliterateJa('あー いー うー えー おー')).toEqual('ā ī ū ē ō')
expect(transliterateJa('アア イイ ウウ エエ オオ オウ')).toEqual('aa ii ū ee oo ō')
expect(transliterateJa('アー イー ウー エー オー')).toEqual('ā ī ū ē ō')
})
it('should leave non fullwidth kana unchanged', function () {
expect(transliterateJa('abc ABC 漢字 (.)')).toEqual('abc ABC 漢字 (.)')
expect(transliterateJa('アイウエオ カキクケコ')).toEqual('アイウエオ カキクケコ')
})
it('should transliterate misc. words correctly', function () {
expect(transliterateJa('アヴァンギャルド')).toEqual('avangyarudo') // Avant-garde
expect(transliterateJa('アクサン・スィルコンフレックス')).toEqual('akusan sirukonfurekkusu') // Accent circonflexe
expect(transliterateJa('アドレシッング')).toEqual('adoreshinngu') // Addressing
expect(transliterateJa('イェス')).toEqual('yesu') // Yes
expect(transliterateJa('インテリジェンス')).toEqual('interijensu') // Intelligence
expect(transliterateJa('インテルメッツォ')).toEqual('interumettso') // Intermezzo
expect(transliterateJa('グァテマラ')).toEqual('gwatemara') // Guatemala
expect(transliterateJa('クァルテット')).toEqual('kwarutetto') // Quartet
expect(transliterateJa('クィンテット')).toEqual('kwintetto') // Quintet
expect(transliterateJa('クォーター')).toEqual('kwōtā') // Quarter
expect(transliterateJa('サブウーファー')).toEqual('sabuūfā') // Sub woofer
expect(transliterateJa('ソフトウェア')).toEqual('sofutowea') // Software
expect(transliterateJa('ツィーター')).toEqual('tsītā') // Tweeter
expect(transliterateJa('デューティー')).toEqual('dyūtī') // Duty
expect(transliterateJa('ドキュメントィンドウ')).toEqual('dokyumentwindō') // Document window
expect(transliterateJa('ヌーヴェルヴァーグ')).toEqual('nūveruvāgu') // Nouvelle vague
expect(transliterateJa('ハイジャッンプ')).toEqual('haijanmpu') // High jump
expect(transliterateJa('バッファ')).toEqual('baffa') // Buffer
expect(transliterateJa('フーホェア')).toEqual('fūhwea') // WhoWhere?
expect(transliterateJa('フェイズィング')).toEqual('feizingu') // Phasing
expect(transliterateJa('フッロピー')).toEqual('furropī') // Floppy (alternative transcription)
expect(transliterateJa('ブュー')).toEqual('byū') // View
expect(transliterateJa('フューチャー')).toEqual('fyūchā') // Future
expect(transliterateJa('フロッピィ')).toEqual('furoppī') // Floppy
expect(transliterateJa('ボージョレー・ヌーヴォー')).toEqual('bōjorē nūvō') // Beaujolais nouveau
expect(transliterateJa('ボスニア・ヘルツェゴビナ')).toEqual('bosunia herutsegobina') // Bosnia and Herzegovina
expect(transliterateJa('マッハ')).toEqual('mahha') // Mach
expect(transliterateJa('レヴュー')).toEqual('revyū') // Review
expect(transliterateJa('レクリェーション')).toEqual('rekuryēshon') // Recreation
})
it('should use fallback for small vowels on special case', function () {
// These words use rare combination of small vowels.
expect(transliterateJa('アゲィンスト')).toEqual('ageinsuto') // Against (alternative transcription)
expect(transliterateJa('エッセィ')).toEqual('essei') // Essay (alternative transcription)
expect(transliterateJa('ゾゥアラジィ')).toEqual('zouarajī') // Zoology (alternative transcription)
expect(transliterateJa('ゾゥァラジカル')).toEqual('zouarajikaru') // Zoological (alternative transcription)
expect(transliterateJa('ボランテァ')).toEqual('borantea') // Volunteer (alternative transcription)
})
})