Sha256: 106cdc2203c9a2ec38e57a4c7d4fb3d43831089961cdfdc95784e32b2005e453

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

# coding: utf-8

require 'test_helper'

class Thinreports::Core::Shape::PageNumber::TestInternal < Minitest::Test
  include Thinreports::TestHelper

  PageNumber = Thinreports::Core::Shape::PageNumber

  def setup
    @report = new_report('layout_text1.tlf')
    @report.start_new_page
  end

  def init_pageno(format = {})
    PageNumber::Internal.new(@report.page, PageNumber::Format.new(format))
  end

  def test_read_format
    pageno = init_pageno('format' => 'Page {page}')

    assert_equal pageno.read_format, 'Page {page}'
  end

  def test_write_format
    pageno = init_pageno('format' => 'Page {page}')
    pageno.write_format('{page}')

    assert_equal pageno.read_format, '{page}'
  end

  def test_reset_format
    pageno = init_pageno('format' => '{page}')
    pageno.write_format('Page {page}')
    pageno.reset_format

    assert_equal pageno.read_format, '{page}'
  end

  def test_build_format
    pageno = init_pageno('format' => '{page} / {total}')
    assert_equal pageno.build_format(1, 100), '1 / 100'

    pageno.write_format('{page}')
    assert_equal pageno.build_format(1, 100), '1'

    @report.start_page_number_from 5
    pageno = init_pageno('format' => '{page} / {total}')
    assert_equal pageno.build_format(1, 100), '5 / 104'

    # if counted target is a List shape
    pageno = init_pageno('format' => '{page} / {total}',
                         'target' => 'list-id')
    assert_equal pageno.build_format(1, 100), '1 / 100'
  end

  def test_type_of
    pageno = init_pageno
    assert pageno.type_of?(:pageno)
  end

  def test_style
    pageno = init_pageno
    style = pageno.style

    assert_instance_of PageNumber::Style, style
    assert_same pageno.style, style
  end

  def test_for_report
    pageno = init_pageno('target' => '')
    assert_equal pageno.for_report?, true

    pageno = init_pageno('target' => 'list-id')
    assert_equal pageno.for_report?, false
  end

  def test_Style_class
    refute_includes PageNumber::Style.accessible_styles, :valign
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thinreports-0.8.2 test/unit/core/shape/page_number/test_internal.rb
thinreports-0.8.1 test/unit/core/shape/page_number/test_internal.rb
thinreports-0.8.0 test/unit/core/shape/page_number/test_internal.rb