diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 00:11:02 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 00:11:02 +0000 |
| commit | c95fc172145f1bdbc8d959b6cee31555fc545784 (patch) | |
| tree | 5aa4940ddefb9bea164905d61916593cc265a05c /spec/scripts/lib/glfm | |
| parent | eda321fc0b96e44e296341f6288dd7f1a27ba93a (diff) | |
| download | gitlab-ce-c95fc172145f1bdbc8d959b6cee31555fc545784.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/scripts/lib/glfm')
| -rw-r--r-- | spec/scripts/lib/glfm/parse_examples_spec.rb | 331 | ||||
| -rw-r--r-- | spec/scripts/lib/glfm/update_example_snapshots_spec.rb | 130 |
2 files changed, 416 insertions, 45 deletions
diff --git a/spec/scripts/lib/glfm/parse_examples_spec.rb b/spec/scripts/lib/glfm/parse_examples_spec.rb new file mode 100644 index 00000000000..7caba95e10e --- /dev/null +++ b/spec/scripts/lib/glfm/parse_examples_spec.rb @@ -0,0 +1,331 @@ +# frozen_string_literal: true +require 'fast_spec_helper' +require_relative '../../../../scripts/lib/glfm/parse_examples' + +RSpec.describe Glfm::ParseExamples, '#parse_examples' do + subject do + described_module = described_class + Class.new { include described_module }.new + end + + let(:spec_txt_contents) do + <<~SPEC_TXT_CONTENTS + --- + title: Spec + ... + + # Introduction + + intro + + # 1.0.0 H1 + + ## 1.1.0 H2 + + no extension + + ```````````````````````````````` example + example 1 md + . + html + ```````````````````````````````` + + one extension + + ```````````````````````````````` example extension_1.1.0-1 + example 2 md + . + html + ```````````````````````````````` + + ### 1.1.1 H3 with no examples + + text + + ### 1.1.2 Consecutive H3 with example + + text + + ```````````````````````````````` example disabled + example 3 md + . + html + ```````````````````````````````` + + ## 1.2.0 H2 with all disabled examples + + + ```````````````````````````````` example disabled + example 4 md + . + html + ```````````````````````````````` + + ## 1.2.0 New H2 + + + ```````````````````````````````` example extension_1.2.0-1 + example 5 md + . + html + ```````````````````````````````` + + # 2.0.0 New H1 + + ## 2.1.0 H2 + + ```````````````````````````````` example gitlab extension_2.1.0-1 + example 6 md + . + html + ```````````````````````````````` + + ## 2.2.0 H2 which contains an H3 + + No example here, just text + + ### 2.2.1 H3 + + The CommonMark and GHFM specifications don't have any examples inside an H3, but it is + supported for the GLFM specification. + + ```````````````````````````````` example extension_2.2.1-1 + example 7 md + . + html + ```````````````````````````````` + + # 3.0.0 New H1 + + ## 3.1.0 H2 + + ```````````````````````````````` example + example 8 md + . + html + ```````````````````````````````` + + ### 3.1.1 H3 + + ```````````````````````````````` example + example 9 md + . + html + ```````````````````````````````` + + ### 3.1.1 Consecutive H3 + + ```````````````````````````````` example + example 10 md + . + html + ```````````````````````````````` + + ## 3.2.0 Another H2 + + ```````````````````````````````` example + example 11 md + . + html + ```````````````````````````````` + + <!-- END TESTS --> + + # Appendix + + Appendix text. + SPEC_TXT_CONTENTS + end + + let(:spec_txt_lines) { spec_txt_contents.split("\n") } + + describe "parsing" do + it 'correctly parses' do + examples = subject.parse_examples(spec_txt_lines) + + expected = + [ + { + disabled: false, + end_line: 19, + example: 1, + extensions: [], + headers: [ + '1.0.0 H1', + '1.1.0 H2' + ], + html: 'html', + markdown: 'example 1 md', + section: '1.1.0 H2', + start_line: 15 + }, + { + disabled: false, + end_line: 27, + example: 2, + extensions: %w[extension_1.1.0-1], + headers: [ + '1.0.0 H1', + '1.1.0 H2' + ], + html: 'html', + markdown: 'example 2 md', + section: '1.1.0 H2', + start_line: 23 + }, + { + disabled: true, + end_line: 41, + example: 3, + extensions: %w[disabled], + headers: [ + '1.0.0 H1', + '1.1.0 H2', + '1.1.2 Consecutive H3 with example' + ], + html: 'html', + markdown: 'example 3 md', + section: '1.1.2 Consecutive H3 with example', + start_line: 37 + }, + { + disabled: true, + end_line: 50, + example: 4, + extensions: %w[disabled], + headers: [ + '1.0.0 H1', + '1.2.0 H2 with all disabled examples' + ], + html: 'html', + markdown: 'example 4 md', + section: '1.2.0 H2 with all disabled examples', + start_line: 46 + }, + { + disabled: false, + end_line: 59, + example: 5, + extensions: %w[extension_1.2.0-1], + headers: [ + '1.0.0 H1', + '1.2.0 New H2' + ], + html: 'html', + markdown: 'example 5 md', + section: '1.2.0 New H2', + start_line: 55 + }, + { + disabled: false, + end_line: 69, + example: 6, + extensions: %w[gitlab extension_2.1.0-1], + headers: [ + '2.0.0 New H1', + '2.1.0 H2' + ], + html: 'html', + markdown: 'example 6 md', + section: '2.1.0 H2', + start_line: 65 + }, + { + disabled: false, + end_line: 84, + example: 7, + extensions: %w[extension_2.2.1-1], + headers: [ + '2.0.0 New H1', + '2.2.0 H2 which contains an H3', + '2.2.1 H3' + ], + html: 'html', + markdown: 'example 7 md', + section: '2.2.1 H3', + start_line: 80 + }, + { + disabled: false, + end_line: 94, + example: 8, + extensions: [], + headers: [ + '3.0.0 New H1', + '3.1.0 H2' + ], + html: 'html', + markdown: 'example 8 md', + section: '3.1.0 H2', + start_line: 90 + }, + { + disabled: false, + end_line: 102, + example: 9, + extensions: [], + headers: [ + '3.0.0 New H1', + '3.1.0 H2', + '3.1.1 H3' + ], + html: 'html', + markdown: 'example 9 md', + section: '3.1.1 H3', + start_line: 98 + }, + { + disabled: false, + end_line: 110, + example: 10, + extensions: [], + headers: [ + '3.0.0 New H1', + '3.1.0 H2', + '3.1.1 Consecutive H3' + ], + html: 'html', + markdown: 'example 10 md', + section: '3.1.1 Consecutive H3', + start_line: 106 + }, + { + disabled: false, + end_line: 118, + example: 11, + extensions: [], + headers: [ + '3.0.0 New H1', + '3.2.0 Another H2' + ], + html: 'html', + markdown: 'example 11 md', + section: '3.2.0 Another H2', + start_line: 114 + } + ] + + expect(examples).to eq(expected) + end + end + + describe "with incorrect header nesting" do + let(:spec_txt_contents) do + <<~SPEC_TXT_CONTENTS + --- + title: Spec + ... + + # H1 + + ### H3 + + SPEC_TXT_CONTENTS + end + + it "raises if H3 is nested directly in H1" do + expect { subject.parse_examples(spec_txt_lines) } + .to raise_error(/The H3 'H3' may not be nested directly within the H1 'H1'/) + end + end +end diff --git a/spec/scripts/lib/glfm/update_example_snapshots_spec.rb b/spec/scripts/lib/glfm/update_example_snapshots_spec.rb index fe815aa6f1e..6bf4dc3bd0d 100644 --- a/spec/scripts/lib/glfm/update_example_snapshots_spec.rb +++ b/spec/scripts/lib/glfm/update_example_snapshots_spec.rb @@ -134,6 +134,19 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do <p><strong>bold</strong></p> ```````````````````````````````` + ## H2 which contains an H3 + + ### Example in an H3 + + The CommonMark and GHFM specifications don't have any examples inside an H3, but it is + supported for the GLFM specification. + + ```````````````````````````````` example gitlab + Example in an H3 + . + <p>Example in an H3</p> + ```````````````````````````````` + # Second GitLab-Specific Section with Examples ## Strong but with HTML @@ -182,15 +195,15 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~GLFM_EXAMPLE_STATUS_YML_CONTENTS --- - 02_01__inlines__strong__001: + 02_01_00__inlines__strong__001: # The skip_update_example_snapshots key is present, but false, so this example is not skipped skip_update_example_snapshots: false - 02_01__inlines__strong__002: + 02_01_00__inlines__strong__002: # It is OK to have an empty (nil) value for an example statuses entry, it means they will all be false. - 05_01__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001: + 05_01_00__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001: # Always skip this example skip_update_example_snapshots: 'skipping this example because it is very bad' - 05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: + 05_02_00__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: # Always skip this example, but preserve the existing manual modifications skip_update_example_snapshots: 'skipping this example because we have manually modified it' GLFM_EXAMPLE_STATUS_YML_CONTENTS @@ -200,21 +213,21 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~ES_HTML_YML_IO_EXISTING_CONTENTS --- - 00_00__obsolete_entry_to_be_deleted__001: + 00_00_00__obsolete_entry_to_be_deleted__001: canonical: | This entry is no longer exists in the spec.txt, and is not skipped, so it will be deleted. static: |- This entry is no longer exists in the spec.txt, and is not skipped, so it will be deleted. wysiwyg: |- This entry is no longer exists in the spec.txt, and is not skipped, so it will be deleted. - 02_01__inlines__strong__001: + 02_01_00__inlines__strong__001: canonical: | This entry is existing, but not skipped, so it will be overwritten. static: |- This entry is existing, but not skipped, so it will be overwritten. wysiwyg: |- This entry is existing, but not skipped, so it will be overwritten. - 05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: + 05_02_00__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: canonical: | <p><strong>This example will have its manually modified static HTML, WYSIWYG HTML, and ProseMirror JSON preserved</strong></p> static: |- @@ -228,16 +241,16 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~ES_PROSEMIRROR_JSON_YML_IO_EXISTING_CONTENTS --- - 00_00__obsolete_entry_to_be_deleted__001: + 00_00_00__obsolete_entry_to_be_deleted__001: { "obsolete": "This entry is no longer exists in the spec.txt, and is not skipped, so it will be deleted." } - 02_01__inlines__strong__001: |- + 02_01_00__inlines__strong__001: |- { "existing": "This entry is existing, but not skipped, so it will be overwritten." } # 02_01__inlines__strong__002: is omitted from the existing file and skipped, to test that scenario. - 02_03__inlines__strikethrough_extension__001: |- + 02_03_00__inlines__strikethrough_extension__001: |- { "type": "doc", "content": [ @@ -252,11 +265,11 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do } ] } - 04_01__second_gitlab_specific_section_with_examples__strong_but_with_html__001: |- + 04_01_00__second_gitlab_specific_section_with_examples__strong_but_with_html__001: |- { "existing": "This entry is manually modified and preserved because skip_update_example_snapshot_prosemirror_json will be truthy" } - 05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: |- + 05_02_00__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: |- { "existing": "This entry is manually modified and preserved because skip_update_example_snapshots will be truthy" } @@ -303,7 +316,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do let(:es_examples_index_yml_contents) { reread_io(es_examples_index_yml_io) } let(:es_markdown_yml_contents) { reread_io(es_markdown_yml_io) } let(:expected_unskipped_example) do - /05_01__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001/ + /05_01_00__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001/ end it 'still writes the example to examples_index.yml' do @@ -323,14 +336,14 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~GLFM_EXAMPLE_STATUS_YML_CONTENTS --- - 02_01__inlines__strong__001: + 02_01_00__inlines__strong__001: skip_update_example_snapshots: 'if the skip_update_example_snapshots key is truthy...' skip_update_example_snapshot_html_static: '...then no other skip_update_example_* keys can be truthy' GLFM_EXAMPLE_STATUS_YML_CONTENTS end it 'raises an error' do - expected_msg = "Error: '02_01__inlines__strong__001' must not have any 'skip_update_example_snapshot_*' " \ + expected_msg = "Error: '02_01_00__inlines__strong__001' must not have any 'skip_update_example_snapshot_*' " \ "values specified if 'skip_update_example_snapshots' is truthy" expect { subject.process }.to raise_error(/#{Regexp.escape(expected_msg)}/) end @@ -343,27 +356,30 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~ES_EXAMPLES_INDEX_YML_CONTENTS --- - 02_01__inlines__strong__001: + 02_01_00__inlines__strong__001: spec_txt_example_position: 1 source_specification: commonmark - 02_01__inlines__strong__002: + 02_01_00__inlines__strong__002: spec_txt_example_position: 2 source_specification: github - 02_03__inlines__strikethrough_extension__001: + 02_03_00__inlines__strikethrough_extension__001: spec_txt_example_position: 4 source_specification: github - 03_01__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: + 03_01_00__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: spec_txt_example_position: 5 source_specification: gitlab - 04_01__second_gitlab_specific_section_with_examples__strong_but_with_html__001: + 03_02_01__first_gitlab_specific_section_with_examples__h2_which_contains_an_h3__example_in_an_h3__001: spec_txt_example_position: 6 source_specification: gitlab - 05_01__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001: + 04_01_00__second_gitlab_specific_section_with_examples__strong_but_with_html__001: spec_txt_example_position: 7 source_specification: gitlab - 05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: + 05_01_00__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001: spec_txt_example_position: 8 source_specification: gitlab + 05_02_00__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: + spec_txt_example_position: 9 + source_specification: gitlab ES_EXAMPLES_INDEX_YML_CONTENTS end @@ -380,21 +396,23 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~ES_MARKDOWN_YML_CONTENTS --- - 02_01__inlines__strong__001: | + 02_01_00__inlines__strong__001: | __bold__ - 02_01__inlines__strong__002: | + 02_01_00__inlines__strong__002: | __bold with more text__ - 02_03__inlines__strikethrough_extension__001: | + 02_03_00__inlines__strikethrough_extension__001: | ~~Hi~~ Hello, world! - 03_01__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: | + 03_01_00__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: | **bold** - 04_01__second_gitlab_specific_section_with_examples__strong_but_with_html__001: | + 03_02_01__first_gitlab_specific_section_with_examples__h2_which_contains_an_h3__example_in_an_h3__001: | + Example in an H3 + 04_01_00__second_gitlab_specific_section_with_examples__strong_but_with_html__001: | <strong> bold </strong> - 05_01__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001: | + 05_01_00__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001: | **this example will be skipped** - 05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: | + 05_02_00__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: | **This example will have its manually modified static HTML, WYSIWYG HTML, and ProseMirror JSON preserved** ES_MARKDOWN_YML_CONTENTS end @@ -416,16 +434,16 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~GLFM_EXAMPLE_STATUS_YML_CONTENTS --- - 02_01__inlines__strong__002: + 02_01_00__inlines__strong__002: skip_update_example_snapshot_prosemirror_json: "skipping because JSON isn't cool enough" - 03_01__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: + 03_01_00__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: skip_update_example_snapshot_html_static: "skipping because there's too much static" - 04_01__second_gitlab_specific_section_with_examples__strong_but_with_html__001: + 04_01_00__second_gitlab_specific_section_with_examples__strong_but_with_html__001: skip_update_example_snapshot_html_wysiwyg: 'skipping because what you see is NOT what you get' skip_update_example_snapshot_prosemirror_json: "skipping because JSON still isn't cool enough" - 05_01__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001: + 05_01_00__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001: skip_update_example_snapshots: 'skipping this example because it is very bad' - 05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: + 05_02_00__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: skip_update_example_snapshots: 'skipping this example because we have manually modified it' GLFM_EXAMPLE_STATUS_YML_CONTENTS end @@ -434,33 +452,40 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~ES_HTML_YML_CONTENTS --- - 02_01__inlines__strong__001: + 02_01_00__inlines__strong__001: canonical: | <p><strong>bold</strong></p> static: |- <p data-sourcepos="1:1-1:8" dir="auto"><strong>bold</strong></p> wysiwyg: |- <p><strong>bold</strong></p> - 02_01__inlines__strong__002: + 02_01_00__inlines__strong__002: canonical: | <p><strong>bold with more text</strong></p> static: |- <p data-sourcepos="1:1-1:23" dir="auto"><strong>bold with more text</strong></p> wysiwyg: |- <p><strong>bold with more text</strong></p> - 02_03__inlines__strikethrough_extension__001: + 02_03_00__inlines__strikethrough_extension__001: canonical: | <p><del>Hi</del> Hello, world!</p> static: |- <p data-sourcepos="1:1-1:20" dir="auto"><del>Hi</del> Hello, world!</p> wysiwyg: |- <p><s>Hi</s> Hello, world!</p> - 03_01__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: + 03_01_00__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: canonical: | <p><strong>bold</strong></p> wysiwyg: |- <p><strong>bold</strong></p> - 04_01__second_gitlab_specific_section_with_examples__strong_but_with_html__001: + 03_02_01__first_gitlab_specific_section_with_examples__h2_which_contains_an_h3__example_in_an_h3__001: + canonical: | + <p>Example in an H3</p> + static: |- + <p data-sourcepos="1:1-1:16" dir="auto">Example in an H3</p> + wysiwyg: |- + <p>Example in an H3</p> + 04_01_00__second_gitlab_specific_section_with_examples__strong_but_with_html__001: canonical: | <p><strong> bold @@ -469,7 +494,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do <strong> bold </strong> - 05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: + 05_02_00__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: canonical: | <p><strong>This example will have its manually modified static HTML, WYSIWYG HTML, and ProseMirror JSON preserved</strong></p> static: |- @@ -483,7 +508,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do # language=YAML <<~ES_PROSEMIRROR_JSON_YML_CONTENTS --- - 02_01__inlines__strong__001: |- + 02_01_00__inlines__strong__001: |- { "type": "doc", "content": [ @@ -503,7 +528,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do } ] } - 02_03__inlines__strikethrough_extension__001: |- + 02_03_00__inlines__strikethrough_extension__001: |- { "type": "doc", "content": [ @@ -527,7 +552,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do } ] } - 03_01__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: |- + 03_01_00__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: |- { "type": "doc", "content": [ @@ -547,11 +572,26 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do } ] } - 04_01__second_gitlab_specific_section_with_examples__strong_but_with_html__001: |- + 03_02_01__first_gitlab_specific_section_with_examples__h2_which_contains_an_h3__example_in_an_h3__001: |- + { + "type": "doc", + "content": [ + { + "type": "paragraph", + "content": [ + { + "type": "text", + "text": "Example in an H3" + } + ] + } + ] + } + 04_01_00__second_gitlab_specific_section_with_examples__strong_but_with_html__001: |- { "existing": "This entry is manually modified and preserved because skip_update_example_snapshot_prosemirror_json will be truthy" } - 05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: |- + 05_02_00__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001: |- { "existing": "This entry is manually modified and preserved because skip_update_example_snapshots will be truthy" } |
