# -*- coding: utf-8 -*- require 'helper' require 'write_xlsx' require 'stringio' class TestCondFormat08 < Minitest::Test def setup @workbook = WriteXLSX.new(StringIO.new) @worksheet = @workbook.add_worksheet('') end ############################################################################### # # Test the _assemble_xml_file() method. # # Test conditional formats. # def test_conditional_formats @worksheet.select # Start test code. @worksheet.write('A1', 10) @worksheet.write('A2', 20) @worksheet.write('A3', 30) @worksheet.write('A4', 40) [ 'yesterday', 'today', 'tomorrow', 'last 7 days', 'last week', 'this week', 'next week', 'last month', 'this month', 'next month' ].each do |criteria| @worksheet.conditional_formatting('A1:A4', { :type => 'time_period', :criteria => criteria, :format => nil } ) end @worksheet.assemble_xml_file result = got_to_array(@worksheet.instance_variable_get(:@writer).string) expected = expected_to_array(expected_xml) assert_equal(expected, result) end def expected_xml < 10 20 30 40 FLOOR(A1,1)=TODAY()-1 FLOOR(A1,1)=TODAY() FLOOR(A1,1)=TODAY()+1 AND(TODAY()-FLOOR(A1,1)<=6,FLOOR(A1,1)<=TODAY()) AND(TODAY()-ROUNDDOWN(A1,0)>=(WEEKDAY(TODAY())),TODAY()-ROUNDDOWN(A1,0)<(WEEKDAY(TODAY())+7)) AND(TODAY()-ROUNDDOWN(A1,0)<=WEEKDAY(TODAY())-1,ROUNDDOWN(A1,0)-TODAY()<=7-WEEKDAY(TODAY())) AND(ROUNDDOWN(A1,0)-TODAY()>(7-WEEKDAY(TODAY())),ROUNDDOWN(A1,0)-TODAY()<(15-WEEKDAY(TODAY()))) AND(MONTH(A1)=MONTH(TODAY())-1,OR(YEAR(A1)=YEAR(TODAY()),AND(MONTH(A1)=1,YEAR(A1)=YEAR(TODAY())-1))) AND(MONTH(A1)=MONTH(TODAY()),YEAR(A1)=YEAR(TODAY())) AND(MONTH(A1)=MONTH(TODAY())+1,OR(YEAR(A1)=YEAR(TODAY()),AND(MONTH(A1)=12,YEAR(A1)=YEAR(TODAY())+1))) EOS end end