Module:User:Erutuon/scripts/testcases

local tests = require("Module:UnitTests")

local find_best_script = require "Module:User:Erutuon/scripts".find_best_script local tag_text = require "Module:script utilities".tag_text local get_lang_by_code = require("Module:languages").getByCode local get_script_by_code = require "Module:scripts".getByCode

local function tag(text, lang, scCode) return tag_text(text, lang, get_script_by_code(scCode)) end

function tests:check_find_best_script(example, lang_code, expected) local lang = get_lang_by_code(lang_code) self:equals(tag(example, lang, expected) .. " (" .. lang:getCanonicalName .. ")",		find_best_script(example, lang_code),		expected) end

function tests:test_find_best_script local examples = { { "word", "en", "Latn" }, { "большо́й", "ru", "Cyrl" }, { "ругала се шерпа лонцу широка му уста", "sh", "Cyrl" }, "Scripts with overlapping characters", { "my", "en", "Latn" }, { "my", "egy", "Latnx" }, { "Русь", "orv", "Cyrs" }, { "Русь", "ru", "Cyrl" }, { "λόγος", "grc", "polytonic" }, { "λόγος", "el", "Grek" }, "Scripts using the exact same characters as another script", { "anaasází", "nv", "nv-Latn" }, { "العربية", "ar", "Arab" }, { "عرب", "fa", "fa-Arab" }, "Scripts consisting of two or more other scripts", { "ああ言えばこう言う", "ja", "Jpan" }, { "アイリッシュ海", "ja", "Jpan" }, "Scripts sometimes containing characters of another script", { "ABC順", "ja", "Jpan" }, { "OX로", "ko", "Kore" }, "Extraneous characters", { "<<<>>>", "en", "Latn" }, }	tests:iterate(examples, "check_find_best_script") end

return tests