Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
799fd9c8
Commit
799fd9c8
authored
Jan 29, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Add tests for raw-unicode-escape codec.
parents
db6add7d
c9c4338e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+50
-0
No files found.
Lib/test/test_codecs.py
View file @
799fd9c8
...
...
@@ -2097,6 +2097,56 @@ class UnicodeEscapeTest(unittest.TestCase):
self
.
assertEqual
(
decode
(
br"\U00110000"
,
"replace"
),
(
"
\
ufffd
"
,
10
))
class
RawUnicodeEscapeTest
(
unittest
.
TestCase
):
def
test_empty
(
self
):
self
.
assertEqual
(
codecs
.
raw_unicode_escape_encode
(
""
),
(
b""
,
0
))
self
.
assertEqual
(
codecs
.
raw_unicode_escape_decode
(
b""
),
(
""
,
0
))
def
test_raw_encode
(
self
):
encode
=
codecs
.
raw_unicode_escape_encode
for
b
in
range
(
256
):
self
.
assertEqual
(
encode
(
chr
(
b
)),
(
bytes
([
b
]),
1
))
def
test_raw_decode
(
self
):
decode
=
codecs
.
raw_unicode_escape_decode
for
b
in
range
(
256
):
self
.
assertEqual
(
decode
(
bytes
([
b
])
+
b'0'
),
(
chr
(
b
)
+
'0'
,
2
))
def
test_escape_encode
(
self
):
encode
=
codecs
.
raw_unicode_escape_encode
check
=
coding_checker
(
self
,
encode
)
for
b
in
range
(
256
):
if
b
not
in
b'uU'
:
check
(
'
\
\
'
+
chr
(
b
),
b'
\
\
'
+
bytes
([
b
]))
check
(
'
\
u20ac
'
,
br'\u20ac'
)
check
(
'
\
U0001d120
'
,
br'\U0001d120'
)
def
test_escape_decode
(
self
):
decode
=
codecs
.
raw_unicode_escape_decode
check
=
coding_checker
(
self
,
decode
)
for
b
in
range
(
256
):
if
b
not
in
b'uU'
:
check
(
b'
\
\
'
+
bytes
([
b
]),
'
\
\
'
+
chr
(
b
))
check
(
br"\u20ac"
,
"
\
u20ac
"
)
check
(
br"\U0001d120"
,
"
\
U0001d120
"
)
def
test_decode_errors
(
self
):
decode
=
codecs
.
raw_unicode_escape_decode
for
c
,
d
in
(
b'u'
,
4
),
(
b'U'
,
4
):
for
i
in
range
(
d
):
self
.
assertRaises
(
UnicodeDecodeError
,
decode
,
b"
\
\
"
+
c
+
b"0"
*
i
)
self
.
assertRaises
(
UnicodeDecodeError
,
decode
,
b"[
\
\
"
+
c
+
b"0"
*
i
+
b"]"
)
data
=
b"[
\
\
"
+
c
+
b"0"
*
i
+
b"]
\
\
"
+
c
+
b"0"
*
i
self
.
assertEqual
(
decode
(
data
,
"ignore"
),
(
"[]"
,
len
(
data
)))
self
.
assertEqual
(
decode
(
data
,
"replace"
),
(
"[
\
ufffd
]
\
ufffd
"
,
len
(
data
)))
self
.
assertRaises
(
UnicodeDecodeError
,
decode
,
br"\U00110000"
)
self
.
assertEqual
(
decode
(
br"\U00110000"
,
"ignore"
),
(
""
,
10
))
self
.
assertEqual
(
decode
(
br"\U00110000"
,
"replace"
),
(
"
\
ufffd
"
,
10
))
class
SurrogateEscapeTest
(
unittest
.
TestCase
):
def
test_utf8
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment