Module:données Unicode/testcases

Définition, traduction, prononciation, anagramme et synonyme sur le dictionnaire libre Wiktionnaire.

6 tests ont échoué (rafraichir)

  Texte Attendu Obtenu
testGetBlock :
Passed Bloc Basic Latin Basic Latin
  Texte Attendu Obtenu
testGetBlockForChar :
Passed Caractère Basic Latin Basic Latin
  Texte Attendu Obtenu
testGetBlockForInvalidChar :
Passed (Test d’erreur) Chaine vide Un seul caractère attendu, 0 donnés ("") Un seul caractère attendu, 0 donnés ("")
Passed (Test d’erreur) Trop de caractères Un seul caractère attendu, 2 donnés ("AA") Un seul caractère attendu, 2 donnés ("AA")
  Texte Attendu Obtenu
testGetScript :
Passed Script Latin Latin
  Texte Attendu Obtenu
testGetScriptForChar :
Passed Caractère Latin Latin
  Texte Attendu Obtenu
testGetScriptForInvalidChar :
Passed (Test d’erreur) Chaine vide Un seul caractère attendu, 0 donnés Un seul caractère attendu, 0 donnés
Passed (Test d’erreur) Trop de caractères Un seul caractère attendu, 2 donnés Un seul caractère attendu, 2 donnés
  Texte Attendu Obtenu
testGetScriptForTextInheritedAndUnknownChar :
Passed Script et caractère inconnu Unknown Unknown
  Texte Attendu Obtenu
testGetScriptForTextInheritedMajority :
Passed Inherited majoritaire Latin Latin
  Texte Attendu Obtenu
testGetScriptForTextOneScript :
Passed Un seul script Latin Latin
  Texte Attendu Obtenu
testGetScriptForTextOnlyCommon :
Passed Common uniquement Common Common
  Texte Attendu Obtenu
testGetScriptForTextOnlyCommonAndInherited :
Passed Inherited, Common majoritaire Inherited Inherited
  Texte Attendu Obtenu
testGetScriptForTextOnlyInherited :
Passed Inherited uniquement Inherited Inherited
  Texte Attendu Obtenu
testGetScriptForTextScriptAndCommon :
Passed Un script et Common Latin Latin
  Texte Attendu Obtenu
testGetScriptForTextScriptAndUnknownChar :
Passed Script et caractère inconnu à la fin Latin Latin
Passed Script et caractère inconnu au début Latin Latin
  Texte Attendu Obtenu
testGetScriptForTextSeveral :
Passed Plusieurs scripts Unknown Unknown
  Texte Attendu Obtenu
testGetScriptForText_commonAndUnknownChar :
Passed Script et caractère inconnu Unknown Unknown
  Texte Attendu Obtenu
testGetScriptForUnknownChar :
Passed Caractère inconnu Unknown Unknown
  Texte Attendu Obtenu
testGetScriptsForText :
Passed Un seul script {"Latin"} {"Latin"}
  Texte Attendu Obtenu
testGetScriptsForTextSeveral :
Passed Plusieurs scripts {"Common", "Greek", "Latin"} {"Common", "Greek", "Latin"}
  Texte Attendu Obtenu
testGetScriptsForTextTagsIgnored :
Passed Plusieurs scripts {"Greek"} {"Greek"}
Passed Plusieurs scripts {"Greek"} {"Greek"}
Passed Plusieurs scripts {"Greek"} {"Greek"}
  Texte Attendu Obtenu
testGetUnknownBlock :
Passed Bloc invalide (négatif) nil nil
Passed Bloc invalide (trop grand) nil nil
  Texte Attendu Obtenu
testGetUnknownScript :
Passed Script inconnu nil nil
  Texte Attendu Obtenu
testNotTextHasScript :
Passed Un seul script false false
  Texte Attendu Obtenu
