Sha256: a47ded8bf24e452c5cc2bc0ab307486fdd7b3ae45568b2a6eb6b66eafb9dec09

Contents?: true

Size: 1.41 KB

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
hexapdf-0.9.3 test/hexapdf/test_xref_section.rb
hexapdf-0.9.2 test/hexapdf/test_xref_section.rb
hexapdf-0.9.1 test/hexapdf/test_xref_section.rb
hexapdf-0.9.0 test/hexapdf/test_xref_section.rb
hexapdf-0.8.0 test/hexapdf/test_xref_section.rb
hexapdf-0.7.0 test/hexapdf/test_xref_section.rb