using new approach for lexing
This commit is contained in:
1 parent
a2d2b7808d
commit
faaf7925bf
10 files changed
+482
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import io
|
||||
from unittest import TestCase
|
||||
from pdfmajor.safebufiterator import EOF, SafeBufferIt
|
||||
|
||||
|
||||
class UseCase(TestCase):
|
||||
def test_safebuff(self):
|
||||
for bufsize in [2, 33, 65, 66, 100, 200]:
|
||||
it = SafeBufferIt(
|
||||
io.BytesIO(
|
||||
b"this is a lengthy comment that ends here\nso this is not reachable"
|
||||
),
|
||||
buffer_size=bufsize,
|
||||
)
|
||||
for subbuf in it:
|
||||
self.assertLessEqual(len(subbuf), it.buffer_size)
|
||||
|
||||
def test_itraises(self):
|
||||
it = SafeBufferIt(io.BytesIO(b"this"))
|
||||
list(it) # read everything
|
||||
with self.assertRaises(EOF):
|
||||
for _ in it:
|
||||
pass
|
||||
|
||||
def test_seekd(self):
|
||||
for bufsize in [2, 33, 65, 66, 100, 200]:
|
||||
it = SafeBufferIt(
|
||||
io.BytesIO(
|
||||
b"this is a lengthy comment that ends here\nso this is not reachable"
|
||||
),
|
||||
buffer_size=bufsize,
|
||||
)
|
||||
last_buf = next(it)
|
||||
it.seekd(-it.buffer_size)
|
||||
for i, buf in enumerate(it):
|
||||
self.assertEqual(last_buf, buf)
|
||||
it.seekd(-it.buffer_size)
|
||||
if i > 4:
|
||||
break
|
||||
Reference in new issue
Block a user