2016-01-19 10:26:44 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab::Highlight do
|
2016-01-19 10:26:44 -05:00
|
|
|
include RepoHelpers
|
|
|
|
|
2017-01-24 18:42:12 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-06-16 14:07:22 -04:00
|
|
|
let(:repository) { project.repository }
|
2016-01-19 10:26:44 -05:00
|
|
|
let(:commit) { project.commit(sample_commit.id) }
|
|
|
|
|
2016-06-10 18:42:43 -04:00
|
|
|
describe 'custom highlighting from .gitattributes' do
|
2016-06-16 14:07:22 -04:00
|
|
|
let(:branch) { 'gitattributes' }
|
|
|
|
let(:blob) { repository.blob_at_branch(branch, path) }
|
|
|
|
|
2016-06-16 14:52:40 -04:00
|
|
|
let(:highlighter) do
|
2017-07-25 13:09:00 -04:00
|
|
|
described_class.new(blob.path, blob.data, repository: repository)
|
2016-06-16 14:52:40 -04:00
|
|
|
end
|
2016-06-10 18:42:43 -04:00
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
project.change_head('gitattributes')
|
|
|
|
end
|
2016-06-16 14:07:22 -04:00
|
|
|
|
2016-06-22 15:53:58 -04:00
|
|
|
describe 'basic language selection' do
|
|
|
|
let(:path) { 'custom-highlighting/test.gitlab-custom' }
|
|
|
|
it 'highlights as ruby' do
|
|
|
|
expect(highlighter.lexer.tag).to eq 'ruby'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'cgi options' do
|
|
|
|
let(:path) { 'custom-highlighting/test.gitlab-cgi' }
|
|
|
|
|
|
|
|
it 'highlights as json with erb' do
|
|
|
|
expect(highlighter.lexer.tag).to eq 'erb'
|
|
|
|
expect(highlighter.lexer.parent.tag).to eq 'json'
|
|
|
|
end
|
2016-06-10 18:42:43 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-10 17:13:06 -04:00
|
|
|
|
|
|
|
describe '#highlight' do
|
2017-06-06 17:21:29 -04:00
|
|
|
describe 'with CRLF' do
|
|
|
|
let(:branch) { 'crlf-diff' }
|
|
|
|
let(:path) { 'files/whitespace' }
|
|
|
|
let(:blob) { repository.blob_at_branch(branch, path) }
|
|
|
|
let(:lines) do
|
2017-07-25 13:09:00 -04:00
|
|
|
described_class.highlight(blob.path, blob.data, repository: repository).lines
|
2017-06-06 17:21:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'strips extra LFs' do
|
|
|
|
expect(lines[0]).to eq("<span id=\"LC1\" class=\"line\" lang=\"plaintext\">test </span>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-10 17:13:06 -04:00
|
|
|
it 'links dependencies via DependencyLinker' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(Gitlab::DependencyLinker).to receive(:link)
|
|
|
|
.with('file.name', 'Contents', anything).and_call_original
|
2016-07-10 17:13:06 -04:00
|
|
|
|
|
|
|
described_class.highlight('file.name', 'Contents')
|
|
|
|
end
|
|
|
|
end
|
2016-01-19 10:26:44 -05:00
|
|
|
end
|