https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AScripts%2Ftestcases
Module:Scripts/testcases - Revision history
2025-05-26T02:14:18Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.2
https://en.wikipedia.org/w/index.php?title=Module:Scripts/testcases&diff=1185976284&oldid=prev
Alexis Jazz: Imported page from https://en.wiktionary.org/wiki/Module:scripts/testcases AJsImportTool]
2023-11-20T04:04:37Z
<p>Imported page from https://en.wiktionary.org/wiki/Module:scripts/testcases [<a href="/w/index.php?title=User:Alexis_Jazz/AJsImportTool.js&action=edit&redlink=1" class="new" title="User:Alexis Jazz/AJsImportTool.js (page does not exist)">AJsImportTool</a>]</p>
<p><b>New page</b></p><div>local tests = require("Module:UnitTests")<br />
<br />
local m_scripts = require("Module:scripts")<br />
local m_script_utils = require("Module:script utilities")<br />
local getLangByCode = require("Module:languages").getByCode<br />
<br />
local function tag(text, lang, scCode)<br />
return m_script_utils.tag_text(text, lang, m_scripts.getByCode(scCode))<br />
end<br />
<br />
local function tagScript(char, sc)<br />
return string.format('<span class="%s">%s</span>', sc, char)<br />
end<br />
<br />
function tests:checkFindBestScript(example, langCode, expected)<br />
local lang = getLangByCode(langCode)<br />
self:equals(tag(example, lang, expected) .. " (" .. lang:getCanonicalName() .. ")",<br />
lang:findBestScript(example):getCode(),<br />
expected)<br />
end<br />
<br />
function tests:testFindbestScript()<br />
local examples = {<br />
{ "word", "en", "Latn" },<br />
{ "العربية", "ar", "Arab" },<br />
{ "عرب", "fa", "fa-Arab" },<br />
{ "большо́й", "ru", "Cyrl" },<br />
{ "ругала се шерпа лонцу широка му уста", "sh", "Cyrl" },<br />
"Scripts with overlapping characters",<br />
{ "Русь", "orv", "Cyrs" },<br />
{ "Русь", "ru", "Cyrl" },<br />
{ "λόγος", "grc", "Polyt" },<br />
{ "λόγος", "el", "Grek" },<br />
}<br />
<br />
tests:iterate(examples, "checkFindBestScript")<br />
end<br />
<br />
function tests:testCharToScript()<br />
local U = mw.ustring.char<br />
local examples = {<br />
{ "A", "Latn" },<br />
{ "一", "Hani" },<br />
{ "ώ", "Grek" },<br />
{ "ὦ", "Polyt" },<br />
{ "Ж", "Cyrl" },<br />
{ "Ѹ", "Cyrs" },<br />
{ "ꙑ", "Cyrs" },<br />
{ "ა", "Geor" },<br />
{ "Ⴀ", "Geok" },<br />
{ "ⴀ", "Geok" },<br />
{ "!", "None" },<br />
{ U(0x2F82B), "None" },<br />
}<br />
<br />
self:iterate(<br />
examples,<br />
function (self, char, expected)<br />
local sc = m_scripts.charToScript(char)<br />
self:equals(<br />
tagScript(char, sc),<br />
sc,<br />
expected<br />
)<br />
end)<br />
end<br />
<br />
return tests</div>
Alexis Jazz