Fix invalid token testing
This commit is contained in:
Родитель
74f2fef80d
Коммит
f3fbc7244e
|
@ -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()
|
||||
|
|
Загрузка…
Ссылка в новой задаче