Sha256: 2f4f48a9350d0cb7adbf51bf6389dc77bee74fd4b6ee2c00e1d26a2f0caf0536

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# -*- encoding: utf-8 -*-

require 'test_helper'
require 'hexapdf/layout/inline_box'

describe HexaPDF::Layout::InlineBox do
  before do
    @box = HexaPDF::Layout::InlineBox.create(width: 10, height: 15, style: {margin: [15, 10]})
  end

  it "draws the wrapped box at the correct position" do
    canvas = Object.new
    block = ->(c, x, y) do
      assert_equal(canvas, c)
      assert_equal(10, x)
      assert_equal(15, y)
    end
    @box.box.stub(:draw, block) do
      @box.draw(canvas, 0, 0)
    end
  end

  it "returns true if the inline box is empty with no drawing operations" do
    assert(@box.empty?)
    refute(HexaPDF::Layout::InlineBox.create(width: 10, height: 15) {}.empty?)
  end

  describe "valign" do
    it "has a default value of :baseline" do
      assert_equal(:baseline, @box.valign)
    end

    it "can be changed on creation" do
      box = HexaPDF::Layout::InlineBox.create(width: 10, height: 15, valign: :test)
      assert_equal(:test, box.valign)
    end
  end

  it "returns the width including margins" do
    assert_equal(30, @box.width)
  end

  it "returns the height including margins" do
    assert_equal(45, @box.height)
  end

  it "returns 0 for x_min" do
    assert_equal(0, @box.x_min)
  end

  it "returns width for x_max" do
    assert_equal(@box.width, @box.x_max)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hexapdf-0.6.0 test/hexapdf/layout/test_inline_box.rb