require 'spec_helper'
RSpec.describe Prawn::SVG::CSS::Stylesheets do
describe 'typical usage' do
let(:svg) { <<-SVG }
SVG
it 'associates styles with elements' do
result = Prawn::SVG::CSS::Stylesheets.new(CssParser::Parser.new, REXML::Document.new(svg)).load
width_and_styles = result.map { |k, v| [k.attributes['width'].to_i, v] }.sort_by(&:first)
expected = [
[0, [['overflow', 'hidden', false]]],
[1, [['fill', '#ff0000', false]]],
[2,
[['fill', '#ff0000', false], ['fill', '#330000', false], ['fill', '#440000', false],
['fill', '#220000', false]]],
[3, [['fill', '#ff0000', false], ['fill', '#00ff00', false]]],
[4,
[['fill', '#ff0000', false], ['fill', '#330000', false], ['fill', '#440000', false],
['fill', '#00ff00', false]]]
]
expected << [5,
[['fill', '#ff0000', false], ['fill', '#330000', false], ['fill', '#330000', false], ['fill', '#440000', false],
['fill', '#00ff00', false]]]
expected.push(
[6, [['fill', '#ff0000', false], ['fill', '#441234', false], ['fill', '#0000ff', false]]],
[7, [['fill', '#550000', false]]],
[8, [['fill', '#660000', false]]],
[9, [['fill', '#770000', false]]],
[10, [['fill', '#880000', false]]],
[11, [['fill', '#990000', false]]],
[12, [['fill', '#aa0000', false]]],
[13, [['fill', '#bb0000', false]]],
[14, [['fill', '#cc0000', false]]],
[15, [['fill', '#dd0000', false]]],
[16, [['fill', '#ee0000', false]]]
)
expect(width_and_styles).to eq(expected)
end
end
describe 'style tag parsing' do
let(:svg) do
<<~SVG
SVG
end
it 'scans the document for style tags and adds the style information to the css parser' do
css_parser = instance_double(CssParser::Parser)
expect(css_parser).to receive(:add_block!).with('svg, symbol, image, marker, pattern, foreignObject { overflow: hidden }')
expect(css_parser).to receive(:add_block!).with("a\n before>\n x y\n inside <>>\n k j\n after\nz")
expect(css_parser).to receive(:add_block!).with('hello')
allow(css_parser).to receive(:each_rule_set)
Prawn::SVG::CSS::Stylesheets.new(css_parser, REXML::Document.new(svg)).load
end
end
end