def test_get_contents_after_insert4(input_file_simple): pt = PieceTable.fromfile(input_file_simple) assert len(pt.pieces) == 1 pt.insert(0, 'unseriousnessbywayofhowtosandhacks\n') exp = 'unseriousnessbywayofhowtosandhacks\nthe quick brown fox\njumped over the lazy dog' assert pt.get_contents() == exp assert len(pt.pieces) == 2
def test_get_contents_after_insert2(input_file_simple): pt = PieceTable.fromfile(input_file_simple) assert len(pt.pieces) == 1 pt.insert(1, 'a') exp = 'tahe quick brown fox\njumped over the lazy dog' assert pt.get_contents() == exp print(pt.pieces) assert len(pt.pieces) == 3
def test_from_file(input_file_simple): pt = PieceTable.fromfile(input_file_simple) assert len(pt.pieces) == 1 piece = pt.pieces[0] assert piece.start == 0 assert piece.length == 44 assert piece.piece_type == PieceType.ORIGINAL assert len(pt.original) == 44 line_starts = piece.line_starts assert len(line_starts) == 2 assert line_starts[0] == 0 assert line_starts[1] == 20
def test_insert_middle(input_file_simple): pt = PieceTable.fromfile(input_file_simple) assert len(pt.pieces) == 1 pt.insert(20, "went to the park and\n") assert len(pt.pieces) == 3 assert pt.pieces[0].start == 0 assert pt.pieces[0].length == 20 assert pt.pieces[0].piece_type == PieceType.ORIGINAL assert pt.pieces[1].start == 0 assert pt.pieces[1].length == 21 assert pt.pieces[1].piece_type == PieceType.ADDED assert pt.pieces[2].start == 20 assert pt.pieces[2].length == 24 assert pt.pieces[2].piece_type == PieceType.ORIGINAL
def test_get_contents_after_insert5(input_file_simple): pt = PieceTable.fromfile(input_file_simple) assert len(pt.pieces) == 1 pt.insert(44, '\n\n thats the end') exp = 'the quick brown fox\njumped over the lazy dog\n\n thats the end' assert pt.get_contents() == exp pt.insert(47, "asdf ") exp = 'the quick brown fox\njumped over the lazy dog\n\n asdf thats the end' assert pt.get_contents() == exp pt.insert(5, 'qqq') exp = 'the qqqquick brown fox\njumped over the lazy dog\n\n asdf thats the end' assert pt.get_contents() == exp print(pt.pieces) pt.insert(53, " dang ") print(pt.pieces) exp = 'the qqqquick brown fox\njumped over the lazy dog\n\n asd dang f thats the end' assert pt.get_contents() == exp
def test_get_contents_after_insert(input_file_simple): pt = PieceTable.fromfile(input_file_simple) assert len(pt.pieces) == 1 pt.insert(20, "went to the park and\n") exp = 'the quick brown fox\nwent to the park and\njumped over the lazy dog' assert pt.get_contents() == exp