Skip to content

Commit

Permalink
Add new tests with syntax highlighting/include:file expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
wioux committed Jul 7, 2022
1 parent 6bd7802 commit 5d3e04f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/templates/helpers/html_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@ def options
expect(htmlify("test {include:file:foo.rdoc}", :rdoc).gsub(/[\r?\n]+/, '')).to eq '<p>test HI</p>'
end

it "preserves syntax highlighting in {include:} snippets" do
load_markup_provider(:rdoc)
expect(File).to receive(:file?).with('foo.rdoc').and_return(true)
expect(File).to receive(:read).with('foo.rdoc').and_return(
" !!!ruby\n x = 1\n"
)
expect(htmlify("{include:file:foo.rdoc}", :rdoc).gsub(/[\r?\n]+/, '')).
not_to include("&lt;")
end

it "escapes {include:} html snippets only once" do
expect(self).to receive(:html_syntax_highlight_html) do |source|
%(<strong>#{CGI.escapeHTML(source)}</strong>)
end.at_least(:once)

load_markup_provider(:rdoc)
expect(File).to receive(:file?).with('foo.md').and_return(true)
expect(File).to receive(:read).with('foo.md').and_return(
" !!!html\n <h1>\n"
)
expect(htmlify("{include:file:foo.md}", :markdown).gsub(/[\r?\n]+/, '')).
to include(%(<strong>&lt;h1&gt;</strong>))
end

it "does not autolink URLs inside of {} (markdown specific)" do
log.enter_level(Logger::FATAL) do
pending 'This test depends on markdown' unless markup_class(:markdown)
Expand Down Expand Up @@ -648,6 +672,12 @@ def subject.respond_to?(method, include_all = false)
)
end

it "wraps but doesn't alter code snippets that already contain highlighting tags" do
expect(subject.htmlify('<pre lang="foo"><span class="kw">for</span></pre>', :html)).to eq(
'<pre class="code foo"><code class="foo"><span class="kw">for</span></code></pre>'
)
end

it "highlights source when matching a pre lang= tag" do
expect(subject.htmlify('<pre lang="foo"><code>x = 1</code></pre>', :html)).to eq(
'<pre class="code foo"><code class="foo">x = 1</code></pre>'
Expand Down

0 comments on commit 5d3e04f

Please sign in to comment.