2015-05-23 23:34:03 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BlobHelper do
|
2016-01-19 08:52:41 -05:00
|
|
|
let(:blob_name) { 'test.lisp' }
|
|
|
|
let(:no_context_content) { ":type \"assem\"))" }
|
|
|
|
let(:blob_content) { "(make-pathname :defaults name\n#{no_context_content}" }
|
|
|
|
let(:split_content) { blob_content.split("\n") }
|
|
|
|
let(:multiline_content) do
|
|
|
|
%q(
|
|
|
|
def test(input):
|
|
|
|
"""This is line 1 of a multi-line comment.
|
|
|
|
This is line 2.
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
end
|
2015-05-23 23:34:03 -04:00
|
|
|
|
2016-01-19 08:52:41 -05:00
|
|
|
describe '#highlight' do
|
2015-05-23 23:34:03 -04:00
|
|
|
it 'should return plaintext for unknown lexer context' do
|
2016-01-19 08:52:41 -05:00
|
|
|
result = helper.highlight(blob_name, no_context_content, nowrap: true)
|
2015-05-23 23:34:03 -04:00
|
|
|
expect(result).to eq('<span id="LC1" class="line">:type "assem"))</span>')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should highlight single block' do
|
|
|
|
expected = %Q[<span id="LC1" class="line"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span>
|
|
|
|
<span id="LC2" class="line"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span>]
|
|
|
|
|
2016-01-19 08:52:41 -05:00
|
|
|
expect(helper.highlight(blob_name, blob_content, nowrap: true)).to eq(expected)
|
2015-05-23 23:34:03 -04:00
|
|
|
end
|
2015-07-31 01:31:53 -04:00
|
|
|
|
|
|
|
it 'should highlight multi-line comments' do
|
2016-01-19 08:52:41 -05:00
|
|
|
result = helper.highlight(blob_name, multiline_content, nowrap: true)
|
2015-07-31 01:31:53 -04:00
|
|
|
html = Nokogiri::HTML(result)
|
|
|
|
lines = html.search('.s')
|
|
|
|
expect(lines.count).to eq(3)
|
|
|
|
expect(lines[0].text).to eq('"""This is line 1 of a multi-line comment.')
|
2016-01-19 08:52:41 -05:00
|
|
|
expect(lines[1].text).to eq(' This is line 2.')
|
|
|
|
expect(lines[2].text).to eq(' """')
|
2015-07-31 01:31:53 -04:00
|
|
|
end
|
2015-08-10 02:08:28 -04:00
|
|
|
|
|
|
|
context 'diff highlighting' do
|
|
|
|
let(:blob_name) { 'test.diff' }
|
|
|
|
let(:blob_content) { "+aaa\n+bbb\n- ccc\n ddd\n"}
|
|
|
|
let(:expected) do
|
|
|
|
%q(<span id="LC1" class="line"><span class="gi">+aaa</span></span>
|
|
|
|
<span id="LC2" class="line"><span class="gi">+bbb</span></span>
|
|
|
|
<span id="LC3" class="line"><span class="gd">- ccc</span></span>
|
|
|
|
<span id="LC4" class="line"> ddd</span>)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should highlight each line properly' do
|
2016-01-19 08:52:41 -05:00
|
|
|
result = helper.highlight(blob_name, blob_content, nowrap: true)
|
2015-08-10 02:08:28 -04:00
|
|
|
expect(result).to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
2015-05-23 23:34:03 -04:00
|
|
|
end
|
2016-01-19 08:52:41 -05:00
|
|
|
|
|
|
|
describe "#highlighter" do
|
|
|
|
it 'should highlight continued blocks' do
|
|
|
|
# Both lines have LC1 as ID since formatter doesn't support continue at the moment
|
|
|
|
expected = [
|
|
|
|
'<span id="LC1" class="line"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span>',
|
|
|
|
'<span id="LC1" class="line"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span>'
|
|
|
|
]
|
|
|
|
|
|
|
|
highlighter = helper.highlighter(blob_name, blob_content, nowrap: true)
|
|
|
|
result = split_content.map{ |content| highlighter.highlight(content) }
|
|
|
|
expect(result).to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
2015-05-23 23:34:03 -04:00
|
|
|
end
|