testScriptIntervals :
Passed yo εε {{to=2, script="Latin", from=1}, {to=3, script="Common", from=3}, {to=5, script="Greek", from=4}} {{to=2, script="Latin", from=1}, {to=3, script="Common", from=3}, {to=5, script="Greek", from=4}}
  Texte Attendu Obtenu
testScriptIntervalsTag :
Passed yo
oy
{{to=2, script="Latin", from=1}, {to=6, from=3}, {to=8, script="Latin", from=7}} {{to=2, script="Latin", from=1}, {to=6, from=3}, {to=8, script="Latin", from=7}}
  Texte Attendu Obtenu
testSetWritingDirectionLtrHorizontalOnly :
Passed ltr seulement a et ε a et ε
  Texte Attendu Obtenu
testSetWritingDirectionLtrHorizontalOnlyTag :
Passed ltr seulement et balise a et<br>ε a et<br>ε
  Texte Attendu Obtenu
testSetWritingDirectionLtrVerticalAndCommon :
Passed vertical et Common <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ ᠶᠠ</span> <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ ᠶᠠ</span>
  Texte Attendu Obtenu
testSetWritingDirectionLtrVerticalAndInherited :
Passed vertical et Inherited <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ́ᠶᠠ</span> <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ́ᠶᠠ</span>
  Texte Attendu Obtenu
testSetWritingDirectionLtrVerticalOnly :
Passed vertical seulement <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳᠶᠠ</span> <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳᠶᠠ</span>
  Texte Attendu Obtenu
testSetWritingDirectionLtrVerticalOnlyTag :
Passed vertical seulement et balise <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ</span><br><span dir="ltr" style="writing-mode:vertical-lr">ᠶᠠ</span> <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ</span><br><span dir="ltr" style="writing-mode:vertical-lr">ᠶᠠ</span>
  Texte Attendu Obtenu
testSetWritingDirectionRtlHorizontalAndCommon :
Failed rtl et Common <span dir="rtl" style="writing-mode:horizontal-tb">עב רית</span> עב רית
  Texte Attendu Obtenu
testSetWritingDirectionRtlHorizontalAndInherited :
Failed rtl et Inherited <span dir="rtl" style="writing-mode:horizontal-tb">עב́רית</span> עב́רית
  Texte Attendu Obtenu
testSetWritingDirectionRtlHorizontalOnly :
Failed rtl seulement <span dir="rtl" style="writing-mode:horizontal-tb">עברית</span> עברית
  Texte Attendu Obtenu
testSetWritingDirectionRtlHorizontalOnlyTag :
Failed rtl seulement et balise <span dir="rtl" style="writing-mode:horizontal-tb">עב</span><br><span dir="rtl" style="writing-mode:horizontal-tb">רית</span> עב<br>רית
  Texte Attendu Obtenu
testSetWritingDirectionTwoDirections :
Failed a et עברית a et <span dir="rtl" style="writing-mode:horizontal-tb">עברית</span> a et עברית
Passed ae ᠠᠨ́ᡳᠶᠠ εε ae <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́ᡳᠶᠠ </span>εε ae <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́ᡳᠶᠠ </span>εε
Passed aeᠠᠨ́εε ae<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́</span>εε ae<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́</span>εε
Failed aeᠠᠨ́ᡳᠶᠠעב רית ae<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́ᡳᠶᠠ</span><span dir="rtl" style="writing-mode:horizontal-tb">עב רית</span> ae<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́ᡳᠶᠠ</span>עב רית
  Texte Attendu Obtenu
testShouldItalicizeOnlyCommonAndInherited :
Passed Common et Inherited true true
  Texte Attendu Obtenu
testShouldItalicizeOnlyLatinCommonInherited :
Passed Latin, Common et Inherited true true
  Texte Attendu Obtenu
testShouldItalicizeSingleScript :
Passed Latin seulement true true
Passed Common seulement true true
Passed Inherited seulement true true
  Texte Attendu Obtenu
testShouldItalicizeTag :
Passed Balise HTML true true
  Texte Attendu Obtenu
