# -*- coding: utf-8 -*-
require 'helper'
require 'write_xlsx'
require 'stringio'
class TestWriteConditionalFormatting < Test::Unit::TestCase
def setup
@workbook = WriteXLSX.new(StringIO.new)
@worksheet = @workbook.add_worksheet('')
end
def test_conditional_formatting_01
format = Writexlsx::Format.new(Writexlsx::Formats.new)
@worksheet.conditional_formatting('A1',
:type => 'cell',
:format => format,
:criteria => 'greater than',
:value => 5
)
@worksheet.__send__('write_conditional_formats')
result = @worksheet.instance_variable_get(:@writer).string
expected = '5'
assert_equal(expected, result)
end
def test_conditional_formatting_02
format = Writexlsx::Format.new(Writexlsx::Formats.new)
@worksheet.conditional_formatting('A2',
:type => 'cell',
:format => format,
:criteria => 'less than',
:value => 30
)
@worksheet.__send__('write_conditional_formats')
result = @worksheet.instance_variable_get(:@writer).string
expected = '30'
assert_equal(expected, result)
end
def test_conditional_formatting_03
format = Writexlsx::Format.new(Writexlsx::Formats.new)
@worksheet.conditional_formatting('A3',
:type => 'cell',
:format => nil,
:criteria => '>=',
:value => 50
)
@worksheet.__send__('write_conditional_formats')
result = @worksheet.instance_variable_get(:@writer).string
expected = '50'
assert_equal(expected, result)
end
def test_conditional_formatting_04
format = Writexlsx::Format.new(Writexlsx::Formats.new)
@worksheet.conditional_formatting('A1',
:type => 'cell',
:format => format,
:criteria => 'between',
:minimum => 10,
:maximum => 20
)
@worksheet.__send__('write_conditional_formats')
result = @worksheet.instance_variable_get(:@writer).string
expected = '1020'
assert_equal(expected, result)
end
end