Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-01-19 16:52:41 +0300
committerDouwe Maan <douwe@gitlab.com>2016-01-19 16:52:41 +0300
commit512bebe21d7f57b691a1c8355581feb64b9b6292 (patch)
tree22813185c803071668a235b9418e1476075e81df /spec/helpers
parent0a8039eb7790426880bdd7b9d67775aeb6e5dac7 (diff)
Refactor Gitlab::Highlight and fix tests
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/blob_helper_spec.rb63
1 files changed, 33 insertions, 30 deletions
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
index b8bba36439a..87849230dbe 100644
--- a/spec/helpers/blob_helper_spec.rb
+++ b/spec/helpers/blob_helper_spec.rb
@@ -1,22 +1,22 @@
require 'spec_helper'
describe BlobHelper do
- describe 'highlight' do
- 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
+ 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
+ describe '#highlight' do
it 'should return plaintext for unknown lexer context' do
- result = highlight(blob_name, no_context_content, nowrap: true, continue: false)
+ result = helper.highlight(blob_name, no_context_content, nowrap: true)
expect(result).to eq('<span id="LC1" class="line">:type &quot;assem&quot;))</span>')
end
@@ -24,28 +24,17 @@ describe BlobHelper 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">&quot;assem&quot;</span><span class="p">))</span></span>]
- expect(highlight(blob_name, blob_content, nowrap: true, continue: false)).to eq(expected)
- end
-
- 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">&quot;assem&quot;</span><span class="p">))</span></span>'
- ]
-
- result = split_content.map{ |content| highlight(blob_name, content, nowrap: true, continue: true) }
- expect(result).to eq(expected)
+ expect(helper.highlight(blob_name, blob_content, nowrap: true)).to eq(expected)
end
it 'should highlight multi-line comments' do
- result = highlight(blob_name, multiline_content, nowrap: true, continue: false)
+ result = helper.highlight(blob_name, multiline_content, nowrap: true)
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.')
- expect(lines[1].text).to eq(' This is line 2.')
- expect(lines[2].text).to eq(' """')
+ expect(lines[1].text).to eq(' This is line 2.')
+ expect(lines[2].text).to eq(' """')
end
context 'diff highlighting' do
@@ -59,9 +48,23 @@ describe BlobHelper do
end
it 'should highlight each line properly' do
- result = highlight(blob_name, blob_content, nowrap: true, continue: false)
+ result = helper.highlight(blob_name, blob_content, nowrap: true)
expect(result).to eq(expected)
end
end
end
+
+ 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">&quot;assem&quot;</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
end