test/hexapdf/content/test_canvas.rb in hexapdf-0.4.0 vs test/hexapdf/content/test_canvas.rb in hexapdf-0.5.0

- old
+ new

@@ -7,26 +7,16 @@ require 'hexapdf/content/processor' require 'hexapdf/content/parser' describe HexaPDF::Content::Canvas do before do - @processor = TestHelper::OperatorRecorder.new - @parser = HexaPDF::Content::Parser.new - @doc = HexaPDF::Document.new @doc.config['graphic_object.arc.max_curves'] = 4 @page = @doc.pages.add @canvas = @page.canvas end - # Asserts that the content string contains the operators. - def assert_operators(content, operators) - @processor.recorded_ops.clear - @parser.parse(content, @processor) - assert_equal(operators, @processor.recorded_ops) - end - # Asserts that a specific operator is invoked when the block is executed. def assert_operator_invoked(op, *args) mock = Minitest::Mock.new if args.empty? mock.expect(:invoke, nil) { true } @@ -636,14 +626,13 @@ end end it "serializes correctly" do @canvas.circle(0, 0, 1) - @processor.recorded_ops.clear - @parser.parse(@canvas.contents, @processor) - assert_equal([:move_to, :curve_to, :curve_to, :curve_to, :curve_to, :close_subpath], - @processor.recorded_ops.map(&:first)) + assert_operators(@canvas.contents, + [:move_to, :curve_to, :curve_to, :curve_to, :curve_to, :close_subpath], + only_names: true) end it "returns the canvas object" do assert_equal(@canvas, @canvas.circle(1, 2, 3)) end @@ -656,14 +645,13 @@ end end it "serializes correctly" do @canvas.ellipse(0, 0, a: 10, b: 5, inclination: 10) - @processor.recorded_ops.clear - @parser.parse(@canvas.contents, @processor) - assert_equal([:move_to, :curve_to, :curve_to, :curve_to, :curve_to, :close_subpath], - @processor.recorded_ops.map(&:first)) + assert_operators(@canvas.contents, + [:move_to, :curve_to, :curve_to, :curve_to, :curve_to, :close_subpath], + only_names: true) end it "returns the canvas object" do assert_equal(@canvas, @canvas.circle(1, 2, 3)) end @@ -914,12 +902,11 @@ it "serializes correctly" do @canvas.begin_text @canvas.begin_text @canvas.begin_text(force_new: true) - @parser.parse(@canvas.contents, @processor) - assert_equal([:begin_text, :end_text, :begin_text], @processor.recorded_ops.map(&:first)) + assert_operators(@canvas.contents, [:begin_text, :end_text, :begin_text], only_names: true) end it "returns the canvas object" do assert_equal(@canvas, @canvas.begin_text) end @@ -945,12 +932,11 @@ it "serializes correctly" do @canvas.end_text @canvas.begin_text @canvas.end_text @canvas.end_text - @parser.parse(@page.contents, @processor) - assert_equal([:begin_text, :end_text], @processor.recorded_ops.map(&:first)) + assert_operators(@page.contents, [:begin_text, :end_text], only_names: true) end it "returns the canvas object" do assert_equal(@canvas, @canvas.begin_text) end @@ -1011,9 +997,11 @@ describe "font" do it "returns the set font" do assert_nil(@canvas.font) @canvas.font("Times", size: 10) + assert_same(@doc.fonts.load("Times"), @canvas.font) + @canvas.font(@canvas.font) assert_same(@doc.fonts.load("Times"), @canvas.font) @canvas.font("Helvetica", size: 10) assert_operators(@canvas.contents, [[:set_font_and_size, [:F1, 10]], [:set_leading, [12.0]], [:set_font_and_size, [:F2, 10]]])