def test_skip_to_peek(self): ps = ParserStream("abcd") ps.peek() ps.peek() ps.skip_to_peek() self.assertEqual('c', ps.current()) self.assertEqual('c', ps.current_peek()) self.assertEqual(2, ps.get_peek_index()) self.assertEqual(2, ps.get_index()) ps.peek() self.assertEqual('c', ps.current()) self.assertEqual('d', ps.current_peek()) self.assertEqual(3, ps.get_peek_index()) self.assertEqual(2, ps.get_index()) ps.next() self.assertEqual('d', ps.current()) self.assertEqual('d', ps.current_peek()) self.assertEqual(3, ps.get_peek_index()) self.assertEqual(3, ps.get_index())
def test_peek(self): ps = ParserStream("abcd") self.assertEqual('a', ps.current_peek()) self.assertEqual(0, ps.get_peek_index()) self.assertEqual('b', ps.peek()) self.assertEqual('b', ps.current_peek()) self.assertEqual(1, ps.get_peek_index()) self.assertEqual('c', ps.peek()) self.assertEqual('c', ps.current_peek()) self.assertEqual(2, ps.get_peek_index()) self.assertEqual('d', ps.peek()) self.assertEqual('d', ps.current_peek()) self.assertEqual(3, ps.get_peek_index()) self.assertEqual(None, ps.peek()) self.assertEqual(None, ps.current_peek()) self.assertEqual(4, ps.get_peek_index())
def test_reset_peek(self): ps = ParserStream("abcd") ps.next() ps.peek() ps.peek() ps.reset_peek() self.assertEqual('b', ps.current()) self.assertEqual('b', ps.current_peek()) self.assertEqual(1, ps.get_peek_index()) self.assertEqual(1, ps.get_index()) ps.peek() self.assertEqual('b', ps.current()) self.assertEqual('c', ps.current_peek()) self.assertEqual(2, ps.get_peek_index()) self.assertEqual(1, ps.get_index()) ps.peek() ps.peek() ps.peek() ps.reset_peek() self.assertEqual('b', ps.current()) self.assertEqual('b', ps.current_peek()) self.assertEqual(1, ps.get_peek_index()) self.assertEqual(1, ps.get_index()) self.assertEqual('c', ps.peek()) self.assertEqual('b', ps.current()) self.assertEqual('c', ps.current_peek()) self.assertEqual(2, ps.get_peek_index()) self.assertEqual(1, ps.get_index()) self.assertEqual('d', ps.peek()) self.assertEqual(None, ps.peek())