Sha256: 5cd7037f50cc878f443de2d8e21684abda7e773a33657fb15750f5ed20d6923e

Contents?: true

Size: 1.83 KB

Versions: 82

Compression:

Stored size: 1.83 KB

Contents

# -*- encoding: utf-8 -*-

require 'test_helper'
require 'hexapdf/xref_section'

describe HexaPDF::XRefSection::Entry do
  it "can describe itself" do
    free = HexaPDF::XRefSection::Entry.new(:free, 1, 2)
    normal = HexaPDF::XRefSection::Entry.new(:in_use, 1, 2, 10)
    compressed = HexaPDF::XRefSection::Entry.new(:compressed, 1, 0, 2, 10)
    assert_match(/1,2 type=free/, free.to_s)
    assert_match(/1,2 type=normal/, normal.to_s)
    assert_match(/1,0 type=compressed/, compressed.to_s)
  end
end

describe HexaPDF::XRefSection do
  before do
    @xref_section = HexaPDF::XRefSection.new
  end

  describe "merge" do
    it "adds all entries from the other xref section, potentially overwriting entries" do
      @xref_section.add_in_use_entry(1, 0, 1)
      xref = HexaPDF::XRefSection.new
      xref.add_in_use_entry(1, 0, 2)
      xref.add_in_use_entry(2, 0, 2)
      assert_equal(1, @xref_section[1, 0].pos)
      assert_nil(@xref_section[2, 0])

      @xref_section.merge!(xref)
      assert_equal(2, @xref_section[1, 0].pos)
      assert_equal(2, @xref_section[2, 0].pos)
    end
  end

  describe "each_subsection" do
    def assert_subsections(result)
      assert_equal(result, @xref_section.each_subsection.map {|s| s.map(&:oid) })
    end

    it "works for newly initialized objects" do
      assert_subsections([[]])
    end

    it "works for a single subsection" do
      @xref_section.add_in_use_entry(1, 0, 0)
      @xref_section.add_in_use_entry(2, 0, 0)
      assert_subsections([[1, 2]])
    end

    it "works for multiple subsections" do
      @xref_section.add_in_use_entry(10, 0, 0)
      @xref_section.add_in_use_entry(11, 0, 0)
      @xref_section.add_in_use_entry(1, 0, 0)
      @xref_section.add_in_use_entry(2, 0, 0)
      @xref_section.add_in_use_entry(20, 0, 0)
      assert_subsections([[1, 2], [10, 11], [20]])
    end
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
hexapdf-1.0.0 test/hexapdf/test_xref_section.rb
hexapdf-0.47.0 test/hexapdf/test_xref_section.rb
hexapdf-0.46.0 test/hexapdf/test_xref_section.rb
hexapdf-0.45.0 test/hexapdf/test_xref_section.rb
hexapdf-0.44.0 test/hexapdf/test_xref_section.rb
hexapdf-0.41.0 test/hexapdf/test_xref_section.rb
hexapdf-0.40.0 test/hexapdf/test_xref_section.rb
hexapdf-0.39.1 test/hexapdf/test_xref_section.rb
hexapdf-0.39.0 test/hexapdf/test_xref_section.rb
hexapdf-0.38.0 test/hexapdf/test_xref_section.rb
hexapdf-0.37.2 test/hexapdf/test_xref_section.rb
hexapdf-0.37.1 test/hexapdf/test_xref_section.rb
hexapdf-0.37.0 test/hexapdf/test_xref_section.rb
hexapdf-0.36.0 test/hexapdf/test_xref_section.rb
hexapdf-0.35.1 test/hexapdf/test_xref_section.rb
hexapdf-0.35.0 test/hexapdf/test_xref_section.rb
hexapdf-0.34.1 test/hexapdf/test_xref_section.rb
hexapdf-0.34.0 test/hexapdf/test_xref_section.rb
hexapdf-0.33.0 test/hexapdf/test_xref_section.rb
hexapdf-0.32.2 test/hexapdf/test_xref_section.rb