File: html_line_highlighter_spec.rb

package info (click to toggle)
ruby-rouge 4.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,844 kB
  • sloc: ruby: 38,489; sed: 2,071; perl: 152; makefile: 8
file content (28 lines) | stat: -rw-r--r-- 1,106 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Formatters::HTMLLineHighlighter do
  let(:subject) { Rouge::Formatters::HTMLLineHighlighter.new(formatter, options) }
  let(:formatter) { Rouge::Formatters::HTML.new }

  let(:options) { {} }
  let(:output) { subject.format(input_stream) }

  describe 'highlight lines' do
    let(:input_stream) { [[Token['Text'], "foo\n"], [Token['Name'], "bar\n"]] }
    let(:options) { { highlight_lines: [2] } }

    it 'should add highlight line class to lines specified by :highlight_lines option' do
      assert { output == %(foo\n<span class="hll"><span class="n">bar</span>\n</span>) }
    end
  end

  describe 'configure highlight line class' do
    let(:input_stream) { [[Token['Text'], "foo\n"], [Token['Name'], "bar\n"]] }
    let(:options) { { highlight_lines: [1, 2], highlight_line_class: 'hiline' } }

    it 'should add highlight line class to lines specified by :highlight_lines option' do
      assert { output == %(<span class="hiline">foo\n</span><span class="hiline"><span class="n">bar</span>\n</span>) }
    end
  end
end