test/hexapdf/layout/test_text_box.rb in hexapdf-0.23.0 vs test/hexapdf/layout/test_text_box.rb in hexapdf-0.24.0

- old
+ new

@@ -10,18 +10,22 @@ @frame = HexaPDF::Layout::Frame.new(0, 0, 100, 100) @inline_box = HexaPDF::Layout::InlineBox.create(width: 10, height: 10) {} end def create_box(items, **kwargs) - HexaPDF::Layout::TextBox.new(items, **kwargs) + HexaPDF::Layout::TextBox.new(items: items, **kwargs) end describe "initialize" do it "takes the inline items to be layed out in the box" do box = create_box([], width: 100) assert_equal(100, box.width) end + + it "supports flowing text around other content" do + assert(create_box([]).supports_position_flow?) + end end describe "fit" do it "fits into a rectangular area" do box = create_box([@inline_box] * 5, style: {padding: 10}) @@ -102,12 +106,23 @@ box = create_box([@inline_box], height: 102) assert_equal([nil, box], box.split(100, 100, @frame)) end - it "splits the box if necessary" do + it "splits the box if necessary when using non-flowing text" do box = create_box([@inline_box] * 10) boxes = box.split(50, 10, @frame) + assert_equal(2, boxes.length) + assert_equal(box, boxes[0]) + refute(boxes[0].split_box?) + assert(boxes[1].split_box?) + assert_equal(5, boxes[1].instance_variable_get(:@items).length) + end + + it "splits the box if necessary when using flowing text that results in a wider box" do + @frame.remove_area(Geom2D::Polygon.new([[0, 100], [50, 100], [50, 10], [0, 10]])) + box = create_box([@inline_box] * 60, style: {position: :flow}) + boxes = box.split(50, 100, @frame) assert_equal(2, boxes.length) assert_equal(box, boxes[0]) assert_equal(5, boxes[1].instance_variable_get(:@items).length) end end