From 8f152a203467493ee4151cb3c14b60ce44d4cf5f Mon Sep 17 00:00:00 2001 From: Jack De Winter Date: Wed, 24 Aug 2022 21:10:23 -0700 Subject: [PATCH] https://github.com/jackdewinter/pymarkdown/issues/450 - Fixed issues with consistency checks disabled for pragmas --- issues.md | 2 - publish/coverage.json | 4 +- publish/test-results.json | 16 ++-- pymarkdown/container_block_leaf_processor.py | 6 +- pymarkdown/extensions/pragma_token.py | 4 + pymarkdown/parser_helper.py | 1 + .../test_markdown_pragma_parsing.py} | 74 +++++++------------ test/rules/test_md039.py | 48 +++++++++--- test/test_main.py | 8 +- test/transform_to_markdown.py | 17 ++++- 10 files changed, 93 insertions(+), 87 deletions(-) rename test/{gfm/test_markdown_html_blocks_extra.py => extensions/test_markdown_pragma_parsing.py} (75%) diff --git a/issues.md b/issues.md index 1f45f0672..1a31e969a 100644 --- a/issues.md +++ b/issues.md @@ -4,8 +4,6 @@ ## Priority 2 - Like To Solve Before Initial -- pragma tests need to remove `disable_consistency_checks=True` - - make sure to generated ordered/unordered tests to make sure both covered - every unordered tests should have an ordered counterpart - every ordered tests should have an unordered counterpart diff --git a/publish/coverage.json b/publish/coverage.json index 24df13668..c578142d6 100644 --- a/publish/coverage.json +++ b/publish/coverage.json @@ -6,8 +6,8 @@ "totalCovered": 3519 }, "lineLevel": { - "totalMeasured": 12281, - "totalCovered": 12281 + "totalMeasured": 12285, + "totalCovered": 12285 } } diff --git a/publish/test-results.json b/publish/test-results.json index 530165b19..e8cfe6520 100644 --- a/publish/test-results.json +++ b/publish/test-results.json @@ -170,6 +170,14 @@ "skippedTests": 0, "elapsedTimeInMilliseconds": 0 }, + { + "name": "test.extensions.test_markdown_pragma_parsing", + "totalTests": 12, + "failedTests": 0, + "errorTests": 0, + "skippedTests": 0, + "elapsedTimeInMilliseconds": 0 + }, { "name": "test.extensions.test_markdown_pragmas", "totalTests": 13, @@ -410,14 +418,6 @@ "skippedTests": 0, "elapsedTimeInMilliseconds": 0 }, - { - "name": "test.gfm.test_markdown_html_blocks_extra", - "totalTests": 12, - "failedTests": 0, - "errorTests": 0, - "skippedTests": 0, - "elapsedTimeInMilliseconds": 0 - }, { "name": "test.gfm.test_markdown_image_links", "totalTests": 30, diff --git a/pymarkdown/container_block_leaf_processor.py b/pymarkdown/container_block_leaf_processor.py index 2b8105e74..d8a96fa61 100644 --- a/pymarkdown/container_block_leaf_processor.py +++ b/pymarkdown/container_block_leaf_processor.py @@ -883,12 +883,10 @@ def __calculate_current_indent_level( last_list_index = 0 had_non_block_token = False did_hit_indent_level_threshold = False - POGGER.debug_with_visible_whitespace("token-stack:$:", parser_state.token_stack) + POGGER.debug("token-stack:$:", parser_state.token_stack) for current_stack_index in range(1, len(parser_state.token_stack)): proposed_indent_level = 0 - POGGER.debug_with_visible_whitespace( - "token:$:", parser_state.token_stack[current_stack_index] - ) + POGGER.debug("token:$:", parser_state.token_stack[current_stack_index]) if parser_state.token_stack[current_stack_index].is_block_quote: last_list_index = 0 ( diff --git a/pymarkdown/extensions/pragma_token.py b/pymarkdown/extensions/pragma_token.py index 1e5acc866..4057f57de 100644 --- a/pymarkdown/extensions/pragma_token.py +++ b/pymarkdown/extensions/pragma_token.py @@ -67,6 +67,8 @@ def look_for_pragmas( Look for a pragma in the current line. """ + POGGER.debug("look_for_pragmas - >$<", line_to_parse) + POGGER.debug("look_for_pragmas - ws >$<", extracted_whitespace) if ( not container_depth and not extracted_whitespace @@ -97,7 +99,9 @@ def look_for_pragmas( else position_marker.line_number ) parser_properties.pragma_lines[index_number] = line_to_parse + POGGER.debug("pragma $ extracted - >$<", index_number, line_to_parse) return True + POGGER.debug("pragma not extracted - >$<", line_to_parse) return False # pylint: disable=too-many-locals, too-many-arguments diff --git a/pymarkdown/parser_helper.py b/pymarkdown/parser_helper.py index ae2a6882d..ae7d82101 100644 --- a/pymarkdown/parser_helper.py +++ b/pymarkdown/parser_helper.py @@ -576,6 +576,7 @@ def make_value_visible(value_to_modify: Any) -> str: str(value_to_modify) .replace(ParserHelper.__backspace_character, "\\b") .replace(ParserHelper.__alert_character, "\\a") + .replace(ParserHelper.tab_character, "\\t") .replace(ParserHelper.newline_character, "\\n") .replace(ParserHelper.whitespace_split_character, "\\x02") .replace(ParserHelper.replace_noop_character, "\\x03") diff --git a/test/gfm/test_markdown_html_blocks_extra.py b/test/extensions/test_markdown_pragma_parsing.py similarity index 75% rename from test/gfm/test_markdown_html_blocks_extra.py rename to test/extensions/test_markdown_pragma_parsing.py index ca036af96..cc61f0735 100644 --- a/test/gfm/test_markdown_html_blocks_extra.py +++ b/test/extensions/test_markdown_pragma_parsing.py @@ -1,5 +1,5 @@ """ -https://github.github.com/gfm/#html-blocks +Pragmas """ from test.utils import act_and_assert @@ -9,7 +9,7 @@ @pytest.mark.gfm -def test_html_blocks_extrax_01(): +def test_pragma_parsing_01(): """ Test case 01: Pragma alone in a document. """ @@ -20,13 +20,11 @@ def test_html_blocks_extrax_01(): expected_gfm = """""" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_02(): +def test_pragma_parsing_02(): """ Test case 02: Pargma within a paragraph. """ @@ -48,13 +46,11 @@ def test_html_blocks_extrax_02(): expected_gfm = """

