# frozen_string_literal: true
require 'rouge'
describe Nanoc::Filters::ColorizeSyntax, filter: true do
subject { filter.setup_and_run(input, default_colorizer: :rouge, rouge: params) }
let(:filter) { ::Nanoc::Filters::ColorizeSyntax.new }
let(:params) { {} }
let(:wrap) { false }
let(:css_class) { 'highlight' }
let(:input) do
<<~EOS
before
def foo
end
after
EOS
end
let(:output) do
<<~EOS
before
def foo
end
after
EOS
end
context 'with Rouge' do
context 'with default options' do
it { is_expected.to eql output }
end
context 'with legacy' do
let(:legacy) { true }
let(:params) { super().merge(legacy: legacy) }
it { is_expected.to eql output }
context 'with pygments wrapper' do
let(:wrap) { true }
let(:params) { super().merge(wrap: wrap) }
it { is_expected.to eql output }
context 'with css_class' do
let(:css_class) { 'nanoc' }
let(:params) { super().merge(css_class: css_class) }
it { is_expected.to eql output }
end
end
context 'with line number' do
let(:line_numbers) { true }
let(:params) { super().merge(line_numbers: line_numbers) }
let(:output) do
<<~EOS
before
after
EOS
end
it { is_expected.to eql output }
end
end
context 'with formater' do
let(:params) { super().merge(formatter: formatter) }
context 'with inline' do
let(:formatter) { Rouge::Formatters::HTMLInline.new(theme) }
context 'with github theme' do
let(:theme) { Rouge::Themes::Github.new }
let(:output) do
<<~EOS
before
def foo
end
after
EOS
end
it { is_expected.to eql output }
end
context 'with colorful theme' do
let(:theme) { Rouge::Themes::Colorful.new }
let(:output) do
<<~EOS
before
def foo
end
after
EOS
end
it { is_expected.to eql output }
end
end
context 'with linewise' do
let(:formatter) { Rouge::Formatters::HTMLLinewise.new(Rouge::Formatters::HTML.new) }
let(:output) do
<<~EOS
before
def foo
end
after
EOS
end
it { is_expected.to eql output }
end
context 'with pygments' do
let(:wrap) { true }
let(:css_class) { 'codehilite' }
let(:formatter) { Rouge::Formatters::HTMLPygments.new(Rouge::Formatters::HTML.new) }
it { is_expected.to eql output }
end
context 'with table' do
let(:formatter) { Rouge::Formatters::HTMLTable.new(Rouge::Formatters::HTML.new) }
let(:output) do
<<~EOS
before
after
EOS
end
it { is_expected.to eql output }
end
end
end
end