testShouldNotItalicize :
Passed Non latin seulement false false
  Texte Attendu Obtenu
testShouldNotItalicizeLatinAndOther :
Passed Latin et autre false false
  Texte Attendu Obtenu
testShouldNotItalicizeTag :
Passed Balise HTML false false
  Texte Attendu Obtenu
testTextHasScriptSeveral :
Passed Plusieurs scripts, Latin true true
Passed Plusieurs scripts, Greek true true
Passed Plusieurs scripts, Common true true
  Texte Attendu Obtenu
testTextHasScriptSingle :
Passed Un seul script true true



local tests = require("Module:UnitTests")
local m_unicode = require("Module:données Unicode")
local m_table = require("Module:table")

-- Tests --

function tests:testGetBlock()
  self:equals("Bloc", m_unicode.getBlock(0).name.en, "Basic Latin")
end

function tests:testGetBlockForChar()
  self:equals("Caractère", m_unicode.getBlockForChar("A").name.en, "Basic Latin")
end

function tests:testGetScript()
  self:equals("Script", m_unicode.getScript("Latin").code, "Latin")
end

function tests:testGetScriptForChar()
  self:equals("Caractère", m_unicode.getScriptForChar("A").code, "Latin")
end

function tests:testGetScriptForUnknownChar()
  self:equals("Caractère inconnu", m_unicode.getScriptForChar(mw.ustring.char(0x100000)).code, "Unknown")
end

function tests:testGetScriptForTextOneScript()
  self:equals("Un seul script", m_unicode.getScriptForText("ABCDE").code, "Latin")
end

function tests:testGetScriptForTextScriptAndCommon()
  self:equals("Un script et Common", m_unicode.getScriptForText("Texte principalement en Latin").code, "Latin")
end

function tests:testGetScriptForTextInheritedMajority()
  self:equals("Inherited majoritaire", m_unicode.getScriptForText("T̀ ̀").code, "Latin")
end

function tests:testGetScriptForTextOnlyCommon()
  self:equals("Common uniquement", m_unicode.getScriptForText(" ").code, "Common")
end

function tests:testGetScriptForTextOnlyInherited()
  self:equals("Inherited uniquement", m_unicode.getScriptForText("̀").code, "Inherited")
end

function tests:testGetScriptForTextOnlyCommonAndInherited()
  self:equals("Inherited, Common majoritaire", m_unicode.getScriptForText("̀ ").code, "Inherited")
end

function tests:testGetScriptForTextScriptAndUnknownChar()
  self:equals("Script et caractère inconnu à la fin", m_unicode.getScriptForText("A" .. mw.ustring.char(0x100000)).code, "Latin")
  self:equals("Script et caractère inconnu au début", m_unicode.getScriptForText(mw.ustring.char(0x100000) .. "A").code, "Latin")
end

function tests:testGetScriptForText_commonAndUnknownChar()
  self:equals("Script et caractère inconnu", m_unicode.getScriptForText(" " .. mw.ustring.char(0x100000)).code, "Unknown")
end

function tests:testGetScriptForTextInheritedAndUnknownChar()
  self:equals("Script et caractère inconnu", m_unicode.getScriptForText("̀" .. mw.ustring.char(0x100000)).code, "Unknown")
end

function tests:testGetScriptForTextSeveral()
  self:equals("Plusieurs scripts", m_unicode.getScriptForText("Texte en Latin et en Ελληνικά").code, "Unknown")
end

function tests:testGetScriptsForText()
  self:equals_deep("Un seul script", m_table.keysToList(m_unicode.getScriptsForText("Texte")), { "Latin" })
end

function tests:testGetScriptsForTextSeveral()
  self:equals_deep("Plusieurs scripts", m_table.keysToList(m_unicode.getScriptsForText("Texte en Latin et en Ελληνικά")), { "Common", "Greek", "Latin" })
end

