Module:usex/testcases

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Failed 32 tests failed.

Name Expected Actual
Failed test_format_english Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_quote_quotation_content_is_wrapped_ Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_quote_quotation_is_wrapped Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_quote_with_translation Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_quote_without_quote_displays_hint Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_quote_without_translation_displays_hint_hint Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_adds_does_not_add_italic_tag_for_quote Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_adds_italic_tag_for_latn_script Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_adds_left_to_right_mark_after_example Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_adds_left_to_right_mark_after_example_inline Lua error -- Module:usex:651: assign to undeclared variable 'result'
Failed test_format_usex_adds_script_and_language_tag Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_example_content_is_wrapped Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_explicit_script Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_inline Lua error -- Module:usex:651: assign to undeclared variable 'result'
Failed test_format_usex_inline_and_transliteration Lua error -- Module:usex:651: assign to undeclared variable 'result'
Failed test_format_usex_is_wrapped_ Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_literally_is_wrapped Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_translation_is_wrapped Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_transliterated_text_is_italic Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_transliteration_is_wrapped Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_with_automatic_transliteration Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_with_dash_transliteration_parameter_disables_transliteration Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_with_embedded_wiki_link Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_with_literal_translation Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_with_manual_transliteration Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_with_noenum Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_with_ref Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_without_translation_displays_hint Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_usex_without_translation_displays_usex Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_with_translation Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_format_without_usex_displays_hint Lua error -- Module:usex:654: assign to undeclared variable 'result'
Failed test_qualifier Lua error -- Module:usex:654: assign to undeclared variable 'result'

local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local m_usex = require('Module:usex')
local m_languages = require("Module:languages")
local m_scripts = require("Module:scripts")
local en, fr, ko = m_languages.getByCode('en'), m_languages.getByCode('fr'), m_languages.getByCode('ko')
local rtl_script = m_scripts.getByCode('Hebr')
local translation_hint_usex = '(please add an English translation of this usage example)'
local translation_hint_quote = '(please add an English translation of this quote)'

local function format(args)
    return m_usex.format_usex {
        lang = args.lang or en,
        sc = args.sc,           				-- The script code
        usex = args.usex,           			-- The example or quote
        translation = args.translation,     	-- The English translation for examples on foreign entries.
        transliteration = args.transliteration,	-- The Latin transliteration for examples in non-Latin script.
        noenum = args.noenum or false,			-- To use in unnumbered sections (not following a definition).
        inline = args.inline or false,			-- To include the translation in the same line as the example,
                            					-- separated from the example by em dash.
        ref = args.ref,             			-- To include a reference or link to an originating external site
        quote = args.quote or false,			-- Used from Template:quote
        lit = args.lit,             			-- A literal translation.
        substs = args.substs, 					-- Substitutions to be applied to handle irregular transliterations in certain languages
        qualifiers = args.qualifier or {}		-- To include qualifier for the example or quote.
    }
end

function suite:test_format_without_usex_displays_hint()
    local result = format {}
    suite:assertStringContains('(please add the primary text of this usage example)', result, true)
end

function suite:test_format_quote_without_quote_displays_hint()
    local result = format {quote=true}
    suite:assertStringContains('(please add the primary text of this quote)', result, true)
end

function suite:test_format_english()
    local result = format {usex='This is an example'}
    suite:assertStringContains('This is an example', result, true)
    suite:assertNotStringContains(translation_hint_usex, result, true)
end

function suite:test_format_usex_with_embedded_wiki_link()
    local result = format {usex='This is an [[example]]'}
    suite:assertStringContains('This is an [[example#English|example]]', result, true)
end

function suite:test_format_usex_adds_script_and_language_tag()
    local result = format {usex='Example'}
    suite:assertStringContains('<i class="Latn.*">Example</i>', result, false)
end

function suite:test_format_usex_explicit_script()
    local result = format {usex='Example', sc=m_scripts.getByCode('Cyrl')}
    suite:assertStringContains('<i class="Cyrl.*">Example</i>', result, false)
end

function suite:test_format_usex_adds_italic_tag_for_latn_script()
    local result = format {usex='Example'}
    suite:assertStringContains('<i class="Latn mention.*">Example</i>', result, false)
end

function suite:test_format_usex_adds_does_not_add_italic_tag_for_quote()
    local result = format {usex='This is a quote', quote=true}
    suite:assertNotStringContains('<i', result, true)
    suite:assertNotStringContains('</i>', result, true)
end

function suite:test_format_usex_without_translation_displays_usex()
    local result = format {lang=fr, usex='Ceci est un exemple'}
    suite:assertStringContains('Ceci est un exemple', result, true)
end

function suite:test_format_usex_without_translation_displays_hint()
    local result = format {lang=fr, usex='Ceci est un exemple'}
    suite:assertStringContains(translation_hint_usex, result, true)
end

function suite:test_format_with_translation()
    local result = format {lang=fr, usex='Ceci est un exemple',
        translation='This is an example'}
    suite:assertStringContains('Ceci est un exemple', result, true)
    suite:assertStringContains('This is an example', result, true)
    suite:assertNotStringContains(translation_hint_usex, result, true)
end

