Modul:script utilities/testcases

Failed 5 tests failed.

Name Expected Actual
Failed test_lang_t Lua error -- Modul:script_utilities:28: assign to undeclared variable 'params'
Failed test_request_script_en <small>[script needed]</small>[[Category:English terms needing native script]] <small>[script needed]</small>
Passed test_request_script_en_latn
Failed test_request_script_ja <small>[script needed]</small>[[Category:Japanese terms needing native script]] <small>[script needed]</small>
Failed test_request_script_und_hebr <small>[Hebrew needed]</small>[[Category:Undetermined terms needing Hebrew script]] <small>[héber 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_imag_script
Passed test_tag_text_face_nil
Passed test_tag_text_face_term
Passed test_tag_text_sc
Failed test_template_rfscript Lua error -- Modul:script_utilities:336: assign to undeclared variable 'params'

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, imag = m_scripts.getByCode('Latn'), m_scripts.getByCode('Hebr'), m_scripts.getByCode('Imag')
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)
    return m_script_utilities.request_script(lang, sc)
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

-- 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_imag_script()
    local result = tag_text { text='123', face='bold', sc=imag }
    suite:assertEquals('<span class="Imag" 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:English terms needing native script]]', 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:Undetermined terms needing Hebrew script]]', result)
end

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

-- template_rfscript

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

return suite