summaryrefslogtreecommitdiff
path: root/spec/helpers/blob_helper_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-05-23 23:34:03 -0400
committerStan Hu <stanhu@gmail.com>2015-05-27 14:10:58 -0700
commit0cd73885e6279c2a9a477f59eb76095f4e542858 (patch)
tree351a3bf5667d78aa4027538aa03c4e730d36e649 /spec/helpers/blob_helper_spec.rb
parentb222f211c131f471ceae26cff6977881d2d4b4bb (diff)
downloadgitlab-ce-0cd73885e6279c2a9a477f59eb76095f4e542858.tar.gz
Fix git blame syntax highlighting when different commits break up lines
Closes #1521
Diffstat (limited to 'spec/helpers/blob_helper_spec.rb')
-rw-r--r--spec/helpers/blob_helper_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
new file mode 100644
index 00000000000..e49e4e6d5d8
--- /dev/null
+++ b/spec/helpers/blob_helper_spec.rb
@@ -0,0 +1,33 @@
+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") }
+
+ it 'should return plaintext for unknown lexer context' do
+ result = highlight(blob_name, no_context_content, nowrap: true, continue: false)
+ expect(result).to eq('<span id="LC1" class="line">:type &quot;assem&quot;))</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">&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)
+ end
+ end
+end