Skip to content

Commit

Permalink
strategy: merge surrogate pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Jul 27, 2017
1 parent 3e65e3f commit 921f7a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tests/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ def fspaths(draw, pathname_only=False, allow_pathlike=True):
unichr_ = chr
else:
unichr_ = unichr

def normalize(t):
if sys.version_info[0] == 3:
errors = "surrogatepass"
else:
errors = "strict"
return t.encode("utf-16", errors).decode("utf-16", errors)

surrogate = integers(
min_value=0xD800, max_value=0xDFFF).map(lambda i: unichr_(i))
one_char = sampled_from(draw(characters(blacklist_characters=u"\x00")))
any_char = sampled_from([draw(one_char), draw(surrogate)])
any_text = lists(any_char).map(lambda l: u"".join(l))
any_text = lists(any_char).map(lambda l: normalize(u"".join(l)))

windows_path_text = any_text
s.append(windows_path_text)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hypo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from hypothesis import given, strategies

from senf import fsnative, text2fsn, fsn2text, bytes2fsn, fsn2bytes, print_, \
path2fsn, fsn2uri, uri2fsn, sep, altsep
path2fsn, fsn2uri, uri2fsn
from senf._compat import text_type, StringIO

from tests.strategies import fspaths
Expand Down

0 comments on commit 921f7a2

Please sign in to comment.