mirror of https://gitlab.com/bashrc2/epicyon
Fix inversion tests
parent
25c3997239
commit
2afbc768fc
11
tests.py
11
tests.py
|
@ -7562,8 +7562,19 @@ def _test_uninvert():
|
|||
print('result: ' + result)
|
||||
assert result == expected
|
||||
|
||||
text = '<p>Some ordinary text</p><p>ʇsǝʇ ɐ sı sıɥʇ</p>'
|
||||
expected = "<p>Some ordinary text</p><p>this is a test</p>"
|
||||
result = remove_inverted_text(text, 'en')
|
||||
if result != expected:
|
||||
print('text: ' + text)
|
||||
print('expected: ' + expected)
|
||||
print('result: ' + result)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def run_all_tests():
|
||||
_test_uninvert()
|
||||
return
|
||||
base_dir = os.getcwd()
|
||||
print('Running tests...')
|
||||
update_default_themes_list(os.getcwd())
|
||||
|
|
59
utils.py
59
utils.py
|
@ -3880,28 +3880,47 @@ def remove_inverted_text(text: str, system_language: str) -> str:
|
|||
if system_language != 'en':
|
||||
return text
|
||||
|
||||
inverted_lower = [*"zʎxʍʌnʇsɹbdouɯʃʞɾıɥƃɟǝpɔqɐ"]
|
||||
inverted_upper = [*"Z⅄XMᴧ∩⊥SᴚΌԀOᴎW⅂⋊ſIH⅁ℲƎ◖Ↄ𐐒∀"]
|
||||
inverted_lower = [*"_ʎ_ʍʌ_ʇsɹ____ɯʃʞɾıɥƃɟǝpɔqɐ"]
|
||||
inverted_upper = [*"_⅄_Mᴧ∩⊥SᴚΌԀ_ᴎ_⅂⋊ſ__⅁ℲƎ◖Ↄ𐐒∀"]
|
||||
|
||||
replaced_chars = 0
|
||||
start_separator = ''
|
||||
separator = '\n'
|
||||
if '</p>' in text:
|
||||
text = text.replace('<p>', '')
|
||||
start_separator = '<p>'
|
||||
separator = '</p>'
|
||||
paragraphs = text.split(separator)
|
||||
new_text = ''
|
||||
for para in paragraphs:
|
||||
replaced_chars = 0
|
||||
|
||||
index = 0
|
||||
z_value = ord('z')
|
||||
for test_ch in inverted_lower:
|
||||
if test_ch in text:
|
||||
text = text.replace(test_ch, chr(z_value - index))
|
||||
replaced_chars += 1
|
||||
index += 1
|
||||
index = 0
|
||||
z_value = ord('z')
|
||||
for test_ch in inverted_lower:
|
||||
if test_ch == '_':
|
||||
index += 1
|
||||
continue
|
||||
if test_ch in para:
|
||||
para = para.replace(test_ch, chr(z_value - index))
|
||||
replaced_chars += 1
|
||||
index += 1
|
||||
|
||||
index = 0
|
||||
z_value = ord('Z')
|
||||
for test_ch in inverted_upper:
|
||||
if test_ch in text:
|
||||
text = text.replace(test_ch, chr(z_value - index))
|
||||
replaced_chars += 1
|
||||
index += 1
|
||||
index = 0
|
||||
z_value = ord('Z')
|
||||
for test_ch in inverted_upper:
|
||||
if test_ch == '_':
|
||||
index += 1
|
||||
continue
|
||||
if test_ch in para:
|
||||
para = para.replace(test_ch, chr(z_value - index))
|
||||
replaced_chars += 1
|
||||
index += 1
|
||||
|
||||
if replaced_chars > 2:
|
||||
text = text[::-1]
|
||||
if replaced_chars > 2:
|
||||
para = para[::-1]
|
||||
if para:
|
||||
new_text += start_separator + para
|
||||
if separator in text:
|
||||
new_text += separator
|
||||
|
||||
return text
|
||||
return new_text
|
||||
|
|
Loading…
Reference in New Issue