def test_navigation_positions(chikin): assert chikin.char_pos_to_line(0) == (0, 0), '\\' assert chikin.char_pos_to_line(1) == (0, 1), 'documentclass' assert chikin.char_pos_to_line(172) == (11, 6), 'waddle' assert isinstance(next(next(chikin.itemize.children).tokens), TokenWithPosition) # get position of first token waddle_pos = next(next(chikin.itemize.children).tokens).position assert chikin.char_pos_to_line(waddle_pos) == (11, 6) # get position of item enumerate_first_item_pos = next(chikin.enumerate.children).name.position assert chikin.char_pos_to_line(enumerate_first_item_pos) == (22, 1) # get position of section section_pos = list(chikin.find_all('section'))[1].name.position assert chikin.char_pos_to_line(section_pos) == (15, 1)
def test_replace_multiple(chikin): """Replace an element in the parse tree""" chikin.section.replace(chikin.subsection, chikin.subsection) assert 'Chikin Tales' not in str(chikin) assert len(list(chikin.find_all('subsection'))) == 5
def test_find_by_command(chikin): """Find all LaTeX blocks that match a command""" sections = list(chikin.find_all('section')) assert str(sections[0]) == '\section{Chikin Tales}' assert str(sections[1]) == '\section{Chikin Scream}'
def test_replace_single(chikin): """Replace an element in the parse tree""" chikin.section.replace_with(chikin.subsection) assert 'Chikin Tales' not in str(chikin) assert len(list(chikin.find_all('subsection'))) == 4
def test_find_by_command(chikin): """Find all LaTeX blocks that match a command""" sections = list(chikin.find_all('section')) assert str(sections[0]) == r'\section{Chikin Tales}' assert str(sections[1]) == r'\section{Chikin Scream}'