From 8ac07087a85b46ccc0bb9efc3d52edde4244a0c9 Mon Sep 17 00:00:00 2001 From: nagaya Date: Fri, 5 Apr 2024 18:48:18 +0900 Subject: [PATCH] Add test for code_block filter --- .../qiita/markdown/filters/code_block_spec.rb | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 spec/qiita/markdown/filters/code_block_spec.rb diff --git a/spec/qiita/markdown/filters/code_block_spec.rb b/spec/qiita/markdown/filters/code_block_spec.rb new file mode 100644 index 0000000..3356a6f --- /dev/null +++ b/spec/qiita/markdown/filters/code_block_spec.rb @@ -0,0 +1,126 @@ +# frozen_string_literal: true + +describe Qiita::Markdown::Filters::CodeBlock do + subject(:filter) { described_class.new(input_html) } + + let(:context) { nil } + + context "without code" do + let(:input_html) do + <<~HTML +
+        
+ HTML + end + + it "does not change" do + expect(filter.call.to_s).to eq(input_html) + end + end + + context "with code" do + let(:input_html) do + <<~HTML +

+        
+ HTML + end + + it "does not change" do + expect(filter.call.to_s).to eq(input_html) + end + + context "with data-metadata" do + let(:input_html) do + <<~HTML +

+          
+ HTML + end + + it "does not change" do + expect(filter.call.to_s).to eq(input_html) + end + + context "with data-metadata value" do + let(:input_html) do + <<~HTML +

+            
+ HTML + end + + let(:output_html) do + <<~HTML +

+            
+ HTML + end + + it "adds lang on pre" do + expect(filter.call.to_s).to eq(output_html) + end + + context "with value include filename" do + let(:input_html) do + <<~HTML +

+              
+ HTML + end + + let(:output_html) do + <<~HTML +

+              
+ HTML + end + + it "adds lang and filename on pre" do + expect(filter.call.to_s).to eq(output_html) + end + end + end + + context "with data-metadata value like filename" do + let(:input_html) do + <<~HTML +

+            
+ HTML + end + + let(:output_html) do + <<~HTML +

+            
+ HTML + end + + it "adds lang and filename on pre" do + expect(filter.call.to_s).to eq(output_html) + end + end + + context "with data-metadata value like filename without extension" do + let(:input_html) do + <<~HTML +

+            
+ HTML + end + + let(:output_html) do + <<~HTML +

+            
+ HTML + end + + it "adds lang and filename on pre" do + expect(filter.call.to_s).to eq(output_html) + end + end + end + end +end