Off-by-one in GridOut.readline().

This commit is contained in:
A. Jesse Jiryu Davis 2013-12-16 11:32:24 -05:00
parent 3649a3a0d7
commit df60a5fa97
2 changed files with 15 additions and 1 deletions

View File

@ -511,7 +511,7 @@ class GridOut(object):
for pos in xrange(len(chunk_data)):
byte = chunk_data[pos]
if byte == EMPTY or byte == NEWLN:
size = received + pos
size = received + pos + 1
break
received += len(chunk_data)

View File

@ -396,6 +396,7 @@ Hope all is well.
Bye"""))
f.close()
# Try read(), then readline().
g = GridOut(self.db.fs, f._id)
self.assertEqual(b("H"), g.read(1))
self.assertEqual(b("ello world,\n"), g.readline())
@ -406,6 +407,19 @@ Bye"""))
self.assertEqual(b("Bye"), g.readline())
self.assertEqual(b(""), g.readline())
# Try readline() first, then read().
g = GridOut(self.db.fs, f._id)
self.assertEqual(b("He"), g.readline(2))
self.assertEqual(b("l"), g.read(1))
self.assertEqual(b("lo"), g.readline(2))
self.assertEqual(b(" world,\n"), g.readline())
# Only readline().
g = GridOut(self.db.fs, f._id)
self.assertEqual(b("H"), g.readline(1))
self.assertEqual(b("e"), g.readline(1))
self.assertEqual(b("llo world,\n"), g.readline())
def test_iterator(self):
f = GridIn(self.db.fs)
f.close()