function suite:test_format_usex_with_manual_transliteration()
    local result = format {lang=fr, usex='Ceci est un exemple',
        translation='This is an example',
        transliteration='This is the transliterated text'}
    suite:assertStringContains('This is the transliterated text', result, true)
end

function suite:test_format_usex_with_automatic_transliteration()
    local result = format {lang=ko, usex='초식남'}
    suite:assertStringContains('chosingnam', result, true)
end

function suite:test_format_usex_transliterated_text_is_italic()
    local result = format {lang=ko, usex='초식남'}
    suite:assertStringContains('<i.*>chosingnam</i>', result, false)
end

-- tr=- means omit transliteration altogether
function suite:test_format_usex_with_dash_transliteration_parameter_disables_transliteration()
    local result = format {lang=ko, usex='초식남', transliteration='-'}
    suite:assertNotStringContains('chosingnam', result, true)
end

function suite:test_format_usex_with_noenum()
    local result = format {lang=fr, usex='Ceci est un exemple', noenum=true}
    suite:assertStringContains('^\n: ', result, false)
end

function suite:test_format_usex_inline()
    local result = format {lang=fr,
        usex='Ceci est un exemple',
        transliteration='This is an example', inline=true}
    suite:assertStringContains('Ceci est un exemple', result, true)
    suite:assertStringContains('This is an example', result, true)
    suite:assertStringContains('―', result, true)
    suite:assertNotStringContains('<dl>', result, true)
    suite:assertNotStringContains('<dd>', result, true)
end

function suite:test_format_usex_inline_and_transliteration()
    local result = format {lang=ko, usex='초식남',
        translation='This is an example', inline=true}
    suite:assertStringContains('―', result, true)
    suite:assertStringContains('chosingnam', result, true)
end

function suite:test_format_usex_with_ref()
    local result = format {lang=fr, usex='Ceci est un exemple',
        ref='<ref>http://external-ref.com</ref>'}
    suite:assertStringContains('<ref>http://external-ref.com</ref>', result, true)
end

function suite:test_format_quote_without_translation_displays_hint_hint()
    local result = format {lang=fr, usex='Ceci est un quote', quote=true}
    suite:assertStringContains(translation_hint_quote, result, true)
end

function suite:test_format_quote_with_translation()
    local result = format {lang=fr, usex='Ceci est un quote',
        translation='This is a quote', quote=true}
    suite:assertNotStringContains(translation_hint_quote, result, true)
    suite:assertStringContains('This is a quote', result, true)
end

function suite:test_format_usex_with_literal_translation()
    local result = format {lang=fr, usex='Ceci est un exemple',
        translation='This is an example',
        lit='This is the literal translation'}
    suite:assertStringContains('This is the literal translation', result, true)
    suite:assertStringContains('(literally, “.+”)', result, false)
end

function suite:test_format_usex_adds_left_to_right_mark_after_example()
    local result = format {lang=fr, usex='Original', translation='Translated', sc=rtl_script}
    suite:assertStringContains('&rlm;.+Original.+&lrm;.+Translated', result, false)
end

function suite:test_format_usex_adds_left_to_right_mark_after_example_inline()
	local sc = m_scripts.getByCode('Cyrl')
    local result = format {lang=fr, usex='Original', translation='Translated',
    	sc=rtl_script, inline=true}
    suite:assertStringContains('&rlm;.+Original.+&lrm;.+Translated', result, false)
end

function suite:test_qualifier()
	local qualifier = {'A qualifier'}
	local result = format {lang=fr, usex='Usex', qualifier=qualifier}
	suite:assertStringContains('A qualifier', result, false)
end

-- microformat tests

function suite:test_format_usex_is_wrapped_()
    local result = format {usex='Example'}
    suite:assertStringContains('<div class="h%-usage%-example">.*Example.*</div>', result, false)
end

function suite:test_format_usex_example_content_is_wrapped()
    local result = format {usex='Example'}
    suite:assertStringContains('<i class=".*e-example.*">Example</i>', result, false)
end

function suite:test_format_usex_translation_is_wrapped()
    local result = format {usex='Example', translation='Translated'}
    suite:assertStringContains('<span class="e-translation">Translated</span>', result, true)
end

function suite:test_format_usex_transliteration_is_wrapped()
    local result = format {usex='Example', transliteration='Transliteration'}
    suite:assertStringContains('<i lang="en-Latn" class="e-transliteration tr Latn">Transliteration</i>', result, true)
end

function suite:test_format_usex_literally_is_wrapped()
    local result = format {usex='Example', lit='Literally'}
    suite:assertStringContains('<span class="e-literally">Literally</span>', result, true)
end

function suite:test_format_quote_quotation_is_wrapped()
    local result = format {usex='Quotation', quote=true}
    suite:assertStringContains('<div class="h%-quotation">.*Quotation.*</div>', result, false)
end

function suite:test_format_quote_quotation_content_is_wrapped_()
    local result = format {usex='Quotation', quote=true}
    suite:assertStringContains('<span class=".*e%-quotation.*">Quotation</span>', result, false)
end

return suite