test/hexapdf/layout/test_style.rb in hexapdf-0.26.1 vs test/hexapdf/layout/test_style.rb in hexapdf-0.26.2
- old
+ new
@@ -446,16 +446,20 @@
end
describe HexaPDF::Layout::Style::Layers do
before do
@layers = HexaPDF::Layout::Style::Layers.new
+ value = Object.new
+ value.define_singleton_method(:new) {|*| :new }
+ @config = Object.new
+ @config.define_singleton_method(:constantize) {|*| value }
end
it "can be initialized with an array of layers" do
- data = [lambda {}]
+ data = [lambda {}, [:test]]
layers = HexaPDF::Layout::Style::Layers.new(data)
- assert_equal(data, layers.enum_for(:each, {}).to_a)
+ assert_equal([data[0], :new], layers.enum_for(:each, @config).to_a)
end
it "can be duplicated" do
copy = @layers.dup
@layers.add(lambda {})
@@ -467,17 +471,19 @@
block = proc { true }
@layers.add(&block)
assert_equal([block], @layers.enum_for(:each, {}).to_a)
end
+ it "can use a given proc" do
+ block = proc { true }
+ @layers.add(block)
+ assert_equal([block], @layers.enum_for(:each, {}).to_a)
+ end
+
it "can store a reference" do
@layers.add(:link, option: :value)
- value = Object.new
- value.define_singleton_method(:new) {|*| :new }
- config = Object.new
- config.define_singleton_method(:constantize) {|*| value }
- assert_equal([:new], @layers.enum_for(:each, config).to_a)
+ assert_equal([:new], @layers.enum_for(:each, @config).to_a)
end
it "fails if neither a block nor a name is given when adding a layer" do
assert_raises(ArgumentError) { @layers.add }
end
@@ -587,9 +593,16 @@
it "works for files" do
annot = call_link(file: "local-file.pdf")
assert_equal({S: :Launch, F: "local-file.pdf", NewWindow: true}, annot[:A].value)
assert_nil(annot[:Dest])
+ end
+
+ it "works for destinations set via the 'link' custom box property" do
+ @box.properties['link'] = [@canvas.context, :FitH]
+ annot = call_link({})
+ assert_equal([@canvas.context, :FitH], annot[:Dest].value)
+ assert_nil(annot[:A])
end
end
end
describe HexaPDF::Layout::Style do