FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
html5lib-python/tests/test_stream.py at python3-old · DKChan/html5lib-python · GitHub
DKChan
/
html5lib-python
Public
forked from
html5lib/html5lib-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
html5lib-python
/
tests
/
test_stream.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
94 lines (79 loc) · 3.73 KB
Breadcrumbs
html5lib-python
/
tests
/
test_stream.py
Copy path
File metadata and controls
executable file
·
94 lines (79 loc) · 3.73 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import
support
import
unittest
,
codecs
from
html5lib
.
inputstream
import
HTMLInputStream
class
HTMLInputStreamTest
(
unittest
.
TestCase
):
def
test_char_ascii
(
self
):
stream
=
HTMLInputStream
(
"'"
,
encoding
=
'ascii'
)
self
.
assertEquals
(
stream
.
charEncoding
[
0
],
'ascii'
)
self
.
assertEquals
(
stream
.
char
(),
"'"
)
def
test_char_null
(
self
):
stream
=
HTMLInputStream
(
"
\x00
"
)
self
.
assertEquals
(
stream
.
char
(),
u'
\ufffd
'
)
def
test_char_utf8
(
self
):
stream
=
HTMLInputStream
(
u'
\u2018
'
.
encode
(
'utf-8'
),
encoding
=
'utf-8'
)
self
.
assertEquals
(
stream
.
charEncoding
[
0
],
'utf-8'
)
self
.
assertEquals
(
stream
.
char
(),
u'
\u2018
'
)
def
test_char_win1252
(
self
):
stream
=
HTMLInputStream
(
u"
\xa9
\xf1
\u2019
"
.
encode
(
'windows-1252'
))
self
.
assertEquals
(
stream
.
charEncoding
[
0
],
'windows-1252'
)
self
.
assertEquals
(
stream
.
char
(),
u"
\xa9
"
)
self
.
assertEquals
(
stream
.
char
(),
u"
\xf1
"
)
self
.
assertEquals
(
stream
.
char
(),
u"
\u2019
"
)
def
test_bom
(
self
):
stream
=
HTMLInputStream
(
codecs
.
BOM_UTF8
+
"'"
)
self
.
assertEquals
(
stream
.
charEncoding
[
0
],
'utf-8'
)
self
.
assertEquals
(
stream
.
char
(),
"'"
)
def
test_utf_16
(
self
):
stream
=
HTMLInputStream
((
' '
*
1025
).
encode
(
'utf-16'
))
self
.
assert_
(
stream
.
charEncoding
[
0
]
in
[
'utf-16-le'
,
'utf-16-be'
],
stream
.
charEncoding
)
self
.
assertEquals
(
len
(
stream
.
charsUntil
(
' '
,
True
)),
1025
)
def
test_newlines
(
self
):
stream
=
HTMLInputStream
(
codecs
.
BOM_UTF8
+
"a
\n
bb
\r
\n
ccc
\r
ddddxe"
)
self
.
assertEquals
(
stream
.
position
(), (
1
,
0
))
self
.
assertEquals
(
stream
.
charsUntil
(
'c'
),
u"a
\n
bb
\n
"
)
self
.
assertEquals
(
stream
.
position
(), (
3
,
0
))
self
.
assertEquals
(
stream
.
charsUntil
(
'x'
),
u"ccc
\n
dddd"
)
self
.
assertEquals
(
stream
.
position
(), (
4
,
4
))
self
.
assertEquals
(
stream
.
charsUntil
(
'e'
),
u"x"
)
self
.
assertEquals
(
stream
.
position
(), (
4
,
5
))
def
test_newlines2
(
self
):
size
=
HTMLInputStream
.
_defaultChunkSize
stream
=
HTMLInputStream
(
"
\r
"
*
size
+
"
\n
"
)
self
.
assertEquals
(
stream
.
charsUntil
(
'x'
),
"
\n
"
*
size
)
def
test_position
(
self
):
stream
=
HTMLInputStream
(
codecs
.
BOM_UTF8
+
"a
\n
bb
\n
ccc
\n
ddde
\n
f
\n
gh"
)
self
.
assertEquals
(
stream
.
position
(), (
1
,
0
))
self
.
assertEquals
(
stream
.
charsUntil
(
'c'
),
u"a
\n
bb
\n
"
)
self
.
assertEquals
(
stream
.
position
(), (
3
,
0
))
stream
.
unget
(
u"
\n
"
)
self
.
assertEquals
(
stream
.
position
(), (
2
,
2
))
self
.
assertEquals
(
stream
.
charsUntil
(
'c'
),
u"
\n
"
)
self
.
assertEquals
(
stream
.
position
(), (
3
,
0
))
stream
.
unget
(
u"
\n
"
)
self
.
assertEquals
(
stream
.
position
(), (
2
,
2
))
self
.
assertEquals
(
stream
.
char
(),
u"
\n
"
)
self
.
assertEquals
(
stream
.
position
(), (
3
,
0
))
self
.
assertEquals
(
stream
.
charsUntil
(
'e'
),
u"ccc
\n
ddd"
)
self
.
assertEquals
(
stream
.
position
(), (
4
,
3
))
self
.
assertEquals
(
stream
.
charsUntil
(
'h'
),
u"e
\n
f
\n
g"
)
self
.
assertEquals
(
stream
.
position
(), (
6
,
1
))
def
test_position2
(
self
):
stream
=
HTMLInputStream
(
"abc
\n
d"
)
self
.
assertEquals
(
stream
.
position
(), (
1
,
0
))
self
.
assertEquals
(
stream
.
char
(),
u"a"
)
self
.
assertEquals
(
stream
.
position
(), (
1
,
1
))
self
.
assertEquals
(
stream
.
char
(),
u"b"
)
self
.
assertEquals
(
stream
.
position
(), (
1
,
2
))
self
.
assertEquals
(
stream
.
char
(),
u"c"
)
self
.
assertEquals
(
stream
.
position
(), (
1
,
3
))
self
.
assertEquals
(
stream
.
char
(),
u"
\n
"
)
self
.
assertEquals
(
stream
.
position
(), (
2
,
0
))
self
.
assertEquals
(
stream
.
char
(),
u"d"
)
self
.
assertEquals
(
stream
.
position
(), (
2
,
1
))
def
buildTestSuite
():
return
unittest
.
defaultTestLoader
.
loadTestsFromName
(
__name__
)
def
main
():
buildTestSuite
()
unittest
.
main
()
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL