Last active
September 3, 2017 16:54
-
-
Save searls/94d78b546130205a0276beb2519f6d09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SplitsFuriganaTest < ActiveSupport::TestCase | |
def setup | |
@subject = SplitsFurigana.new | |
end | |
def test_some_basics | |
# No reading, no fuss | |
assert_equal [h("ひろ", nil)], @subject.call("ひろ", nil) | |
# All kanji, no splitting | |
assert_equal [h("僕", "ぼく")], @subject.call("僕", "ぼく") | |
assert_equal [h("兄弟", "きょうだい")], @subject.call("兄弟", "きょうだい") | |
# Partial coverage gets split (no furigana over kana, no repitition | |
assert_equal [h("眠", "ねむ"), h("ら", nil)], @subject.call("眠ら", "ねむら") | |
# Split partial when the leading is hiragan too | |
assert_equal [h("お", nil), h("金", "かね")], @subject.call("お金", "おかね") | |
# Hiragana in the middle | |
assert_equal [h("女", "おんな"), h("の", nil), h("子", "こ")], @subject.call("女の子", "おんなのこ") | |
# Pronunciation of numbers changes, so furigana over them | |
assert_equal [h("6月", "ろくがつ")], @subject.call("6月", "ろくがつ") | |
# Romaji may have furigana too, but there are furigan | |
assert_equal [h("VISA", "びさ")], @subject.call("VISA", "びさ") | |
end | |
def test_nasty_edge_cases | |
# All katakana & punctuation, no kanji, no furigana: | |
assert_equal [h("ザ・ベスト", nil)], @subject.call("ザ・ベスト", "ざべすと") | |
# A reading can be shorter than the kanji | |
assert_equal [h("啄木鳥", "けら")], @subject.call("啄木鳥", "けら") | |
end | |
private | |
def h(text, kana) | |
SplitsFurigana::FuriganaPair.new(text, kana) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment