Sha256: f9bab06749be45240be64e3a3dfdabadadc37261e5c5144e79474ffd47b509de

Contents?: true

Size: 1.48 KB

Versions: 20

Compression:

Stored size: 1.48 KB

Contents

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

require 'test_helper'
require 'hexapdf/document'
require 'hexapdf/type/actions/set_ocg_state'

describe HexaPDF::Type::Actions::SetOCGState do
  before do
    @doc = HexaPDF::Document.new
    @action = HexaPDF::Type::Actions::SetOCGState.new({}, document: @doc)
    @ocg = @doc.optional_content.add_ocg('Test')
  end

  describe "add_state_change" do
    it "allows using Ruby-esque and PDF type names for the state change type" do
      @action.add_state_change(:on, @ocg)
      @action.add_state_change(:ON, @ocg)
      @action.add_state_change(:off, @ocg)
      @action.add_state_change(:OFF, @ocg)
      @action.add_state_change(:toggle, @ocg)
      @action.add_state_change(:Toggle, @ocg)
      assert_equal([:ON, @ocg, :ON, @ocg, :OFF, @ocg, :OFF, @ocg, :Toggle, @ocg, :Toggle, @ocg],
                   @action[:State].value)
    end

    it "allows specifying more than one OCG" do
      @action.add_state_change(:on, [@ocg, @doc.optional_content.add_ocg('Test2')])
      assert_equal([:ON, @ocg, @doc.optional_content.ocg('Test2')], @action[:State].value)
    end

    it "raises an error if the provide state change type is invalid" do
      assert_raises(ArgumentError) { @action.add_state_change(:unknown, nil) }
    end

    it "raises an error if an OCG specified via a string does not exist" do
      error = assert_raises(HexaPDF::Error) { @action.add_state_change(:on, "Unknown") }
      assert_match(/Invalid OCG.*Unknown.*specified/, error.message)
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
hexapdf-1.0.2 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-1.0.1 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-1.0.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.47.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.46.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.45.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.44.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.41.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.40.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.39.1 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.39.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.38.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.37.2 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.37.1 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.37.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.36.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.35.1 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.35.0 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.34.1 test/hexapdf/type/actions/test_set_ocg_state.rb
hexapdf-0.34.0 test/hexapdf/type/actions/test_set_ocg_state.rb