function tests:testGetScriptsForTextTagsIgnored()
  self:equals_deep("Plusieurs scripts", m_table.keysToList(m_unicode.getScriptsForText("Ελληνικά<br>Ελληνικά")), { "Greek" })
  self:equals_deep("Plusieurs scripts", m_table.keysToList(m_unicode.getScriptsForText("Ελληνικά<br/>Ελληνικά")), { "Greek" })
  self:equals_deep("Plusieurs scripts", m_table.keysToList(m_unicode.getScriptsForText('Ελληνικά<span id="yo">Ελληνικά</span>')), { "Greek" })
end

function tests:testTextHasScriptSingle()
  self:equals("Un seul script", m_unicode.textHasScript("Texte", "Latin"), true)
end

function tests:testTextHasScriptSeveral()
  self:equals("Plusieurs scripts, Latin", m_unicode.textHasScript("Texte en Latin et en Ελληνικά", "Latin"), true)
  self:equals("Plusieurs scripts, Greek", m_unicode.textHasScript("Texte en Latin et en Ελληνικά", "Greek"), true)
  self:equals("Plusieurs scripts, Common", m_unicode.textHasScript("Texte en Latin et en Ελληνικά", "Common"), true)
end

function tests:testNotTextHasScript()
  self:equals("Un seul script", m_unicode.textHasScript("Texte", "Greek"), false)
end

function tests:testShouldItalicizeSingleScript()
  self:equals("Latin seulement", m_unicode.shouldItalicize("Texte"), true)
  self:equals("Common seulement", m_unicode.shouldItalicize(" "), true)
  self:equals("Inherited seulement", m_unicode.shouldItalicize("́"), true)
end

function tests:testShouldItalicizeOnlyCommonAndInherited()
  self:equals("Common et Inherited", m_unicode.shouldItalicize("1̧"), true)
end

function tests:testShouldItalicizeOnlyLatinCommonInherited()
  self:equals("Latin, Common et Inherited", m_unicode.shouldItalicize("Un ḿ"), true)
end

function tests:testShouldItalicizeTag()
  self:equals("Balise HTML", m_unicode.shouldItalicize("a<br>a"), true)
end

function tests:testShouldNotItalicizeTag()
  self:equals("Balise HTML", m_unicode.shouldItalicize("ε<br>ε"), false)
end

function tests:testShouldNotItalicize()
  self:equals("Non latin seulement", m_unicode.shouldItalicize("ε"), false)
end

function tests:testShouldNotItalicizeLatinAndOther()
  self:equals("Latin et autre", m_unicode.shouldItalicize("a et ε"), false)
end

function tests:testScriptIntervals()
  local _, invervals = m_unicode.getScriptsForText("yo εε", true)
  self:equals_deep("yo εε", invervals, { { script = "Latin", from = 1, to = 2 }, { script = "Common", from = 3, to = 3 }, { script = "Greek", from = 4, to = 5 } })
end

function tests:testScriptIntervalsTag()
  local _, invervals = m_unicode.getScriptsForText("yo<br>oy", true)
  self:equals_deep("yo<br>oy", invervals, { { script = "Latin", from = 1, to = 2 }, { from = 3, to = 6 }, { script = "Latin", from = 7, to = 8 } })
end

function tests:testSetWritingDirectionLtrHorizontalOnly()
  self:equals("ltr seulement", m_unicode.setWritingDirection("a et ε"), "a et ε")
end

function tests:testSetWritingDirectionLtrHorizontalOnlyTag()
  self:equals("ltr seulement et balise", m_unicode.setWritingDirection("a et<br>ε"), "a et<br>ε")
end

function tests:testSetWritingDirectionRtlHorizontalOnly()
  self:equals("rtl seulement", m_unicode.setWritingDirection("עברית"), '<span dir="rtl" style="writing-mode:horizontal-tb">עברית</span>')
end

