Beispiel #1
0
    def test__next__1(self):
        input = io.StringIO('first line\nsecond line\nthird line')
        lines = inputlines_.InputLines(input)

        line = next(lines)
        self.assertEqual(line, 'first line')
        self.assertEqual(line.loc(), inputloc_.InputLoc(repr(input), 1))

        line = next(lines)
        self.assertEqual(line, 'second line')
        self.assertEqual(line.loc(), inputloc_.InputLoc(repr(input), 2))

        line = next(lines)
        self.assertEqual(line, 'third line')
        self.assertEqual(line.loc(), inputloc_.InputLoc(repr(input), 3))

        with self.assertRaises(StopIteration):
            next(lines)
Beispiel #2
0
 def test__loc__1(self):
     it = ThreeLines()
     bi = bufferediterator_.BufferedIterator(it)
     self.assertEqual(it.loc(), inputloc_.InputLoc('three_lines', 1))
     self.assertEqual(bi.loc(), it.loc())
     line = next(bi)
     self.assertEqual(line.loc(), inputloc_.InputLoc('three_lines', 1))
     self.assertEqual(it.loc(), inputloc_.InputLoc('three_lines', 2))
     self.assertEqual(bi.loc(), it.loc())
     line = next(bi)
     self.assertEqual(line.loc(), inputloc_.InputLoc('three_lines', 2))
     self.assertEqual(it.loc(), inputloc_.InputLoc('three_lines', 3))
     self.assertEqual(bi.loc(), it.loc())
     line = next(bi)
     self.assertEqual(line.loc(), inputloc_.InputLoc('three_lines', 3))
     self.assertEqual(it.loc(), inputloc_.InputLoc('three_lines', 4))
     self.assertEqual(bi.loc(), it.loc())
     # this is quite illegal...
     bi._index = 1
     self.assertEqual(bi.loc(), inputloc_.InputLoc('three_lines', 2))
     self.assertEqual(it.loc(), inputloc_.InputLoc('three_lines', 4))
Beispiel #3
0
 def test__logstr__1(self):
     ctx = inputloc_.InputLoc('foo.pdf', 20)
     self.assertEqual(ctx.__logstr__(), 'foo.pdf:20')
Beispiel #4
0
 def test__init__1(self):
     ctx = inputloc_.InputLoc('foo.pdf', 20)
     self.assertEqual(ctx.name, 'foo.pdf')
     self.assertEqual(ctx.line, 20)
Beispiel #5
0
 def test__loc__1(self):
     input = io.StringIO('first line\nsecond line\nthird line')
     lines = inputlines_.InputLines(input)
     self.assertEqual(lines.loc(), inputloc_.InputLoc(repr(input), 1))
Beispiel #6
0
    def test__next__1(self):
        bi = bufferediterator_.BufferedIterator(ThreeLines())
        self.assertEqual(bi._index, 0)
        self.assertEqual(len(bi._buffer), 0)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'first line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 1))
        self.assertEqual(bi._index, 1)
        self.assertEqual(len(bi._buffer), 1)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'second line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 2))
        self.assertEqual(bi._index, 2)
        self.assertEqual(len(bi._buffer), 2)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'third line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 3))
        self.assertEqual(bi._index, 3)
        self.assertEqual(len(bi._buffer), 3)

        with self.assertRaises(StopIteration):
            next(bi)

        bi.rewind()
        self.assertEqual(bi._index, 0)
        self.assertEqual(len(bi._buffer), 3)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'first line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 1))
        self.assertEqual(bi._index, 1)
        self.assertEqual(len(bi._buffer), 3)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'second line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 2))
        self.assertEqual(bi._index, 2)
        self.assertEqual(len(bi._buffer), 3)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'third line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 3))
        self.assertEqual(bi._index, 3)
        self.assertEqual(len(bi._buffer), 3)

        with self.assertRaises(StopIteration):
            next(bi)

        bi.rewind()
        self.assertEqual(bi._index, 0)
        self.assertEqual(len(bi._buffer), 3)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'first line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 1))
        self.assertEqual(bi._index, 1)
        self.assertEqual(len(bi._buffer), 3)

        bi.drop()
        self.assertEqual(bi._index, 0)
        self.assertEqual(len(bi._buffer), 2)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'second line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 2))
        self.assertEqual(bi._index, 1)
        self.assertEqual(len(bi._buffer), 2)

        ln = next(bi)
        self.assertIsInstance(ln, inputline_.InputLine)
        self.assertEqual(ln, 'third line')
        self.assertEqual(ln.loc(), inputloc_.InputLoc('three_lines', 3))
        self.assertEqual(bi._index, 2)
        self.assertEqual(len(bi._buffer), 2)

        with self.assertRaises(StopIteration):
            next(bi)
Beispiel #7
0
 def loc(self):
     return inputloc_.InputLoc('three_lines', self._lineno)
Beispiel #8
0
 def test__init__3(self):
     loc = inputloc_.InputLoc('foo.pdf', 12)
     line = inputline_.InputLine('lorem ipsum', loc)
     self.assertIs(line.loc(), loc)
Beispiel #9
0
 def test__loc__1(self):
     ctx = inputloc_.InputLoc('input.txt', 20)
     self.assertEqual(self.createTestObj().loc(), ctx)
Beispiel #10
0
 def createTestObj(self, description = 'parsing error', string = "funky line",
                   source='input.txt', lineno=20):
     loc = inputloc_.InputLoc(source, lineno)
     line = inputline_.InputLine(string, loc)
     return (self.classTested())(line, description)