test/hexapdf/document/test_destinations.rb in hexapdf-0.26.2 vs test/hexapdf/document/test_destinations.rb in hexapdf-0.27.0
- old
+ new
@@ -27,10 +27,16 @@
assert(@klass.valid?([5, :FitH, 5]))
refute(@klass.valid?([5, :FitH, :other]))
end
end
+ it "accepts an array or a dictionary containing a /D entry as value" do
+ assert(destination([5, :Fit]).valid?)
+ assert(destination({D: [5, :Fit]}).valid?)
+ assert(destination(HexaPDF::Dictionary.new({D: [5, :Fit]})).valid?)
+ end
+
it "can be asked whether the referenced page is in a remote document" do
assert(destination([5, :Fit]).remote?)
refute(destination([HexaPDF::Dictionary.new({}), :Fit]).remote?)
end
@@ -40,10 +46,14 @@
it "can validate a destination" do
assert(destination([5, :Fit]).valid?)
end
+ it "returns the destination array" do
+ assert_equal([5, :Fit], destination([5, :Fit]).value)
+ end
+
describe "type :xyz" do
before do
@dest = destination([:page, :XYZ, :left, :top, :zoom])
end
@@ -392,9 +402,40 @@
it "deletes a named destination" do
@doc.destinations.add('abc', [:page, :Fit])
assert(@doc.destinations['abc'])
@doc.destinations.delete('abc')
refute(@doc.destinations['abc'])
+ end
+
+ describe "resolve" do
+ it "resolves the named destination" do
+ @doc.catalog.names.destinations.add_entry("arr", [@page, :Fit])
+ @doc.catalog.names.destinations.add_entry("dict", {D: [@page, :Fit]})
+ assert_equal([@page, :Fit], @doc.destinations.resolve("arr").value)
+ assert_equal([@page, :Fit], @doc.destinations.resolve("dict").value)
+ end
+
+ it "returns nil if the named destination is not found" do
+ assert_nil(@doc.destinations.resolve("arr"))
+ end
+
+ it "resolves the old-style named destination" do
+ @doc.catalog[:Dests] = {arr: [@page, :Fit]}
+ assert_equal([@page, :Fit], @doc.destinations.resolve(:arr).value)
+ end
+
+ it "returns nil if the old-style named destination is not found" do
+ assert_nil(@doc.destinations.resolve(:arr))
+ end
+
+ it "uses a PDFArray or array argument directly" do
+ assert_equal([@page, :Fit], @doc.destinations.resolve([@page, :Fit]).value)
+ assert_equal([@page, :Fit], @doc.destinations.resolve(HexaPDF::PDFArray.new([@page, :Fit])).value)
+ end
+
+ it "returns nil if the resolved destination is not valid" do
+ assert_nil(@doc.destinations.resolve([@page, :Fitd]))
+ end
end
describe "each" do
before do
3.times {|i| @doc.destinations.add("abc#{i}", [:page, :Fit]) }