mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-28 05:56:37 +10:00
Apply syntax highlighting when expanding diff plus some refactor. #3945
This commit is contained in:
@@ -9,25 +9,41 @@ describe Gitlab::Diff::Highlight, lib: true do
|
||||
let(:diff_file) { Gitlab::Diff::File.new(diff) }
|
||||
|
||||
describe '.process_diff_lines' do
|
||||
let(:diff_lines) { Gitlab::Diff::Highlight.process_diff_lines(diff_file.new_path, diff_file.diff_lines) }
|
||||
context 'when processing Gitlab::Diff::Line objects' do
|
||||
let(:diff_lines) { Gitlab::Diff::Highlight.process_diff_lines(diff_file.new_path, diff_file.diff_lines) }
|
||||
|
||||
it 'should return Gitlab::Diff::Line elements' do
|
||||
expect(diff_lines.first).to be_an_instance_of(Gitlab::Diff::Line)
|
||||
it 'should return Gitlab::Diff::Line elements' do
|
||||
expect(diff_lines.first).to be_an_instance_of(Gitlab::Diff::Line)
|
||||
end
|
||||
|
||||
it 'should highlight the code' do
|
||||
code = %Q{<span id="LC3" class="line"> <span class="k">def</span> <span class="nf">popen</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span></span>\n}
|
||||
|
||||
expect(diff_lines[2].text).to eq(code)
|
||||
end
|
||||
|
||||
it 'should keep the inline diff markup' do
|
||||
expect(diff_lines[5].text).to match(Regexp.new(Regexp.escape('<span class="idiff">RuntimeError, </span>')))
|
||||
end
|
||||
|
||||
it 'should not modify "match" lines' do
|
||||
expect(diff_lines[0].text).to eq('@@ -6,12 +6,18 @@ module Popen')
|
||||
expect(diff_lines[22].text).to eq('@@ -19,6 +25,7 @@ module Popen')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should highlight the code' do
|
||||
code = %Q{<span id="LC3" class="line"> <span class="k">def</span> <span class="nf">popen</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span></span>\n}
|
||||
context 'when processing raw lines' do
|
||||
let(:lines) { ["puts 'Hello'\n", "# A comment"] }
|
||||
let(:highlighted_lines) { Gitlab::Diff::Highlight.process_diff_lines('demo.rb', lines) }
|
||||
|
||||
expect(diff_lines[2].text).to eq(code)
|
||||
it 'should highlight the code' do
|
||||
line_1 = %Q{<span id="LC1" class="line"><span class="nb">puts</span> <span class="s1">'Hello'</span></span>\n}
|
||||
line_2 = %Q{<span id="LC2" class="line"><span class="c1"># A comment</span></span>}
|
||||
|
||||
expect(highlighted_lines[0]).to eq(line_1)
|
||||
expect(highlighted_lines[1]).to eq(line_2)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should keep the inline diff markup' do
|
||||
expect(diff_lines[5].text).to match(Regexp.new(Regexp.escape('<span class="idiff">RuntimeError, </span>')))
|
||||
end
|
||||
|
||||
it 'should not modify "match" lines' do
|
||||
expect(diff_lines[0].text).to eq('@@ -6,12 +6,18 @@ module Popen')
|
||||
expect(diff_lines[22].text).to eq('@@ -19,6 +25,7 @@ module Popen')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user