debian-mirror-gitlab/spec/lib/gitlab/highlight_spec.rb

61 lines
1.7 KiB
Ruby
Raw Normal View History

2016-01-29 22:53:50 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Gitlab::Highlight do
2016-01-29 22:53:50 +05:30
include RepoHelpers
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2016-08-24 12:49:21 +05:30
let(:repository) { project.repository }
2016-01-29 22:53:50 +05:30
let(:commit) { project.commit(sample_commit.id) }
2016-08-24 12:49:21 +05:30
describe 'custom highlighting from .gitattributes' do
let(:branch) { 'gitattributes' }
let(:blob) { repository.blob_at_branch(branch, path) }
let(:highlighter) do
2017-09-10 17:25:29 +05:30
described_class.new(blob.path, blob.data, repository: repository)
2016-08-24 12:49:21 +05:30
end
2017-09-10 17:25:29 +05:30
before do
project.change_head('gitattributes')
end
2016-08-24 12:49:21 +05:30
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
end
end
2017-09-10 17:25:29 +05:30
describe '#highlight' do
describe 'with CRLF' do
let(:branch) { 'crlf-diff' }
let(:path) { 'files/whitespace' }
let(:blob) { repository.blob_at_branch(branch, path) }
let(:lines) do
described_class.highlight(blob.path, blob.data, repository: repository).lines
end
it 'strips extra LFs' do
expect(lines[0]).to eq("<span id=\"LC1\" class=\"line\" lang=\"plaintext\">test </span>")
end
end
it 'links dependencies via DependencyLinker' do
expect(Gitlab::DependencyLinker).to receive(:link)
.with('file.name', 'Contents', anything).and_call_original
described_class.highlight('file.name', 'Contents')
end
end
2016-01-29 22:53:50 +05:30
end