2015-12-30 20:18:40 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Diff::Highlight, lib: true do
|
|
|
|
include RepoHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:commit) { project.commit(sample_commit.id) }
|
|
|
|
let(:diff) { commit.diffs.first }
|
2016-01-08 18:40:05 -05:00
|
|
|
let(:diff_file) { Gitlab::Diff::File.new(diff, [commit.parent.id, commit.id], project.repository) }
|
2015-12-30 20:18:40 -05:00
|
|
|
|
|
|
|
describe '.process_diff_lines' do
|
2015-12-31 01:05:52 -05:00
|
|
|
context 'when processing Gitlab::Diff::Line objects' do
|
2016-01-08 18:40:05 -05:00
|
|
|
let(:diff_lines) { Gitlab::Diff::Highlight.process_diff_lines(diff_file) }
|
2015-12-30 20:18:40 -05:00
|
|
|
|
2015-12-31 01:05:52 -05:00
|
|
|
it 'should return Gitlab::Diff::Line elements' do
|
|
|
|
expect(diff_lines.first).to be_an_instance_of(Gitlab::Diff::Line)
|
|
|
|
end
|
2015-12-30 20:18:40 -05:00
|
|
|
|
2015-12-31 01:05:52 -05:00
|
|
|
it 'should highlight the code' do
|
2016-01-08 18:40:05 -05:00
|
|
|
code = %Q{ <span id="LC7" 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}
|
2015-12-30 20:18:40 -05:00
|
|
|
|
2015-12-31 01:05:52 -05:00
|
|
|
expect(diff_lines[2].text).to eq(code)
|
|
|
|
end
|
|
|
|
|
2016-01-08 18:40:05 -05:00
|
|
|
it 'should not generate the inline diff markup' do
|
|
|
|
expect(diff_lines[5].text).not_to match(Regexp.new(Regexp.escape('<span class="idiff">')))
|
2015-12-31 01:05:52 -05:00
|
|
|
end
|
2015-12-30 20:18:40 -05:00
|
|
|
|
2015-12-31 01:05:52 -05:00
|
|
|
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
|
2015-12-30 20:18:40 -05:00
|
|
|
end
|
2016-01-08 18:40:05 -05:00
|
|
|
end
|
2015-12-30 21:44:12 -05:00
|
|
|
|
2016-01-08 18:40:05 -05:00
|
|
|
describe '.process_file' do
|
|
|
|
let(:lines) do
|
|
|
|
Gitlab::Diff::Highlight.process_file(project.repository, commit.id, 'files/ruby/popen.rb')
|
2015-12-30 21:44:12 -05:00
|
|
|
end
|
2015-12-31 01:05:52 -05:00
|
|
|
|
2016-01-08 18:40:05 -05:00
|
|
|
it 'should properly highlight all the lines' do
|
|
|
|
expect(lines[4]).to eq(%Q{<span id="LC5" class="line"> <span class="kp">extend</span> <span class="nb">self</span></span>\n})
|
|
|
|
expect(lines[21]).to eq(%Q{<span id="LC22" class="line"> <span class="k">unless</span> <span class="no">File</span><span class="p">.</span><span class="nf">directory?</span><span class="p">(</span><span class="n">path</span><span class="p">)</span></span>\n})
|
|
|
|
expect(lines[26]).to eq(%Q{<span id="LC27" class="line"> <span class="vi">@cmd_status</span> <span class="o">=</span> <span class="mi">0</span></span>\n})
|
|
|
|
end
|
2015-12-30 20:18:40 -05:00
|
|
|
end
|
2016-01-08 18:40:05 -05:00
|
|
|
|
2015-12-30 20:18:40 -05:00
|
|
|
end
|