spec/prawn/svg/css/stylesheets_spec.rb in prawn-svg-0.29.0 vs spec/prawn/svg/css/stylesheets_spec.rb in prawn-svg-0.29.1
- old
+ new
@@ -9,10 +9,11 @@
#outer { fill: #220000; }
.hero > rect { fill: #00ff00; }
rect { fill: #ff0000; }
rect ~ rect { fill: #330000; }
rect + rect { fill: #440000; }
+ rect:first-child:last-child { fill: #441234; }
circle:first-child { fill: #550000; }
circle:nth-child(2) { fill: #660000; }
circle:last-child { fill: #770000; }
@@ -35,13 +36,17 @@
<g id="inner">
<rect width="6" height="6" />
</g>
- <circle width="7" />
- <circle width="8" />
- <circle width="9" />
+ <circle width="100" />
+
+ <g id="circles">
+ <circle width="7" />
+ <circle width="8" />
+ <circle width="9" />
+ </g>
</g>
<square width="10" chocolate="hi there" />
<square width="11" abc="def" />
<square width="12" abc="ghidef" />
@@ -54,17 +59,39 @@
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)
- expect(width_and_styles).to eq [
+ expected = [
[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]]],
- [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#00ff00", false]]],
- [6, [["fill", "#ff0000", false], ["fill", "#0000ff", false]]],
+ ]
+
+ #
+ # Under ruby < 2.6, a bug in REXML causes the /following-sibling selector to
+ # only pick the first matching sibling. This means the + CSS combinator behaves
+ # incorrectly in the following example:
+ #
+ # <a>
+ # <b a="1" />
+ # <b a="2" />
+ # <b a="3" />
+ # </a>
+ #
+ # The css selector `a b + b` will only pick the second <b>, whereas it should
+ # pick both the second and third <b> elements.
+ #
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6.0')
+ expected << [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#00ff00", false]]]
+ else
+ expected << [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#440000", false], ["fill", "#00ff00", false]]]
+ end
+
+ expected.concat [
+ [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]]],
@@ -72,9 +99,11 @@
[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