Module:Wikt-lang/testcases
Appearance
From Wikipedia, the free encyclopedia
-- Unit tests for [[Module:Wikt-lang]]. Click talk page to run tests. localp=require('Module:UnitTests') localm_Language=require('Module:Wikt-lang') localname_from_tag=require('Module:Lang')._name_from_tag functionp:test_1_link() self:preprocess_equals_preprocess_many('{{#invoke:Wikt-lang/sandbox|wiktlang|','}}','{{#invoke:Wikt-lang|wiktlang|','}}', { {"grc|δημοκρᾰτῐ́ᾱ"}, {"ha|àzàhàr̃iyyā̀"}, {"la|coëō"}, {"nci|Quetzalcōātl"}, {"ru|ру́сский язы́к"}, {"he|שלום"}, {"sh|ćá|ća"},-- fake word with c-acute and tonal acute; add a real word if you know one },{nowiki=1}) end functionp:test_2_private_codes() self:preprocess_equals_preprocess_many('{{#invoke:Wikt-lang/sandbox|wiktlang|','}}','{{#invoke:Wikt-lang|wiktlang|','}}', { {"cel-x-proto|*beru"},-- this private code is taken from Module:Lang's data {"cel-bry-pro|test"}, {"gem-x-proto|test"}, {"gmw-x-proto|test"}, {"gmq-x-gut|test"}, {"grk-x-proto|test́к"}, {"ine-bsl-pro|test"}, {"ine-x-proto|test"}, {"non-x-proto|test"}, {"poz-x-poly-proto|test"}, {"sem-pro|test"}, {"sla-x-proto|test"}, {"zle-ort|test"}, },{nowiki=1}) end localfunctionget_test_patterns(main) localdata=require('Module:Wikt-lang/data/sandbox') locallanguage_codes={} ifmainthen forcode,valuesinpairs(data["languages"])do table.insert(language_codes,{code,values.name}) end end localfunctioncomp(a,b) returna[1]<b[1] end table.sort(language_codes,comp) returnlanguage_codes end functionp:test_3_all_database_links() localwiktionary_test_patterns=get_test_patterns(true) localfull_test_patterns={} fori=1,#wiktionary_test_patternsdo localcode=wiktionary_test_patterns[i][1] table.insert(full_test_patterns,{code.."|test",code.."|test"}) end self:preprocess_equals_preprocess_many('{{#invoke:Wikt-lang/sandbox|wiktlang|','}}','{{#invoke:Wikt-lang|wiktlang|no_cat=yes|','}}',full_test_patterns,{nowiki=1}) end functionp:test_4_errors() self:preprocess_equals_preprocess_many('{{#invoke:Wikt-lang/sandbox|wiktlang|','}}','{{#invoke:Wikt-lang|wiktlang|','}}', { -- not a valid code {"abcd|test"}, -- not a valid private code {"abc-x-proto|test"}, -- no code {""}, -- text, but no code {"|test"}, -- display text, but no code {"||test"}, -- no text {"la|"}, -- no link text {"la||test"}, },{nowiki=1}) end returnp