Sha256: f9bbf066af5ea178639b0f66fff14a582613a930ad9caaa918df6b3079e88d60
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
# -*- encoding: utf-8 -*- require 'test_helper' require 'hexapdf/document' require 'hexapdf/task/dereference' describe HexaPDF::Task::Dereference do before do @doc = HexaPDF::Document.new(io: StringIO.new(MINIMAL_PDF)) end it "dereferences all references to objects" do obj = @doc.add(:test) len = @doc.add(5) str = @doc.add(@doc.wrap({Length: len}, stream: '')) @doc.trailer[:Test] = str pages = @doc.wrap(Type: :Pages) pages.add_page(@doc.wrap(Type: :Page)) @doc.trailer[:Test2] = pages @doc.trailer[:InvalidRef] = HexaPDF::Reference.new(5000, 2) checker = lambda do |val, done = {}| case val when Array then val.all? {|v| checker.call(v, done)} when Hash then val.all? {|_, v| checker.call(v, done)} when HexaPDF::Reference false when HexaPDF::Object if done.key?(val) true else done[val] = true checker.call(val.value, done) end else true end end refute(checker.call(@doc.trailer)) assert_equal([obj, len], @doc.task(:dereference)) assert(checker.call(@doc.trailer)) assert_equal([obj, len], @doc.task(:dereference)) assert(checker.call(@doc.trailer)) end it "dereferences only a single object" do assert(@doc.object(5).value[:Font][:F1].kind_of?(HexaPDF::Reference)) assert_nil(@doc.task(:dereference, object: @doc.object(5))) refute(@doc.object(5).value[:Font][:F1].kind_of?(HexaPDF::Reference)) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hexapdf-0.6.0 | test/hexapdf/task/test_dereference.rb |
hexapdf-0.5.0 | test/hexapdf/task/test_dereference.rb |