This commit is contained in:
Dale Myers 2022-08-08 13:04:19 +01:00
Родитель 74f2fef80d
Коммит f3fbc7244e
2 изменённых файлов: 30 добавлений и 2 удалений

Просмотреть файл

@ -21,7 +21,7 @@ class InvalidTokens(LocalizationTestCase):
violations = []
invalid_token_pattern = re.compile(r"(%[^@%\.a-z0-9]+)|([^%]%$)", flags=re.DOTALL)
invalid_token_pattern = re.compile(r"(%[^@%\.a-z0-9 ]+)", flags=re.DOTALL)
for string in self.collection.localized_strings:
matches = invalid_token_pattern.findall(string.value)

Просмотреть файл

@ -9,5 +9,33 @@ import localizationkit
def test_invalid_tokens(configuration):
"""Test that invalid tokens works"""
test_cases = [
(
False,
localizationkit.LocalizedString(
"Key", "This is a string with no tokens", "Some comment", "en"
),
),
(False, localizationkit.LocalizedString("Key", "%", "Some comment", "en")),
(False, localizationkit.LocalizedString("Key", "25%", "Some comment", "en")),
(False, localizationkit.LocalizedString("Key", "This is 25%", "Some comment", "en")),
(
False,
localizationkit.LocalizedString("Key", "This is 25% off", "Some comment", "en"),
),
(True, localizationkit.LocalizedString("Key", "This is %* off", "Some comment", "en")),
(True, localizationkit.LocalizedString("Key", "This is %! off", "Some comment", "en")),
(True, localizationkit.LocalizedString("Key", "This is %() off", "Some comment", "en")),
(False, localizationkit.LocalizedString("Key", "This is % off", "Some comment", "en")),
(False, localizationkit.LocalizedString("Key", "This is %% off", "Some comment", "en")),
(False, localizationkit.LocalizedString("Key", "This is %d off", "Some comment", "en")),
]
self.assertTrue(1 + 1)
for (has_invalid_tokens, string) in test_cases:
collection = localizationkit.LocalizedCollection([string])
test = localizationkit.tests.invalid_tokens.InvalidTokens(configuration, collection)
result = test.execute()
if has_invalid_tokens:
assert result.succeeded() is False
else:
assert result.succeeded()