This is a paragraph\nstill a paragraph\nand still going.

""" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_03(): +def test_pragma_parsing_03(): """ Test case 03: Pragma at the start and end of the document. """ @@ -74,13 +70,11 @@ def test_html_blocks_extrax_03(): expected_gfm = """

This is a paragraph\nstill a paragraph\nand still going.

""" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_03a(): +def test_pragma_parsing_03a(): """ Test case 03a: Pragma at start and end with a single line paragraph. """ @@ -98,13 +92,11 @@ def test_html_blocks_extrax_03a(): expected_gfm = """

This is a paragraph.

""" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_04(): +def test_pragma_parsing_04(): """ Test case 04: Only two pragmas in entire document. """ @@ -116,13 +108,11 @@ def test_html_blocks_extrax_04(): expected_gfm = "" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_05(): +def test_pragma_parsing_05(): """ Test case 05: Single line paragraph with double pragmas to start and end document. """ @@ -142,13 +132,11 @@ def test_html_blocks_extrax_05(): expected_gfm = "

this is a paragraph

" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_06(): +def test_pragma_parsing_06(): """ Test case 06: Verify that an HTML comment followed by the "pyml " title without any whitespace is parsed. """ @@ -167,13 +155,11 @@ def test_html_blocks_extrax_06(): expected_gfm = "

this is a paragraph

" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_07(): +def test_pragma_parsing_07(): """ Test case 07: Verify that an HTML comment followed by the "pyml " title with multiple whitespace is parsed. """ @@ -192,13 +178,11 @@ def test_html_blocks_extrax_07(): expected_gfm = "

this is a paragraph

" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_08(): +def test_pragma_parsing_08(): """ Test case 08: Pragma-like, without the space after the pragma title. """ @@ -219,13 +203,11 @@ def test_html_blocks_extrax_08(): expected_gfm = "\n

this is a paragraph

" # Act & Assert - act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True - ) + act_and_assert(source_markdown, expected_gfm, expected_tokens) @pytest.mark.gfm -def test_html_blocks_extrax_09(): +def test_pragma_parsing_09(): """ Test case 08: Pragma-like, without the closing comment sequence. """ @@ -243,13 +225,11 @@ def test_html_blocks_extrax_09(): expected_gfm = "{ParserHelper.make_value_visible(ordered_lines[next_line_number])}<--" + ) + detabified_pragma = ParserHelper.detabify_string( + ordered_lines[next_line_number] + ) + print(f"pragma-->{ParserHelper.make_value_visible(detabified_pragma)}<--") + if next_line_number == 1: if transformed_data: transformed_data = ( - f"{ordered_lines[next_line_number]}" + f"{detabified_pragma}" + f"{ParserHelper.newline_character}{transformed_data}" ) else: - transformed_data = ordered_lines[next_line_number] + transformed_data = detabified_pragma else: nth_index = ParserHelper.find_nth_occurrence( transformed_data, @@ -988,12 +997,12 @@ def __handle_pragma_processing(cls, pragma_token, transformed_data): if nth_index == -1: transformed_data = ( f"{transformed_data}{ParserHelper.newline_character}" - + f"{ordered_lines[next_line_number]}" + + f"{detabified_pragma}" ) else: transformed_data = ( f"{transformed_data[:nth_index]}{ParserHelper.newline_character}" - + f"{ordered_lines[next_line_number]}{transformed_data[nth_index:]}" + + f"{detabified_pragma}{transformed_data[nth_index:]}" ) return transformed_data