Module:Description/testcases

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

✓[OK] All tests passed.

Name Expected Actual
✓[OK] test_description_vs_html
✓[OK] test_description_vs_templates

Code

local TUT  = mw.title.new(mw.getCurrentFrame():getTitle()).basePageTitle -- the title under test
local p = require(TUT.prefixedText) -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local mod = '{{#invoke:' .. TUT.text .. '|description'

function suite:test_description_vs_templates()
	-- compare to language templates
	self:assertSameResult('{{en|1=Hello}}',        mod..'|text=Hello|text_lang=en}}')
	self:assertSameResult('{{en|1=}}',             mod..'|text=|text_lang=en}}')
	self:assertSameResult('{{pl|1=Pozdrowienia}}', mod..'|text=Pozdrowienia|text_lang=pl}}')
	self:assertSameResult('{{ar|1=علاء الدين}}', mod..'|text=علاء الدين|text_lang=ar}}')
	self:assertSameResult('{{pl|1=Pozdrowienia|inline=1}}', mod..'|text=Pozdrowienia|text_lang=pl|inline=1}}')
end

function suite:test_description_vs_html()
	-- compare to the actual expectd html
	local txt = '<div class="description mw-content-ltr en" dir="ltr" lang="en">'..
		'<span class="language en" title="angielski"><b>English&#58; </b></span> Hello</div>'
	self:assertSameResult(txt, mod..'|text=Hello|text_lang=en|user_lang=pl}}')
	
	txt = '<div class="description mw-content-ltr en" dir="ltr" lang="en" style='..
		'"display:inline"><span class="language en" title="angielski"><b>English'..
		'&#58; </b></span> Hello</div>'
	self:assertSameResult(txt, mod..'|text=Hello|text_lang=en|user_lang=pl|inline=1}}')
	
	txt = '<div class="description mw-content-ltr en" dir="ltr" lang="en"><span '..
		  'class="language en" title="English"><b>English&#58; </b></span> '..
		  '<span class="plainlinks">[//commons.wikimedia.org/wiki/Category:'..
		  'Language_templates_with_no_text_displayed<span class="error">(missing '..
		  'text)</span>]</span></div>'
	self:assertSameResult(txt, mod..'|text=|text_lang=en|user_lang=en}}')
	
	txt = '<div class="description mw-content-ltr xx" dir="ltr" lang="xx"><span '..
		  'class="language xx"><b>xx:</b></span> Hello</div>'
	self:assertSameResult(txt, mod..'|text=Hello|text_lang=xx|user_lang=en}}')
end

return suite