Skip to content

Commit

Permalink
test: add breaking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinitkumar committed Dec 13, 2024
1 parent bf6363d commit 18ce10c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_json2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)



class TestJson2xml:
"""Tests for `json2xml` package."""

Expand Down Expand Up @@ -229,3 +230,26 @@ def test_encoding_without_pretty_print(self) -> None:
xmldata = json2xml.Json2xml(data, pretty=False).to_xml()
if xmldata:
assert b'encoding="UTF-8"' in xmldata

def test_escapes_angle_brackets(self):
json_data = json.dumps({"root": {"@attrs": {"HelpText": "version <here>"}}})
result = json2xml.Json2xml(json_data).to_xml()
assert 'HelpText="version &lt;here&gt;"' in result

def test_escapes_quotes(self):
json_data = json.dumps({"root": {"@attrs": {"Text": "\"quoted\""}}})
result = json2xml.Json2xml(json_data).to_xml()
assert 'Text="&quot;quoted&quot;"' in result

def test_escapes_ampersands(self):
json_data = json.dumps({"root": {"@attrs": {"Text": "this & that"}}})
result = json2xml.Json2xml(json_data).to_xml()
assert 'Text="this &amp; that"' in result

def test_escapes_mixed_special_chars(self):
json_data = json.dumps({"root": {"@attrs": {"Text": "<tag> & \"quote\""}}})
result = json2xml.Json2xml(json_data).to_xml()
assert 'Text="&lt;tag&gt; &amp; &quot;quote&quot;"' in result



0 comments on commit 18ce10c

Please sign in to comment.