Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 

















Module:Lang/testcases/ISO 639 deprecated and override tag from name







Add links
 









Module
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

< Module:Lang | testcases

local p = require('Module:UnitTests')

--[[--------------------------< T E S T _ P A T T E R N S _ G E T >--------------------------------------------

build a table of test patterns where each entry in the table is a table with two members:
 {"<name>", "<tag>"}

TODO: make this series of test smart enough to include:
 disambiguated names
 disambiguated names with dab removed (not so straigh-forward as that appears)
  see Module:Lang/name to tag/sandbox (may get moved to name_from_tag)

]]

local function test_patterns_get(lanauage_list)
 local lang_data =  mw.loadData('Module:Lang/data');        -- language name override and transliteration tool-tip tables
 local override_table = lang_data.override;
 local tpats = {}               -- collect test patterns here
 for tag, names in pairs (lanauage_list) do
  local pattern = {};              -- here we assemble the test pattern for <name>
  if override_table[tag] then
   table.insert (pattern, override_table[tag][1]);     -- add first <name> only to the pattern
   table.insert (pattern, tag);         -- add the 'expected result' <tag>
  else
   table.insert (pattern, names[1]);        -- add first <name> only to the pattern
   table.insert (pattern, tag);         -- add the 'expected result' <tag>
  end
  table.insert (tpats, pattern);          -- accumulate in list of patterns
 end

 local function comp (a, b)             -- local function used by table.sort()
  return a[2] < b[2];              -- ascending sort by code (because test limits are by code)
 end
 
 table.sort (tpats, comp);             -- make the list pretty
 return tpats;                -- and done
end




--[[--------------------------< T E S T _ T A G _ F R O M _ N A M E >------------------------------------------
]]

function p:test_tag_from_name_iso_639_deprecated()
 local test_patterns = test_patterns_get(mw.loadData("Module:Language/data/iana languages").deprecated)
 self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|tag_from_name|', '}}', '', '', test_patterns, {nowiki=1})
end

function p:test_tag_from_name_iso_639_override()
 local test_patterns = test_patterns_get(mw.loadData('Module:Lang/data').override)
 self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|tag_from_name|', '}}', '', '', test_patterns, {nowiki=1})
end

return p

Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Lang/testcases/ISO_639_deprecated_and_override_tag_from_name&oldid=981638243"





This page was last edited on 3 October 2020, at 15:18 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki