From 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 18 Nov 2021 13:16:36 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-5-stable-ee --- spec/lib/banzai/filter/markdown_filter_spec.rb | 153 +++++++++++++++---------- 1 file changed, 94 insertions(+), 59 deletions(-) (limited to 'spec/lib/banzai/filter/markdown_filter_spec.rb') diff --git a/spec/lib/banzai/filter/markdown_filter_spec.rb b/spec/lib/banzai/filter/markdown_filter_spec.rb index c5e84a0c1e7..a310de5c015 100644 --- a/spec/lib/banzai/filter/markdown_filter_spec.rb +++ b/spec/lib/banzai/filter/markdown_filter_spec.rb @@ -5,90 +5,125 @@ require 'spec_helper' RSpec.describe Banzai::Filter::MarkdownFilter do include FilterSpecHelper - describe 'markdown engine from context' do - it 'defaults to CommonMark' do - expect_next_instance_of(Banzai::Filter::MarkdownEngines::CommonMark) do |instance| - expect(instance).to receive(:render).and_return('test') + shared_examples_for 'renders correct markdown' do + describe 'markdown engine from context' do + it 'defaults to CommonMark' do + expect_next_instance_of(Banzai::Filter::MarkdownEngines::CommonMark) do |instance| + expect(instance).to receive(:render).and_return('test') + end + + filter('test') end - filter('test') - end + it 'uses CommonMark' do + expect_next_instance_of(Banzai::Filter::MarkdownEngines::CommonMark) do |instance| + expect(instance).to receive(:render).and_return('test') + end - it 'uses CommonMark' do - expect_next_instance_of(Banzai::Filter::MarkdownEngines::CommonMark) do |instance| - expect(instance).to receive(:render).and_return('test') + filter('test', { markdown_engine: :common_mark }) end - - filter('test', { markdown_engine: :common_mark }) end - end - describe 'code block' do - context 'using CommonMark' do - before do - stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark) + describe 'code block' do + context 'using CommonMark' do + before do + stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark) + end + + it 'adds language to lang attribute when specified' do + result = filter("```html\nsome code\n```", no_sourcepos: true) + + if Feature.enabled?(:use_cmark_renderer) + expect(result).to start_with('
')
+          else
+            expect(result).to start_with('
')
+          end
+        end
+
+        it 'does not add language to lang attribute when not specified' do
+          result = filter("```\nsome code\n```", no_sourcepos: true)
+
+          expect(result).to start_with('
')
+        end
+
+        it 'works with utf8 chars in language' do
+          result = filter("```日\nsome code\n```", no_sourcepos: true)
+
+          if Feature.enabled?(:use_cmark_renderer)
+            expect(result).to start_with('
')
+          else
+            expect(result).to start_with('
')
+          end
+        end
+
+        it 'works with additional language parameters' do
+          result = filter("```ruby:red gem foo\nsome code\n```", no_sourcepos: true)
+
+          if Feature.enabled?(:use_cmark_renderer)
+            expect(result).to start_with('
')
+          else
+            expect(result).to start_with('
')
+          end
+        end
       end
+    end
 
-      it 'adds language to lang attribute when specified' do
-        result = filter("```html\nsome code\n```", no_sourcepos: true)
-
-        expect(result).to start_with('
')
-      end
-
-      it 'does not add language to lang attribute when not specified' do
-        result = filter("```\nsome code\n```", no_sourcepos: true)
-
-        expect(result).to start_with('
')
-      end
+    describe 'source line position' do
+      context 'using CommonMark' do
+        before do
+          stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark)
+        end
 
-      it 'works with utf8 chars in language' do
-        result = filter("```日\nsome code\n```", no_sourcepos: true)
+        it 'defaults to add data-sourcepos' do
+          result = filter('test')
 
-        expect(result).to start_with('
')
-      end
+          expect(result).to eq '

test

' + end - it 'works with additional language parameters' do - result = filter("```ruby:red gem\nsome code\n```", no_sourcepos: true) + it 'disables data-sourcepos' do + result = filter('test', no_sourcepos: true) - expect(result).to start_with('
')
+          expect(result).to eq '

test

' + end end end - end - describe 'source line position' do - context 'using CommonMark' do - before do - stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark) - end + describe 'footnotes in tables' do + it 'processes footnotes in table cells' do + text = <<-MD.strip_heredoc + | Column1 | + | --------- | + | foot [^1] | - it 'defaults to add data-sourcepos' do - result = filter('test') + [^1]: a footnote + MD - expect(result).to eq '

test

' - end + result = filter(text, no_sourcepos: true) - it 'disables data-sourcepos' do - result = filter('test', no_sourcepos: true) + expect(result).to include('foot test

' + if Feature.enabled?(:use_cmark_renderer) + expect(result).to include('
') + else + expect(result).to include('
') + end end end end - describe 'footnotes in tables' do - it 'processes footnotes in table cells' do - text = <<-MD.strip_heredoc - | Column1 | - | --------- | - | foot [^1] | - - [^1]: a footnote - MD + context 'using ruby-based HTML renderer' do + before do + stub_feature_flags(use_cmark_renderer: false) + end - result = filter(text, no_sourcepos: true) + it_behaves_like 'renders correct markdown' + end - expect(result).to include('foot ') + context 'using c-based HTML renderer' do + before do + stub_feature_flags(use_cmark_renderer: true) end + + it_behaves_like 'renders correct markdown' end end -- cgit v1.2.1