Sha256: 9b4790c649d7bcf045ad06efd9a3f1b6c8b19e0ac43debb2324d7bc5962dbf86

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

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

require 'test_helper'
require 'hexapdf/xref_section'

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

4 entries across 4 versions & 1 rubygems

Version Path
hexapdf-0.6.0 test/hexapdf/test_xref_section.rb
hexapdf-0.5.0 test/hexapdf/test_xref_section.rb
hexapdf-0.4.0 test/hexapdf/test_xref_section.rb
hexapdf-0.3.0 test/hexapdf/test_xref_section.rb