def __check_for_special_html_blocks( line_to_parse: str, character_index: int ) -> Optional[str]: """ Check for the easy to spot special blocks: 2-5. """ if character_index >= len(line_to_parse): return None html_block_type = None if ParserHelper.is_character_at_index( line_to_parse, character_index, HtmlHelper.__html_block_2_to_5_start ): if ParserHelper.are_characters_at_index( line_to_parse, character_index + 1, HtmlHelper.__html_block_2_continued_start, ): html_block_type = HtmlHelper.html_block_2 elif ParserHelper.is_character_at_index_one_of( line_to_parse, character_index + 1, HtmlHelper.__html_block_4_continued_start, ): html_block_type = HtmlHelper.html_block_4 elif ParserHelper.are_characters_at_index( line_to_parse, character_index + 1, HtmlHelper.__html_block_5_continued_start, ): html_block_type = HtmlHelper.html_block_5 elif ParserHelper.is_character_at_index( line_to_parse, character_index, HtmlHelper.__html_block_3_continued_start, ): html_block_type = HtmlHelper.html_block_3 return html_block_type
def test_are_characters_at_index_with_character_at_end(): """ Make sure that a string with one of the characters at the index is handled properly. """ # Arrange input_string = "this is a abc" sequence_to_look_for = "abc" start_index = len(input_string) - len(sequence_to_look_for) expected_output = True # Act actual_output = ParserHelper.are_characters_at_index( input_string, start_index, sequence_to_look_for) # Assert assert expected_output == actual_output
def are_characters_at_index_with_not_present(): """ Make sure that a string without any characters at the index is handled properly. """ # Arrange input_string = "this is a test" start_index = 6 sequence_to_look_for = "abc" expected_output = False # Act actual_output = ParserHelper.are_characters_at_index( input_string, start_index, sequence_to_look_for) # Assert assert expected_output == actual_output
def test_are_characters_at_index_with_empty_string(): """ Make sure that an empty string is handled properly. """ # Arrange input_string = "" start_index = 0 sequence_to_look_for = "abc" expected_output = False # Act actual_output = ParserHelper.are_characters_at_index( input_string, start_index, sequence_to_look_for) # Assert assert expected_output == actual_output
def __handle_inline_image_link_start_character(inline_request): if ParserHelper.are_characters_at_index( inline_request.source_text, inline_request.next_index, LinkHelper.image_start_sequence, ): inline_response = InlineProcessor.__handle_inline_special( inline_request.source_text, inline_request.next_index, inline_request.inline_blocks, 2, inline_request.remaining_line, inline_request.current_string_unresolved, ) assert not inline_response.consume_rest_of_line else: inline_response = InlineResponse() inline_response.new_string = LinkHelper.image_start_sequence[0] inline_response.new_index = inline_request.next_index + 1 return inline_response