require 'spec_helper'
describe Prawn::Svg::Parser do
describe "document width and height" do
it "handles the width and height being set as a %" do
svg = <<-SVG
SVG
document = Prawn::Svg::Document.new(svg, [2000, 2000], {})
Prawn::Svg::Parser.new(document).parse[-2][-1].should == [["line", [100.0, 900.0, 900.0, 100.0], []]]
end
it "handles the width and height being set in inches" do
svg = <<-SVG
SVG
document = Prawn::Svg::Document.new(svg, [2000, 2000], {})
Prawn::Svg::Parser.new(document).parse[-2][-1].should == [["line", [72.0, 720.0 - 72.0, 720.0 - 72.0, 72.0], []]]
end
end
describe :parse_element do
before(:each) do
@document = Prawn::Svg::Document.new("", [100, 100], {})
@parser = Prawn::Svg::Parser.new(@document)
end
def mock_element(name, attributes = {})
e = double(:name => name, :attributes => attributes)
Prawn::Svg::Element.new(@document, e, [], {})
end
it "ignores tags it doesn't know about" do
calls = []
@parser.send :parse_element, mock_element("unknown")
calls.should == []
@document.warnings.length.should == 1
@document.warnings.first.should include("Unknown tag")
end
it "ignores tags that don't have all required attributes set" do
calls = []
@parser.send :parse_element, mock_element("ellipse", "rx" => "1")
calls.should == []
@document.warnings.length.should == 1
@document.warnings.first.should include("Must have attributes ry on tag ellipse")
end
end
end