Skip to content

Commit a9babdb

Browse files
committed
Add new tests with syntax highlighting/include:file expectations
1 parent 6bd7802 commit a9babdb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

spec/templates/helpers/html_helper_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,30 @@ def options
144144
expect(htmlify("test {include:file:foo.rdoc}", :rdoc).gsub(/[\r?\n]+/, '')).to eq '<p>test HI</p>'
145145
end
146146

147+
it "preserves syntax highlighting in {include:} snippets" do
148+
load_markup_provider(:rdoc)
149+
expect(File).to receive(:file?).with('foo.rdoc').and_return(true)
150+
expect(File).to receive(:read).with('foo.rdoc').and_return(
151+
" !!!ruby\n x = 1\n"
152+
)
153+
expect(htmlify("{include:file:foo.rdoc}", :rdoc).gsub(/[\r?\n]+/, '')).
154+
not_to include("&lt;")
155+
end
156+
157+
it "escapes {include:} html snippets only once" do
158+
expect(self).to receive(:html_syntax_highlight_html) do |source|
159+
%(<strong>#{CGI.escapeHTML(source)}</strong>)
160+
end.at_least(:once)
161+
162+
load_markup_provider(:rdoc)
163+
expect(File).to receive(:file?).with('foo.md').and_return(true)
164+
expect(File).to receive(:read).with('foo.md').and_return(
165+
" !!!html\n <h1>\n"
166+
)
167+
expect(htmlify("{include:file:foo.md}", :markdown).gsub(/[\r?\n]+/, '')).
168+
to include(%(<strong>&lt;h1&gt;</strong>))
169+
end
170+
147171
it "does not autolink URLs inside of {} (markdown specific)" do
148172
log.enter_level(Logger::FATAL) do
149173
pending 'This test depends on markdown' unless markup_class(:markdown)
@@ -648,6 +672,12 @@ def subject.respond_to?(method, include_all = false)
648672
)
649673
end
650674

675+
it "wraps but doesn't alter ruby snippets that already contain highlighting tags" do
676+
expect(subject.htmlify('<pre lang="ruby"><span class="kw">for</span></pre>', :html)).to eq(
677+
'<pre class="code ruby"><code class="ruby"><span class="kw">for</span></code></pre>'
678+
)
679+
end
680+
651681
it "highlights source when matching a pre lang= tag" do
652682
expect(subject.htmlify('<pre lang="foo"><code>x = 1</code></pre>', :html)).to eq(
653683
'<pre class="code foo"><code class="foo">x = 1</code></pre>'

0 commit comments

Comments
 (0)