require 'spec_helper' describe BlobHelper 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 describe '#highlight' do it 'should return plaintext for unknown lexer context' do result = helper.highlight(blob_name, no_context_content, nowrap: true) expect(result).to eq(':type "assem"))') end it 'should highlight single block' do expected = %Q[(make-pathname :defaults name :type "assem"))] expect(helper.highlight(blob_name, blob_content, nowrap: true)).to eq(expected) end it 'should highlight multi-line comments' do 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(' """') end context 'diff highlighting' do let(:blob_name) { 'test.diff' } let(:blob_content) { "+aaa\n+bbb\n- ccc\n ddd\n"} let(:expected) do %q(+aaa +bbb - ccc ddd) end it 'should highlight each line properly' do 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 = [ '(make-pathname :defaults name', ':type "assem"))' ] highlighter = helper.highlighter(blob_name, blob_content, nowrap: true) result = split_content.map{ |content| highlighter.highlight(content) } expect(result).to eq(expected) end end describe "#sanitize_svg" do let(:input_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'unsanitized.svg') } let(:data) { open(input_svg_path).read } let(:expected_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'sanitized.svg') } let(:expected) { open(expected_svg_path).read } it 'should retain essential elements' do blob = OpenStruct.new(data: data) expect(sanitize_svg(blob).data).to eq(expected) end end end