Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Mar 18, 2019
1 parent 36b0f04 commit 9926ecf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion soupsieve/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def uchr(i):
def uord(c):
"""Get Unicode ordinal."""

if len(c) == 2:
if len(c) == 2: # pragma: no cover
high, low = [ord(p) for p in c]
ordinal = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000
else:
Expand Down
33 changes: 33 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,39 @@ def test_closest_must_be_parent(self):
self.assertTrue(sv.closest('div #div-05', el) is None)
self.assertTrue(sv.closest('a', el) is None)

def test_escape_hyphen(self):
"""Test escape hyphen cases."""

self.assertEqual(r'\-', sv.escape('-'))
self.assertEqual(r'--', sv.escape('--'))

def test_escape_numbers(self):
"""Test escape hyphen cases."""

self.assertEqual(r'\33 ', sv.escape('3'))
self.assertEqual(r'-\33 ', sv.escape('-3'))
self.assertEqual(r'--3', sv.escape('--3'))

def test_escape_null(self):
"""Test escape null character."""

self.assertEqual('\ufffdtest', sv.escape('\x00test'))

def test_escape_ctrl(self):
"""Test escape control character."""

self.assertEqual(r'\1 test', sv.escape('\x01test'))

def test_escape_special(self):
"""Test escape special character."""

self.assertEqual(r'\{\}\[\]\ \(\)', sv.escape('{}[] ()'))

def test_escape_wide_unicode(self):
"""Test handling of wide Unicode."""

self.assertEqual('Emoji\\ \U0001F60D', sv.escape('Emoji \U0001F60D'))

def test_copy_pickle(self):
"""Test copy and pickle."""

Expand Down

0 comments on commit 9926ecf

Please sign in to comment.