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&amp;action=edit&amp;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(&quot;Module:UnitTests&quot;)<br /> <br /> local m_scripts = require(&quot;Module:scripts&quot;)<br /> local m_script_utils = require(&quot;Module:script utilities&quot;)<br /> local getLangByCode = require(&quot;Module:languages&quot;).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(&#039;&lt;span class=&quot;%s&quot;&gt;%s&lt;/span&gt;&#039;, sc, char)<br /> end<br /> <br /> function tests:checkFindBestScript(example, langCode, expected)<br /> local lang = getLangByCode(langCode)<br /> self:equals(tag(example, lang, expected) .. &quot; (&quot; .. lang:getCanonicalName() .. &quot;)&quot;,<br /> lang:findBestScript(example):getCode(),<br /> expected)<br /> end<br /> <br /> function tests:testFindbestScript()<br /> local examples = {<br /> { &quot;word&quot;, &quot;en&quot;, &quot;Latn&quot; },<br /> { &quot;العربية&quot;, &quot;ar&quot;, &quot;Arab&quot; },<br /> { &quot;عرب&quot;, &quot;fa&quot;, &quot;fa-Arab&quot; },<br /> { &quot;большо́й&quot;, &quot;ru&quot;, &quot;Cyrl&quot; },<br /> { &quot;ругала се шерпа лонцу широка му уста&quot;, &quot;sh&quot;, &quot;Cyrl&quot; },<br /> &quot;Scripts with overlapping characters&quot;,<br /> { &quot;Русь&quot;, &quot;orv&quot;, &quot;Cyrs&quot; },<br /> { &quot;Русь&quot;, &quot;ru&quot;, &quot;Cyrl&quot; },<br /> { &quot;λόγος&quot;, &quot;grc&quot;, &quot;Polyt&quot; },<br /> { &quot;λόγος&quot;, &quot;el&quot;, &quot;Grek&quot; },<br /> }<br /> <br /> tests:iterate(examples, &quot;checkFindBestScript&quot;)<br /> end<br /> <br /> function tests:testCharToScript()<br /> local U = mw.ustring.char<br /> local examples = {<br /> { &quot;A&quot;, &quot;Latn&quot; },<br /> { &quot;一&quot;, &quot;Hani&quot; },<br /> { &quot;ώ&quot;, &quot;Grek&quot; },<br /> { &quot;ὦ&quot;, &quot;Polyt&quot; },<br /> { &quot;Ж&quot;, &quot;Cyrl&quot; },<br /> { &quot;Ѹ&quot;, &quot;Cyrs&quot; },<br /> { &quot;ꙑ&quot;, &quot;Cyrs&quot; },<br /> { &quot;ა&quot;, &quot;Geor&quot; },<br /> { &quot;Ⴀ&quot;, &quot;Geok&quot; },<br /> { &quot;ⴀ&quot;, &quot;Geok&quot; },<br /> { &quot;!&quot;, &quot;None&quot; },<br /> { U(0x2F82B), &quot;None&quot; },<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