-- Unit tests for [[Module:Fiction redirect category handler]]. Click talk page to run tests.
local p = require('Module:UnitTests')
function p:test_01_redirect_categories()
self:preprocess_equals_sandbox_many('{{#invoke:Fiction redirect category handler', 'character|test=yes', {
{"restricted=yes", "R from fictional character, R restricted, R to section, R with possibilities, R printworthy"},
{"birth_name=yes", "R from fictional character, R from birth name, R to section, R printworthy"},
{"alt_name=yes", "R from fictional character, R from alternative name, R to section, R printworthy"},
{"former_name=yes", "R from fictional character, R from former name, R to section, R printworthy"},
{"short_name=yes", "R from fictional character, R from short name, R to section, R printworthy"},
{"long_name=yes", "R from fictional character, R from long name, R to section, R printworthy"},
{"title_name=yes", "R from fictional character, R from name with title, R to section, R unprintworthy"},
{"alt_spelling=yes", "R from fictional character, R from alternative spelling, R to section, R unprintworthy"},
{"to_diacritic=yes", "R from fictional character, R to diacritic, R to section, R unprintworthy"},
{"incorrect_name=yes", "R from fictional character, R from incorrect name, R to section, R unprintworthy"},
{"capitalisation=yes", "R from fictional character, R from miscapitalisation, R to section, R unprintworthy"},
{"unneeded_dab=yes", "R from fictional character, R from unnecessary disambiguation, R to section, R unprintworthy"},
{"primary=yes", "R from fictional character, R to section, R avoided double redirect, R printworthy"},
{"merge=yes", "R from fictional character, R to section, R from merge, R with possibilities, R printworthy"},
{"history=yes", "R from fictional character, R to section, R with history, R with possibilities, R printworthy"},
{"draft_move=yes", "R from fictional character, R from move, R from draft namespace, R to section, R unprintworthy"},
})
end
function p:test_02_title_handling()
self:preprocess_equals_sandbox_many('{{#invoke:Fiction redirect category handler', 'character|test=yes', {
{"test_title=Sawyer", "R from fictional character, R to section, R with Wikidata item, R with possibilities, R printworthy"},
{"test_title=Sawyer (characteer)", "R from fictional character, R from incorrect disambiguation, R to section, R unprintworthy"},
{"test_title=Sawyer (Lost)|correct_disambiguation=Lost", "R from fictional character, R to section, R with possibilities, R printworthy"},
{"test_title=Sawyer (Lost character)|correct_disambiguation=Lost", "R from fictional character, R to section, R with possibilities, R printworthy"},
})
end
function p:test_03_element_title_handling()
self:preprocess_equals_sandbox_many('{{#invoke:Fiction redirect category handler', 'element|test=yes', {
{"test_title=4 8 15 16 23 42", "R from fictional element, R to section, R with possibilities, R printworthy"},
{"test_title=4 8 15 16 23 42 (element)", "R from fictional element, R from incorrect disambiguation, R to section, R unprintworthy"},
{"test_title=4 8 15 16 23 42 (The Lost Numbers)", "R from fictional element, R from incorrect disambiguation, R to section, R unprintworthy"},
{"test_title=4 8 15 16 23 42 (Lost element)|correct_disambiguation=Lost", "R from fictional element, R to section, R with possibilities, R printworthy"},
{"test_title=4 8 15 16 23 42 (Lost)|correct_disambiguation=Lost", "R from fictional element, R to section, R with possibilities, R printworthy"},
})
end
function p:test_04_location_title_handling()
self:preprocess_equals_sandbox_many('{{#invoke:Fiction redirect category handler', 'location|test=yes', {
{"test_title=The Swan", "R from fictional location, R to section, R with possibilities, R printworthy"},
{"test_title=The Swan (location)", "R from fictional location, R from incorrect disambiguation, R to section, R unprintworthy"},
{"test_title=The Swan (Lost)|correct_disambiguation=Lost", "R from fictional location, R to section, R with possibilities, R printworthy"},
{"test_title=The Swan (Lost location)|correct_disambiguation=Lost", "R from fictional location, R to section, R with possibilities, R printworthy"},
})
end
function p:test_05_title_section_handling()
self:preprocess_equals_sandbox_many('{{#invoke:Fiction redirect category handler', 'character|test=yes', {
{"", "R from fictional character, R to section, R with possibilities, R printworthy"},
{"anchor=yes", "R from fictional character, R to anchor, R with possibilities, R printworthy"},
{"section=test", "R from fictional character, R to section, R with possibilities, R printworthy"},
{"list=test", "R from fictional character, R to list entry, R with possibilities, R printworthy"},
{"to_article=test", "R from fictional character, R with possibilities, R printworthy"},
})
end
function p:test_06_multi_series()
self:preprocess_equals_sandbox_many('{{#invoke:Fiction redirect category handler', 'character|test=yes', {
{"series_name=Arrow (TV series)|series_name2=DC Extended Universe", "Arrow (TV series), DC Extended Universe, R from fictional character, R to section, R with possibilities, R printworthy"},
{"series_name=Arrow (TV series)|series_name2=DC Extended Universe|series_name3=The Flash (TV series)", "Arrow (TV series), DC Extended Universe, The Flash (TV series), R from fictional character, R to section, R with possibilities, R printworthy"},
})
end
return p