Repository navigation
fix(mascara): no tapar abreviaturas con & ni frases entre llaves #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """La máscara protege los códigos y nada más: «R&D» y una frase entre llaves llegan al modelo como texto.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from traductor_es.nucleo.mascara import desenmascarar, enmascarar, sin_formato | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("texto", "tokens"), | ||
| [ | ||
| ("Defeat the &4Arachnarch", ("&4",)), | ||
| ("&c&lDanger!", ("&c", "&l")), # códigos encadenados | ||
| ("§c&lMix", ("§c", "&l")), | ||
| ("Salt &bPepper", ("&b",)), | ||
| ("the &6Wrench&r to rotate", ("&6", "&r")), # el cierre va pegado a la palabra | ||
| ("WRENCH&r done", ("&r",)), | ||
| ("{image:mod:textures/a.png width:50}", ("{image:mod:textures/a.png width:50}",)), | ||
| ("{@pagebreak}", ("{@pagebreak}",)), | ||
| ("{0} items", ("{0}",)), | ||
| ("Press {key.jump}", ("{key.jump}",)), | ||
| ], | ||
| ) | ||
| def test_los_codigos_se_protegen(texto: str, tokens: tuple[str, ...]) -> None: | ||
| m = enmascarar(texto) | ||
| assert m.tokens == tokens | ||
| assert desenmascarar(m.texto, m.tokens) == texto | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("texto", ["R&D Lab", "Q&A", "B&B Inn", "AT&T", "{the quick brown fox}"]) | ||
| def test_lo_que_no_es_codigo_queda_como_texto(texto: str) -> None: | ||
| assert enmascarar(texto).tokens == () | ||
|
|
||
|
|
||
| def test_sin_formato_no_se_come_letras() -> None: | ||
| assert sin_formato("R&D and &4Red") == "R&D and Red" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an uppercase ampersand code follows an all-caps word, such as
WRENCH&RorWRENCH&R Ready, the uppercase-predecessor branches do not match because the code is not followed immediately by a lowercase letter. The code is therefore sent as translatable text and can be lost or changed;sin_formatoalso leaves it in place. The previous matcher protected this form, so preserve uppercase codes here without masking terminalR&Das a code.Useful? React with 👍 / 👎.