test: escape_xml

This commit is contained in:
QuentinN42
2022-02-10 12:17:38 +01:00
parent dab7a8089b
commit b1ce2f290b
3 changed files with 3944 additions and 1 deletions

3919
coverage.xml Normal file

File diff suppressed because it is too large Load Diff

24
tests/test_format.py Normal file
View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
import unittest
import string
from yamllint.format import escape_xml, severity_from_level
class TextToXMLTestCase(unittest.TestCase):
specials = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&apos;'
}
def test_letters_chars(self):
txt = string.ascii_letters
self.assertEqual(escape_xml(txt), txt)
def test_specials_chars(self):
for inp, out in self.specials.items():
self.assertEqual(escape_xml(inp), out)

View File

@@ -37,7 +37,7 @@ def escape_xml(text):
text = text.replace('<', '&lt;') text = text.replace('<', '&lt;')
text = text.replace('>', '&gt;') text = text.replace('>', '&gt;')
text = text.replace('"', '&quot;') text = text.replace('"', '&quot;')
text = text.replace('"', '&apos;') text = text.replace("'", '&apos;')
return text return text