gitlab-org--gitlab-foss/spec/lib/gitlab/diff/highlight_spec.rb

49 lines
2.2 KiB
Ruby
Raw Normal View History

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) }
describe '.process_diff_lines' do
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) }
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
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}
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">')))
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
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
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
end
2016-01-08 18:40:05 -05:00
end