Skip to content

Commit 02aa5b4

Browse files
authored
Merge pull request increments#157 from increments/add-test-for-code-block
Add test for code_block filter
2 parents a11865f + 8ac0708 commit 02aa5b4

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# frozen_string_literal: true
2+
3+
describe Qiita::Markdown::Filters::CodeBlock do
4+
subject(:filter) { described_class.new(input_html) }
5+
6+
let(:context) { nil }
7+
8+
context "without code" do
9+
let(:input_html) do
10+
<<~HTML
11+
<pre>
12+
</pre>
13+
HTML
14+
end
15+
16+
it "does not change" do
17+
expect(filter.call.to_s).to eq(input_html)
18+
end
19+
end
20+
21+
context "with code" do
22+
let(:input_html) do
23+
<<~HTML
24+
<pre><code>
25+
</code></pre>
26+
HTML
27+
end
28+
29+
it "does not change" do
30+
expect(filter.call.to_s).to eq(input_html)
31+
end
32+
33+
context "with data-metadata" do
34+
let(:input_html) do
35+
<<~HTML
36+
<pre><code data-metadata>
37+
</code></pre>
38+
HTML
39+
end
40+
41+
it "does not change" do
42+
expect(filter.call.to_s).to eq(input_html)
43+
end
44+
45+
context "with data-metadata value" do
46+
let(:input_html) do
47+
<<~HTML
48+
<pre><code data-metadata="ruby">
49+
</code></pre>
50+
HTML
51+
end
52+
53+
let(:output_html) do
54+
<<~HTML
55+
<pre lang="ruby"><code data-metadata="ruby">
56+
</code></pre>
57+
HTML
58+
end
59+
60+
it "adds lang on pre" do
61+
expect(filter.call.to_s).to eq(output_html)
62+
end
63+
64+
context "with value include filename" do
65+
let(:input_html) do
66+
<<~HTML
67+
<pre><code data-metadata="ruby:abc.rb">
68+
</code></pre>
69+
HTML
70+
end
71+
72+
let(:output_html) do
73+
<<~HTML
74+
<pre filename="abc.rb" lang="ruby"><code data-metadata="ruby:abc.rb">
75+
</code></pre>
76+
HTML
77+
end
78+
79+
it "adds lang and filename on pre" do
80+
expect(filter.call.to_s).to eq(output_html)
81+
end
82+
end
83+
end
84+
85+
context "with data-metadata value like filename" do
86+
let(:input_html) do
87+
<<~HTML
88+
<pre><code data-metadata="abc.rb">
89+
</code></pre>
90+
HTML
91+
end
92+
93+
let(:output_html) do
94+
<<~HTML
95+
<pre filename="abc.rb" lang="ruby"><code data-metadata="abc.rb">
96+
</code></pre>
97+
HTML
98+
end
99+
100+
it "adds lang and filename on pre" do
101+
expect(filter.call.to_s).to eq(output_html)
102+
end
103+
end
104+
105+
context "with data-metadata value like filename without extension" do
106+
let(:input_html) do
107+
<<~HTML
108+
<pre><code data-metadata="Dockerfile">
109+
</code></pre>
110+
HTML
111+
end
112+
113+
let(:output_html) do
114+
<<~HTML
115+
<pre lang="Dockerfile"><code data-metadata="Dockerfile">
116+
</code></pre>
117+
HTML
118+
end
119+
120+
it "adds lang and filename on pre" do
121+
expect(filter.call.to_s).to eq(output_html)
122+
end
123+
end
124+
end
125+
end
126+
end

0 commit comments

Comments
 (0)