Jump to content

Module:script utilities/testcases

From Wiktionary, the free dictionary

Failed 4 tests failed.

Name Expected Actual
Passed test_lang_t
Passed test_lang_t_sc_override
Failed test_request_script_en <small>[script needed]</small>[[Category:Requests for native script for English terms|TEST]] <small>[script needed]</small>
Passed test_request_script_en_latn
Failed test_request_script_ja <small>[script needed]</small>[[Category:Requests for native script for Japanese terms|TEST]] <small>[script needed]</small>
Failed test_request_script_und_hebr <small>[Hebrew needed]</small>[[Category:Requests for Hebrew script for Undetermined terms|TEST]] <small>[Hebrew needed]</small>
Passed test_tag_text_adds_class
Passed test_tag_text_face_bold
Passed test_tag_text_face_head
Passed test_tag_text_face_hypothetical
Passed test_tag_text_face_is_ignored_for_image_script
Passed test_tag_text_face_nil
Passed test_tag_text_face_term
Passed test_tag_text_sc
Failed test_template_rfscript Lua error -- Module:script_utilities:471: This language is written in the Latin alphabet. It does not need a native script.

local ScribuntoUnit = require('Module:ScribuntoUnit')
local m_script_utilities = require('Module:script utilities')
local m_scripts = require("Module:scripts")
local m_languages = require("Module:languages")
local en, ja, und = m_languages.getByCode('en'), m_languages.getByCode('ja'), m_languages.getByCode('und')
local latn, hebr, image = m_scripts.getByCode('Latn'), m_scripts.getByCode('Hebr'), m_scripts.getByCode('Image')
local suite = ScribuntoUnit:new()

-- helper functions

local function tag_text(args)
    return m_script_utilities.tag_text(
        args.text,
        args.lang or en,
        args.sc or latn,
        args.face,
        args.class
    )
end

local function lang_t(args)
    local frame = mw.getCurrentFrame():newChild{ title = 'test', args = args }
    return m_script_utilities.lang_t(frame:newChild{})
end

local function request_script(lang, sc)
	-- Make [[Module:utilities/format categories]] think that it is being
	-- executed on a mainspace page so that it will output categories.
	local old = mw.title.getCurrentTitle
	mw.title.getCurrentTitle = function() return mw.title.new("test") end
    local ret = m_script_utilities.request_script(lang, sc)
    mw.title.getCurrentTitle = old
    return ret
end

local function template_rfscript(args)
    local frame = mw.getCurrentFrame():newChild{ title = 'test', args = args }
    return m_script_utilities.template_rfscript(frame)
end

-- lang_t

function suite:test_lang_t()
    local result = lang_t{'en', '123'}
    suite:assertEquals('<span class="None" lang="en">123</span>', result)
end

function suite:test_lang_t_sc_override()
    local result = lang_t{'ro', 'абвг', sc = 'Hani'}
    suite:assertEquals('<span class="Hani" lang="ro">абвг</span>', result)
end

-- tag_text

function suite:test_tag_text_face_nil()
    local result = tag_text { text='123' }
    suite:assertEquals('<span class="Latn" lang="en">123</span>', result)
end

function suite:test_tag_text_face_term()
    local result = tag_text { text='123', face='term' }
    suite:assertEquals('<i class="Latn mention" lang="en">123</i>', result)
end

function suite:test_tag_text_face_head()
    local result = tag_text { text='123', face='head' }
    suite:assertEquals('<strong class="Latn headword" lang="en">123</strong>', result)
end

function suite:test_tag_text_face_hypothetical()
    local result = tag_text { text='123', face='hypothetical' }
    suite:assertEquals('<span class="hypothetical-star">*</span><i class="Latn hypothetical" lang="en">123</i>', result)
end

function suite:test_tag_text_face_bold()
    local result = tag_text { text='123', face='bold' }
    suite:assertEquals('<b class="Latn" lang="en">123</b>', result)
end

function suite:test_tag_text_sc()
    local result = tag_text { text='123', sc=hebr }
    suite:assertEquals('<span class="Hebr" lang="en">123</span>', result)
end

function suite:test_tag_text_face_is_ignored_for_image_script()
    local result = tag_text { text='123', face='bold', sc=image }
    suite:assertEquals('<span class="Image" lang="en">123</span>', result)
end

function suite:test_tag_text_adds_class()
    local result = tag_text { text='123', class='test' }
    suite:assertEquals('<span class="Latn test" lang="en">123</span>', result)
end

-- request_script

function suite:test_request_script_en()
    local result = request_script(en)
    suite:assertEquals('<small>[script needed]</small>[[Category:Requests for native script for English terms|TEST]]', result)
end

function suite:test_request_script_en_latn()
    local result = request_script(en, latn)
    suite:assertEquals('', result)
end

function suite:test_request_script_und_hebr()
    local result = request_script(und, hebr)
    suite:assertEquals('<small>[Hebrew needed]</small>[[Category:Requests for Hebrew script for Undetermined terms|TEST]]', result)
end

function suite:test_request_script_ja()
    local result = request_script(ja)
    suite:assertEquals('<small>[script needed]</small>[[Category:Requests for native script for Japanese terms|TEST]]', result)
end

-- template_rfscript

function suite:test_template_rfscript()
    local result = template_rfscript {'en'}
    suite:assertEquals('<small>[script needed]</small>[[Category:Requests for native script for English terms|TEST]]', result)
end

return suite