test/test_format.rb in writeexcel-0.4.1 vs test/test_format.rb in writeexcel-0.4.2

- old
+ new

@@ -7,11 +7,11 @@ TEST_DIR = File.expand_path(File.dirname(__FILE__)) PERL_OUTDIR = File.join(TEST_DIR, 'perl_output') def setup @ruby_file = StringIO.new - @format = Format.new + @format = Writeexcel::Format.new end def teardown end @@ -20,22 +20,22 @@ def test_format_properties_with_valid_value # set_format_properties( propty => val ) valid_properties = get_valid_format_properties valid_properties.each do |k,v| - fmt = Format.new + fmt = Writeexcel::Format.new before = get_format_property(fmt) fmt.set_format_properties(k => v) after = get_format_property(fmt) after.delete_if {|key, val| before[key] == val } assert_equal(1, after.size, "change 1 property[:#{k}] but #{after.size} was changed.#{after.inspect}") assert_equal(v, after[k], "[:#{k}] doesn't match.") end # set_format_properties( propty_1 => val1, propty_2 => val2) valid_properties.each do |k,v| - fmt = Format.new + fmt = Writeexcel::Format.new before = get_format_property(fmt) fmt.set_format_properties(k => v, :bold => 1) after = get_format_property(fmt) after.delete_if {|key, val| before[key] == val } assert_equal(2, after.size, "change 1 property[:#{k}] but #{after.size} was changed.#{after.inspect}") @@ -45,11 +45,11 @@ # set_format_properties( hash_variable ) valid_properties = get_valid_format_properties valid_properties.each do |k,v| arg = {k => v} - fmt = Format.new + fmt = Writeexcel::Format.new before = get_format_property(fmt) fmt.set_format_properties(arg) after = get_format_property(fmt) after.delete_if {|key, val| before[key] == val } assert_equal(1, after.size, "change 1 property[:#{k}] but #{after.size} was changed.#{after.inspect}") @@ -59,11 +59,11 @@ # set_format_properties( hash_variable, hash_variable... ) valid_properties = get_valid_format_properties valid_properties.each do |k,v| arg = {k => v} arg2 = {:bold => 1} - fmt = Format.new + fmt = Writeexcel::Format.new before = get_format_property(fmt) fmt.set_format_properties(arg, arg2) after = get_format_property(fmt) after.delete_if {|key, val| before[key] == val } assert_equal(2, after.size, "change 1 property[:#{k}] but #{after.size} was changed.#{after.inspect}") @@ -73,11 +73,11 @@ # set_color by string valid_color_string_number = get_valid_color_string_number [:color , :bg_color, :fg_color].each do |coltype| valid_color_string_number.each do |str, num| - fmt = Format.new + fmt = Writeexcel::Format.new before = get_format_property(fmt) fmt.set_format_properties(coltype => str) after = get_format_property(fmt) after.delete_if {|key, val| before[key] == val } assert_equal(1, after.size, "change 1 property[:#{coltype}:#{str}] but #{after.size} was changed.#{after.inspect}") @@ -105,18 +105,18 @@ # default state assert_equal(10, @format.size) # valid size from low to high [1, 100, 100**10].each do |size| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_size(size) assert_equal(size, fmt.size, "valid size:#{size} - doesn't match.") end # invalid size -- size doesn't change [-1, 0, 1/2.0, 'hello', true, false, nil, [0,0], {:invalid => "val"}].each do |size| - fmt = Format.new + fmt = Writeexcel::Format.new default = fmt.size fmt.set_size(size) assert_equal(default, fmt.size, "size:#{size.inspect} doesn't match.") end end @@ -160,34 +160,34 @@ # valid color # set by string str_num = get_valid_color_string_number str_num.each do |str,num| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_color(str) assert_equal(num, fmt.color) end # valid color # set by number [8, 36, 63].each do |color| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_color(color) assert_equal(color, fmt.color) end # invalid color ['color', :col, -1, 63.5, 10*10].each do |color| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_color(color) assert_equal(default_col, fmt.color, "color : #{color}") end # invalid color ...but... # 0 <= color < 8 then color += 8 in order to valid value [0, 7.5].each do |color| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_color(color) assert_equal((color + 8).to_i, fmt.color, "color : #{color}") end @@ -212,22 +212,22 @@ def test_set_bold # default state assert_equal(400, @format.bold) # valid weight - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_bold assert_equal(700, fmt.bold) {0 => 400, 1 => 700, 100 => 100, 1000 => 1000}.each do |weight, value| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_bold(weight) assert_equal(value, fmt.bold) end # invalid weight [-1, 99, 1001, 'bold'].each do |weight| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_bold(weight) assert_equal(400, fmt.bold, "weight : #{weight}") end end @@ -245,24 +245,24 @@ def test_set_italic # default state assert_equal(0, @format.italic) # valid arg - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_italic assert_equal(1, fmt.italic) {0=>0, 1=>1}.each do |arg,value| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_italic(arg) assert_equal(value, fmt.italic, "arg : #{arg}") end # invalid arg [-1, 0.2, 100, 'italic', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_italic(#{arg}) : invalid arg. arg must be 0, 1 or none."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_italic(arg) } end end @@ -284,25 +284,25 @@ def test_set_underline # default state assert_equal(0, @format.underline, "default state") # valid args - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_underline assert_equal(1, fmt.underline, "No arg") [0, 1, 2, 33, 34].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_underline(arg) assert_equal(arg, fmt.underline, "arg : #{arg}") end # invalid args [-1, 0.2, 100, 'under', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_underline(#{arg}) : arg must be 0, 1 or none, 2, 33, 34."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_underline(arg) } end end @@ -318,25 +318,25 @@ def test_set_font_strikeout # default state assert_equal(0, @format.font_strikeout, "default state") # valid args - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_strikeout assert_equal(1, fmt.font_strikeout, "No arg") [0, 1].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_strikeout(arg) assert_equal(arg, fmt.font_strikeout, "arg : #{arg}") end # invalid args [-1, 0.2, 100, 'strikeout', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_font_strikeout(#{arg}) : arg must be 0, 1 or none."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_strikeout(arg) } end end @@ -354,25 +354,25 @@ def test_set_font_script # default state assert_equal(0, @format.font_script, "default state") # valid args - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_script assert_equal(1, fmt.font_script, "No arg") [0, 1, 2].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_script(arg) assert_equal(arg, fmt.font_script, "arg : #{arg}") end # invalid args [-1, 0.2, 100, 'script', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_font_script(#{arg}) : arg must be 0, 1 or none, or 2."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_script(arg) } end end @@ -389,25 +389,25 @@ def test_set_font_outline # default state assert_equal(0, @format.font_outline, "default state") # valid args - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_outline assert_equal(1, fmt.font_outline, "No arg") [0, 1].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_outline(arg) assert_equal(arg, fmt.font_outline, "arg : #{arg}") end # invalid args [-1, 0.2, 100, 'outline', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_font_outline(#{arg}) : arg must be 0, 1 or none."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_outline(arg) } end end @@ -423,25 +423,25 @@ def test_set_font_shadow # default state assert_equal(0, @format.font_shadow, "default state") # valid args - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_shadow assert_equal(1, fmt.font_shadow, "No arg") [0, 1].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_shadow(arg) assert_equal(arg, fmt.font_shadow, "arg : #{arg}") end # invalid args [-1, 0.2, 100, 'shadow', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_font_shadow(#{arg}) : arg must be 0, 1 or none."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_font_shadow(arg) } end end @@ -458,18 +458,18 @@ # default state assert_equal(0, @format.num_format) # Excel built in Format Index (0 .. 49) [0, 49].each do |n| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_num_format(n) assert_equal(n, fmt.num_format, "n: #{n}") end # Format string ["#,##0", "m/d/yy", "hh:mm:ss"].each do |string| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_num_format(string) assert_equal(string, fmt.num_format, "string: #{string}") end end @@ -507,25 +507,25 @@ def test_set_locked # default state assert_equal(1, @format.locked, "default state") # valid args - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_locked assert_equal(1, fmt.locked, "No arg") [0, 1].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_locked(arg) assert_equal(arg, fmt.locked, "arg : #{arg}") end # invalid args [-1, 0.2, 100, 'locked', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_font_shadow(#{arg}) : arg must be 0, 1 or none."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_locked(arg) } end end =begin @@ -556,25 +556,25 @@ def test_set_hidden # default state assert_equal(0, @format.hidden, "default state") # valid args - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_hidden assert_equal(1, fmt.hidden, "No arg") [0, 1].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_hidden(arg) assert_equal(arg, fmt.hidden, "arg : #{arg}") end # invalid args [-1, 0.2, 100, 'hidden', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_font_shadow(#{arg}) : arg must be 0, 1 or none."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_hidden(arg) } end end @@ -624,11 +624,11 @@ 'fill'=>4, 'justify'=>5, 'center_across'=>6, 'centre_across'=>6, 'merge'=>6, 'top'=>0, 'vcenter'=>1, 'vcentre'=>1, 'bottom'=>2, 'vjustify'=>3 } valid_args.each do |arg, value| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_align(arg) case arg when 'left', 'center', 'centre', 'right', 'fill', 'justify', 'center_across', 'centre_across', 'merge' assert_equal(value, fmt.text_h_align, "arg: #{arg}") @@ -637,11 +637,11 @@ end end # invalid arg [-1, 0, 1.5, nil, true, false, ['left','top'], {'top'=>0}].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new val = get_format_property(fmt) #print val.inspect #exit fmt.set_align(arg) assert_equal(val[:align], fmt.text_h_align, "arg: #{arg} - text_h_align changed.") @@ -695,25 +695,25 @@ def test_set_text_wrap # default state assert_equal(0, @format.text_wrap, "default state") # valid args - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_text_wrap assert_equal(1, fmt.text_wrap, "No arg") [0, 1].each do |arg| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_text_wrap(arg) assert_equal(arg, fmt.text_wrap, "arg : #{arg}") end # invalid args [-1, 0.2, 100, 'text_wrap', true, false, nil].each do |arg| assert_raise(ArgumentError, "set_text_wrap(#{arg}) : arg must be 0, 1 or none."){ - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_text_wrap(arg) } end end @@ -738,11 +738,11 @@ # default state assert(0, @format.rotation) # # valid args -90 <= angle <= 90, 270 angle can be float or double # [-90.0, 89, 0, 89, 90, 270].each do |angle| - # fmt = Format.new + # fmt = Writeexcel::Format.new # fmt.set_rotation(angle) # assert_equal(angle, fmt.rotation, "angle: #{angle}") # end end @@ -768,11 +768,11 @@ # default state assert_equal(0, @format.indent) # valid arg -- Positive integers [1, 10000000].each do |indent| - fmt = Format.new + fmt = Writeexcel::Format.new fmt.set_indent(indent) assert_equal(indent, fmt.indent, "indent: #{indent}") end # invalid arg @@ -1028,11 +1028,11 @@ assert_equal(contents, rcontents, "Contents not the same") end def test_initialize assert_nothing_raised { - Format.new( + Writeexcel::Format.new( :bold => true, :size => 10, :color => 'black', :fg_color => 43, :align => 'top', @@ -1073,11 +1073,11 @@ compare_file(perl_file, @ruby_file) end def test_copy - format1 = Format.new - format2 = Format.new + format1 = Writeexcel::Format.new + format2 = Writeexcel::Format.new format1.set_size(12) format2.copy(format1)