Module:User:Jberkel/script utilities/testcases

local ScribuntoUnit = require('Module:ScribuntoUnit') local m_script_utilities = require('Module:User:Jberkel/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(' 123 ', result) end

-- tag_text

function suite:test_tag_text_face_nil local result = tag_text { text='123' } suite:assertEquals(' 123 ', result) end

function suite:test_tag_text_face_term local result = tag_text { text='123', face='term' } suite:assertEquals('123', result) end

function suite:test_tag_text_face_head local result = tag_text { text='123', face='head' } suite:assertEquals('123 ', result) end

function suite:test_tag_text_face_hypothetical local result = tag_text { text='123', face='hypothetical' } suite:assertEquals(' * 123', result) end

function suite:test_tag_text_face_bold local result = tag_text { text='123', face='bold' } suite:assertEquals('123', result) end

function suite:test_tag_text_sc local result = tag_text { text='123', sc=hebr } suite:assertEquals(' 123 ', 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(' 123 ', result) end

function suite:test_tag_text_adds_class local result = tag_text { text='123', class='test' } suite:assertEquals(' 123 ', result) end

-- request_script

function suite:test_request_script_en local result = request_script(en) suite:assertEquals(' [script needed] ', 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(' [Hebrew needed] ', result) end

function suite:test_request_script_ja local result = request_script(ja) suite:assertEquals(' [script needed] ', result) end

-- template_rfscript

function suite:test_template_rfscript local result = template_rfscript {'en'} suite:assertEquals(' [script needed] ', result) end

return suite