function tests:testSetWritingDirectionRtlHorizontalAndCommon()
  self:equals("rtl et Common", m_unicode.setWritingDirection("עב רית"), '<span dir="rtl" style="writing-mode:horizontal-tb">עב רית</span>')
end

function tests:testSetWritingDirectionRtlHorizontalAndInherited()
  self:equals("rtl et Inherited", m_unicode.setWritingDirection("עב́רית"), '<span dir="rtl" style="writing-mode:horizontal-tb">עב́רית</span>')
end

function tests:testSetWritingDirectionRtlHorizontalOnlyTag()
  self:equals("rtl seulement et balise", m_unicode.setWritingDirection("עב<br>רית"), '<span dir="rtl" style="writing-mode:horizontal-tb">עב</span><br><span dir="rtl" style="writing-mode:horizontal-tb">רית</span>')
end

function tests:testSetWritingDirectionLtrVerticalOnly()
  self:equals("vertical seulement", m_unicode.setWritingDirection("ᠠᠨᡳᠶᠠ"), '<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳᠶᠠ</span>')
end

function tests:testSetWritingDirectionLtrVerticalAndCommon()
  self:equals("vertical et Common", m_unicode.setWritingDirection("ᠠᠨᡳ ᠶᠠ"), '<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ ᠶᠠ</span>')
end

function tests:testSetWritingDirectionLtrVerticalAndInherited()
  self:equals("vertical et Inherited", m_unicode.setWritingDirection("ᠠᠨᡳ́ᠶᠠ"), '<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ́ᠶᠠ</span>')
end

function tests:testSetWritingDirectionLtrVerticalOnlyTag()
  self:equals("vertical seulement et balise", m_unicode.setWritingDirection("ᠠᠨᡳ<br>ᠶᠠ"), '<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨᡳ</span><br><span dir="ltr" style="writing-mode:vertical-lr">ᠶᠠ</span>')
end

function tests:testSetWritingDirectionTwoDirections()
  self:equals("a et עברית", m_unicode.setWritingDirection("a et עברית"), 'a et <span dir="rtl" style="writing-mode:horizontal-tb">עברית</span>')
  self:equals("ae ᠠᠨ́ᡳᠶᠠ εε", m_unicode.setWritingDirection("ae ᠠᠨ́ᡳᠶᠠ εε"), 'ae <span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́ᡳᠶᠠ </span>εε')
  self:equals("aeᠠᠨ́εε", m_unicode.setWritingDirection("aeᠠᠨ́εε"), 'ae<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́</span>εε')
  self:equals("aeᠠᠨ́ᡳᠶᠠעב רית", m_unicode.setWritingDirection("aeᠠᠨ́ᡳᠶᠠעב רית"), 'ae<span dir="ltr" style="writing-mode:vertical-lr">ᠠᠨ́ᡳᠶᠠ</span><span dir="rtl" style="writing-mode:horizontal-tb">עב רית</span>')
end

-- Error tests --

function tests:testGetUnknownBlock()
  self:equals("Bloc invalide (négatif)", m_unicode.getBlock(-1), nil)
  self:equals("Bloc invalide (trop grand)", m_unicode.getBlock(0x1000000), nil)
end

function tests:testGetBlockForInvalidChar()
  self:expect_error("Chaine vide", m_unicode.getBlockForChar, { "" }, 'Un seul caractère attendu, 0 donnés ("")')
  self:expect_error("Trop de caractères", m_unicode.getBlockForChar, { "AA" }, 'Un seul caractère attendu, 2 donnés ("AA")')
end

function tests:testGetUnknownScript()
  self:equals("Script inconnu", m_unicode.getScript("script invalide"), nil)
end

function tests:testGetScriptForInvalidChar()
  self:expect_error("Chaine vide", m_unicode.getScriptForChar, { "" }, "Un seul caractère attendu, 0 donnés")
  self:expect_error("Trop de caractères", m_unicode.getScriptForChar, { "AA" }, "Un seul caractère attendu, 2 donnés")
end

return tests