Utente:Riccardo Casini/testString

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

-- Unit tests for Module:String. Click talk page to run tests. local p = require('Module:UnitTests')

function p:test_len()

   self:preprocess_equals_many('4', {
       {' foo ', '5'},
       {'s= foo ', '3'},
       {, '0'},
       {'s=', '0'},
       {'   ', '3'},
       {'最近の更新', '5'},
   })

end

function p:test_replace()

   self:preprocess_equals_many(, , {
       {'1.1.1.1|.|/', '1/1/1/1'},
       {'alpha (beta)| (| gamma (', 'alpha gamma (beta)'},
       {'Dog (cat)|%s%(.*%)||plain=false', 'Dog'},
   })

end

function p:test_match()

   self:preprocess_equals_many('Errore nel modulo String: La stringa o pattern da cercare è vuota', {
       {'dog (cat)|%((%a-)%)', 'cat'},
       {'dog (cat) (canary) (fish)|%((%a-)%)||-1', 'fish'},
       {'dog (cat) (canary) (fish)|%((%a-)%)||2', 'canary'},
       {'dog (cat) (canary) (fish)|%((%a-)%)|6|1', 'canary'},
       {'dog (cat) (canary) (fish)|%((%a-)%)|6|2', 'fish'},
       {'dog (cat)|%((%a-)%)||2|no_category=true', 'String Module Error: Match not found'},
       {'dog (cat)|%((%a-)%)||2|ignore_errors=true', },
   })

end function p:test_match()

   self:preprocess_equals_many('Errore nel modulo String: La stringa o pattern da cercare è vuota', {
       {'dog (cat)|%((%a-)%)', 'cat'},
       {'dog (cat) (canary) (fish)|%((%a-)%)||-1', 'fish'},
       {'dog (cat) (canary) (fish)|%((%a-)%)||2', 'canary'},
       {'dog (cat) (canary) (fish)|%((%a-)%)|6|1', 'canary'},
       {'dog (cat) (canary) (fish)|%((%a-)%)|6|2', 'fish'},
       {'dog (cat)|%((%a-)%)||2|no_category=true', 'Errore nel modulo String: Corrispondenza non trovata'},
       {'dog (cat)|%((%a-)%)||2|ignore_errors=true', },
   })

end

function p:test_find()

   self:preprocess_equals_many('0', {
       {, '0'},
       {'source=', '0'},
       {'source=|target=', '0'},
       {'source=|target=Bob', '0'},
       {'Bob|Joe', '0'},
       {'Bob|b', '3'},
       {'Bob Joe|oe', '6'},
       {'source= Bob |o', '2'},
       {' Bob |o', '3'},
       {'높지만 급격히|만', '3'},
       {'source=BAAAB|target=%w|plain=false', '1'},
       {'source=BAAAB|target=%w|start=3|plain=false', '3'},
       {'source=BAAAB|target=(%w)%1|plain=false', '2'},
   })

end

function p:test_rep()

   self:preprocess_equals_many('Errore nel modulo String: la funzione rep si aspetta un secondo parametro con il numero di ripetizioni, ricevuto ""', {
       {'abc|1', 'abc'},
       {'a b|7', 'a ba ba ba ba ba ba b'},
       {'bla|glug|no_category=true', 'Errore nel modulo String: la funzione rep si aspetta un secondo parametro con il numero di ripetizioni, ricevuto "glug"'},
       {'bla|glug|ignore_errors=true', },
       {'àèò|3', 'àèòàèòàèò'},
       {'높지만|3', '높지만높지만높지만'},
   })

end

function p:test_decode()

   self:preprocess_equals_many(, , {
       {'source=TEST%3D%3Dabc', 'TEST==abc'},
   })
   self:preprocess_equals_many(, , {
       {'TEST%3D%3Dabc', 'TEST==abc'},
   })
   self:preprocess_equals_many(, , {
       {'%24+%26', "$ &" },
   })
   self:preprocess_equals_many(, , {
       {'%24+%26|PATH', "$+&" },
   })
   self:preprocess_equals_many(, , {
       {'%24+%26|QUERY', "$ &" },
   })
   self:preprocess_equals_many(, , {
       {'%24_%26|WIKI', "$ &" },
   })

end

function p:test_collate()

   self:preprocess_equals_many(, , {
       {'Ameliè', 'Amelie'},
   })
   self:preprocess_equals_many(, , {
       {'John le Carré', 'John le Carre'},
   })
   self:preprocess_equals_many(, , {
       {"Anatolij Michajlovič Stessel'", "Anatolij Michajlovic Stessel'"},
   })
   self:preprocess_equals_many(, , {
       {'Tōgō Heihachirō', "Togo Heihachiro"},
   })
   self:preprocess_equals_many(, , {
       {'Tōgō Heihachirō', "Togo Heihachiro"},
   })
   self:preprocess_equals_many(, , {
       {'Uryū Sotokichi', 'Uryu Sotokichi'},
   })
   self:preprocess_equals_many(, , {
       {'Rolf Løvland', "Rolf Lovland"},
   })
   self:preprocess_equals_many(, , {
       {'John Storgårds', "John Storgards"},
   })

end

function p:test_titolo_alfa()

   self:preprocess_equals_many(', , {
       {'prova', 'Prova'},
   })
   self:preprocess_equals_many(', , {
       {'prova (disambigua)', 'Prova'},
   })
   self:preprocess_equals_many(', , {
       {'...prova', 'Prova'},
   })
   self:preprocess_equals_many(', , {
       {'...prova (disambigua)', 'Prova'},
   })
   self:preprocess_equals_many(', , {
       {'Pròvâ', 'Prova'},
   })
   self:preprocess_equals_many(', , {
       {'Una prova', 'Prova, Una'},
   })
   self:preprocess_equals_many(', , {
       {'La prova (disambigua)', 'Prova, La'},
   })

end

return p