2016-01-19 15:26:44 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Highlight, lib: true do
|
|
|
|
include RepoHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project) }
|
2016-06-16 18:07:22 +00:00
|
|
|
let(:repository) { project.repository }
|
2016-01-19 15:26:44 +00:00
|
|
|
let(:commit) { project.commit(sample_commit.id) }
|
|
|
|
|
|
|
|
describe '.highlight_lines' do
|
|
|
|
let(:lines) do
|
|
|
|
Gitlab::Highlight.highlight_lines(project.repository, commit.id, 'files/ruby/popen.rb')
|
|
|
|
end
|
|
|
|
|
|
|
|
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-06-10 22:42:43 +00:00
|
|
|
describe 'custom highlighting from .gitattributes' do
|
2016-06-16 18:07:22 +00:00
|
|
|
let(:branch) { 'gitattributes' }
|
|
|
|
let(:path) { 'custom-highlighting/test.gitlab-custom' }
|
|
|
|
let(:blob) { repository.blob_at_branch(branch, path) }
|
|
|
|
|
2016-06-16 18:52:40 +00:00
|
|
|
let(:highlighter) do
|
2016-06-16 18:07:22 +00:00
|
|
|
Gitlab::Highlight.new(blob.path, blob.data, repository: repository)
|
2016-06-16 18:52:40 +00:00
|
|
|
end
|
2016-06-10 22:42:43 +00:00
|
|
|
|
2016-06-16 18:07:22 +00:00
|
|
|
before { project.change_head('gitattributes') }
|
|
|
|
|
2016-06-10 22:42:43 +00:00
|
|
|
it 'highlights as ruby' do
|
2016-06-16 18:20:57 +00:00
|
|
|
expect(highlighter.lexer.tag).to eq 'ruby'
|
2016-06-10 22:42:43 +00:00
|
|
|
end
|
|
|
|
end
|
2016-01-19 15:26:44 +00:00
|
|
|
end
|