Module:links/testcases

--[=[	Unit tests for Module:links. Click talk page to run tests. ]=]

local p = require('Module:UnitTests') local m_links = require('Module:links') local m_util = require('Module:utilities') local get_lang_by_code = require("Module:languages").getByCode

local function tag(lang_code, sc_code) return function (text) return '' .. text .. ' '	end end

local options = { nowiki = true, show_difference = true } function p:check_link(example, expected) self:preprocess_equals(example, expected, options) end

function p:test_links local frame = mw.getCurrentFrame local temp = frame.args.temp or "l" local compat = frame.args.compat local lang = compat and "lang=" or "" local link_examples = { 'anchor', {		'',		' -er ' },	{		'',		' -er ' },	'character entity references in link target', {		'',		' wa\'a ' },	{		'',		' wa\'a ' },	{		'',		' 恵&amp;#8204;美 ' },	{		'',		' &amp; ' },	'simple linking', -- (Module:languages) {		'',		' verbum ' },

'using wikilinks', {		'',		' God be with you ' },

'alternative text', {		'',		' went ' },	{		'',		' to go ' },

'sense id', {		'',		' go ' },

'constructed terms', -- (Module:languages) {		'',		' mithril ' },

'reconstructed terms', -- (Module:languages) {		'',		' *bʰréh₂tēr ' },	{		'',		'Script error'

},	{		'',		' *dьnь *serda ' },

{		'',		' verbum .. verbum .. *verbum .. verbum .. *verba ' },	{		'',		' *serda ' },	{		'',		' *serda .. *serda .. serda .. serda .. *serda ' },	{		'',		' *alt1 alt2 ' },	{		'',		' attested .. *unattested .. unattested-alt ' },

'script detection', -- (lang_obj:findBestScript) {		' / ',		' српски / srpski ' },

'target page\'s title', -- (Language:makeEntryName) {		'',		' verbō ' },

'gender and number', -- (Module:gender and number) {		'',		' verbum m ' },	{		'',		' verbum m or f ' },

'transliteration', {		'',		' كلمة &lrm; ( kalima ) ' },	{		'',		' русский ( russkij ) ' },

'gloss', {		'',		' русский ( russkij, “ Russian ” ) ' },

'Wikipedia link', {		'',		' word ' },	{		'',		' w:English language ' },	{		'',		' wikipedia:English language ' },	'Linking to titles with special characters: asterisk, slash', {		'',		' / ' },	{		'',		' // ' },	{		'',		' * ' }, }	self:iterate(link_examples, 'check_link') end

function p:check_make_entry_name(lang_code, unstripped, stripped) local lang_obj = get_lang_by_code(lang_code) local sc_code = lang_obj:findBestScript(unstripped):getCode self:equals(		('[%s] %s'):format(lang_code, sc_code, lang_code, unstripped),		(lang_obj:makeEntryName(unstripped)),		stripped,		{ display = tag(lang_code, sc_code) }	) end

function p:test_remove_diacritics -- insert here lines of the form: local examples = { { 'ru', 'ба́бушка', 'бабушка' }, { 'mk', 'ЃѓЌќ - е́а́́', 'ЃѓЌќ - еа' }, -- Macedonian alphabet { 'sh', 'Łł ĆćŃńŹź Ŭŭ - ȁàȃáā ȐȒŔ ѝӣ', 'Łł ĆćŃńŹź Ŭŭ - aaaaa RRR ии' }, -- Serbian Cyrillic alphabet / Gaj's Latin alphabet { 'grc', 'ᾱ, ᾱ́, ᾰ̓́', 'α, ά, ἄ' }, }	self:iterate(examples, 'check_make_entry_name') end

function p:test_section_link local examples = { {			"w:Hindustani phonology#Vowels [ɛ], [ɛː]", ""				.. "w:Hindustani phonology § Vowels [ɛ], [ɛː]" },	}	self:iterate(		examples,		function (self, page, expected)			self:equals( mw.text.nowiki(page), m_links.section_link(page), expected)		end) end

return p