# -*- coding: utf-8 -*-
require 'helper'
require 'write_xlsx/workbook'
require 'write_xlsx/worksheet'
require 'stringio'
class TestWriteHeaderFooter < Test::Unit::TestCase
def setup
@workbook = WriteXLSX.new(StringIO.new)
@worksheet = @workbook.add_worksheet('')
end
def test_write_odd_header
@worksheet.set_header('Page &P of &N')
@worksheet.__send__('write_odd_header')
result = @worksheet.instance_variable_get(:@writer).string
expected = 'Page &P of &N'
assert_equal(expected, result)
end
def test_write_odd_footer
@worksheet.set_footer('&F')
@worksheet.__send__('write_odd_footer')
result = @worksheet.instance_variable_get(:@writer).string
expected = '&F'
assert_equal(expected, result)
end
def test_write_haeder_footer_only_header
@worksheet.set_header('Page &P of &N')
@worksheet.__send__('write_header_footer')
result = @worksheet.instance_variable_get(:@writer).string
expected = 'Page &P of &N'
assert_equal(expected, result)
end
def test_write_haeder_footer_only_footer
@worksheet.set_footer('&F')
@worksheet.__send__('write_header_footer')
result = @worksheet.instance_variable_get(:@writer).string
expected = '&F'
assert_equal(expected, result)
end
def test_write_haeder_footer_both_header_and_footer
@worksheet.set_header('Page &P of &N')
@worksheet.set_footer('&F')
@worksheet.__send__('write_header_footer')
result = @worksheet.instance_variable_get(:@writer).string
expected = 'Page &P of &N&F'
assert_equal(expected, result)
end
end