Module:ja/testcases

-- Unit tests for Module:ja. Click talk page to run tests. local p = require('Module:UnitTests') local m = require('Module:ja')

function p:r2k(original, katakana) self:equals(original, m.romaji_to_kata(original), katakana) end

function p:script_detection(original, script) self:equals(original, m.script(original), script) end

function p:k2h(original, hiragana) self:equals(original, m.kata_to_hira(original), hiragana) end

function p:h2k(original, katakana) self:equals(original, m.hira_to_kata(original), katakana) end

function p:other(fun, original, output) local mf

if fun == 'count_morae' then mf = m.count_morae elseif fun == 'rm_spaces_hyphens' then mf = m.rm_spaces_hyphens elseif fun == 'kanji_grade' then mf = m.kanji_grade end

self:equals(fun .. ': ' .. original, mf(original), output) end

function p:test_all self:r2k("ayekikye vyewifue", "アイェキキェ ヴィェウィフエ") self:r2k("shinkansen", "シンカンセン") self:r2k("shin'i", "シンイ") self:r2k("shin'ya shinya", "シンヤ シニャ") self:r2k("na ni nu ne no nya nyu nye nyo", "ナ ニ ヌ ネ ノ ニャ ニュ ニェ ニョ") self:r2k("bakkurasshu", "バックラッシュ")

self:script_detection('あいこくしん愛国心メ', 'Hira+Kana+Hani') self:script_detection('あいこくしん愛国心', 'Hira+Hani') self:script_detection('ァー', 'Kana') self:script_detection('あっぷるringo', 'Hira+Romaji') self:script_detection('ニッポン1１', 'Kana+Number') self:script_detection('ニッポンｎｉｐｐｏｎ', 'Kana+Romaji') self:script_detection('一つ', 'Hira+Hani') self:script_detection('〆る', 'Hira+Abbreviation')

self:k2h('アメリカじん', 'あめりかじん')

self:h2k('うぃきぺでぃあ　デス', 'ウィキペディア　デス')

self:other('count_morae', 'しゃっきんジャー', 6)

self:other('rm_spaces_hyphens', 'ishu kakutōgi sen', 'ishukakutōgisen')

self:other('kanji_grade', '立', 1) self:other('kanji_grade', '尊立', 6) self:other('kanji_grade', '藉尊立', 9) end return p