test/hexapdf/test_importer.rb in hexapdf-0.27.0 vs test/hexapdf/test_importer.rb in hexapdf-0.28.0
- old
+ new
@@ -29,16 +29,16 @@
others: [:symbol, 5, 5.5, nil, true, false]})
@obj[:MySelf] = @obj
@source.pages.add
@source.pages.root[:Rotate] = 90
@dest = HexaPDF::Document.new
- @importer = HexaPDF::Importer.for(source: @source, destination: @dest)
+ @importer = HexaPDF::Importer.for(@dest)
end
describe "::for" do
it "caches the importer" do
- assert_same(@importer, HexaPDF::Importer.for(source: @source, destination: @dest))
+ assert_same(@importer, HexaPDF::Importer.for(@dest))
end
end
describe "import" do
it "updates the associated document" do
@@ -59,14 +59,20 @@
@dest.delete(obj)
refute_same(obj, @importer.import(@obj))
end
it "can import a direct object" do
- obj = @importer.import(key: @obj)
- assert(@dest.object?(obj[:key]))
+ assert_nil(@importer.import(nil))
+ assert_equal(5, @importer.import(5))
+ assert(@dest.object?(@importer.import({key: @obj})[:key]))
end
+ it "determines the source document dynamically" do
+ obj = @importer.import(@obj.value)
+ assert_equal("test", obj[:ref].value)
+ end
+
it "copies the data of the imported objects" do
data = {key: @obj, str: "str"}
obj = @importer.import(data)
obj[:str].upcase!
obj[:key][:hash][:key].upcase!
@@ -118,12 +124,13 @@
it "imports Page objects correctly by copying the inherited values" do
page = @importer.import(@source.pages[0])
assert_equal(90, page[:Rotate])
end
- it "raise an error if the given object doesn't belong to the source document" do
+ it "works for importing objects from different documents" do
other_doc = HexaPDF::Document.new
other_obj = other_doc.add("test")
- assert_raises(HexaPDF::Error) { @importer.import(other_obj) }
+ imported = @importer.import(other_obj)
+ assert_equal("test", imported.value)
end
end
end