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)
|
print('result: ' + result)
|
||||||
assert result == expected
|
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():
|
def run_all_tests():
|
||||||
|
_test_uninvert()
|
||||||
|
return
|
||||||
base_dir = os.getcwd()
|
base_dir = os.getcwd()
|
||||||
print('Running tests...')
|
print('Running tests...')
|
||||||
update_default_themes_list(os.getcwd())
|
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':
|
if system_language != 'en':
|
||||||
return text
|
return text
|
||||||
|
|
||||||
inverted_lower = [*"zʎxʍʌnʇsɹbdouɯʃʞɾıɥƃɟǝpɔqɐ"]
|
inverted_lower = [*"_ʎ_ʍʌ_ʇsɹ____ɯʃʞɾıɥƃɟǝpɔqɐ"]
|
||||||
inverted_upper = [*"Z⅄XMᴧ∩⊥SᴚΌԀOᴎW⅂⋊ſIH⅁ℲƎ◖Ↄ𐐒∀"]
|
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
|
index = 0
|
||||||
z_value = ord('z')
|
z_value = ord('z')
|
||||||
for test_ch in inverted_lower:
|
for test_ch in inverted_lower:
|
||||||
if test_ch in text:
|
if test_ch == '_':
|
||||||
text = text.replace(test_ch, chr(z_value - index))
|
index += 1
|
||||||
replaced_chars += 1
|
continue
|
||||||
index += 1
|
if test_ch in para:
|
||||||
|
para = para.replace(test_ch, chr(z_value - index))
|
||||||
|
replaced_chars += 1
|
||||||
|
index += 1
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
z_value = ord('Z')
|
z_value = ord('Z')
|
||||||
for test_ch in inverted_upper:
|
for test_ch in inverted_upper:
|
||||||
if test_ch in text:
|
if test_ch == '_':
|
||||||
text = text.replace(test_ch, chr(z_value - index))
|
index += 1
|
||||||
replaced_chars += 1
|
continue
|
||||||
index += 1
|
if test_ch in para:
|
||||||
|
para = para.replace(test_ch, chr(z_value - index))
|
||||||
|
replaced_chars += 1
|
||||||
|
index += 1
|
||||||
|
|
||||||
if replaced_chars > 2:
|
if replaced_chars > 2:
|
||||||
text = text[::-1]
|
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