Sha256: ba5433ef95fb26d90a8369409e9b47eb428524fe4fcba301c8cae7014198d80b

Contents?: true

Size: 1.49 KB

Versions: 83

Compression:

Stored size: 1.49 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

83 entries across 83 versions & 1 rubygems

Version Path
hexapdf-0.15.2 test/hexapdf/task/test_dereference.rb
hexapdf-0.15.1 test/hexapdf/task/test_dereference.rb
hexapdf-0.15.0 test/hexapdf/task/test_dereference.rb
hexapdf-0.14.4 test/hexapdf/task/test_dereference.rb
hexapdf-0.14.3 test/hexapdf/task/test_dereference.rb
hexapdf-0.14.2 test/hexapdf/task/test_dereference.rb
hexapdf-0.14.1 test/hexapdf/task/test_dereference.rb
hexapdf-0.14.0 test/hexapdf/task/test_dereference.rb
hexapdf-0.13.0 test/hexapdf/task/test_dereference.rb
hexapdf-0.12.3 test/hexapdf/task/test_dereference.rb
hexapdf-0.12.2 test/hexapdf/task/test_dereference.rb
hexapdf-0.12.1 test/hexapdf/task/test_dereference.rb
hexapdf-0.12.0 test/hexapdf/task/test_dereference.rb
hexapdf-0.11.9 test/hexapdf/task/test_dereference.rb
hexapdf-0.11.8 test/hexapdf/task/test_dereference.rb
hexapdf-0.11.7 test/hexapdf/task/test_dereference.rb
hexapdf-0.11.6 test/hexapdf/task/test_dereference.rb
hexapdf-0.11.5 test/hexapdf/task/test_dereference.rb
hexapdf-0.11.4 test/hexapdf/task/test_dereference.rb
hexapdf-0.11.3 test/hexapdf/task/test_dereference.rb