writeexcel 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
data/test/tc_workbook.rb
CHANGED
@@ -1,115 +1,140 @@
|
|
1
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require "writeexcel"
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "writeexcel"
|
5
|
+
require "stringio"
|
6
|
+
|
7
|
+
class TC_Workbook < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
t = Time.now.strftime("%Y%m%d")
|
11
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
12
|
+
@test_file = File.join(Dir.tmpdir, path)
|
13
|
+
@workbook = Workbook.new(@test_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
@workbook.close
|
18
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_new
|
22
|
+
assert_kind_of(Workbook, @workbook)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_add_worksheet
|
26
|
+
sheetnames = ['sheet1', 'sheet2']
|
27
|
+
(0 .. sheetnames.size-1).each do |i|
|
28
|
+
sheets = @workbook.sheets
|
29
|
+
assert_equal(i, sheets.size)
|
30
|
+
@workbook.add_worksheet(sheetnames[i])
|
31
|
+
sheets = @workbook.sheets
|
32
|
+
assert_equal(i+1, sheets.size)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_set_tempdir_after_sheet_added
|
37
|
+
# after shees added, call set_tempdir raise RuntimeError
|
38
|
+
@workbook.add_worksheet('name')
|
39
|
+
assert_raise(RuntimeError, "already sheet exists, but set_tempdir() doesn't raise"){
|
40
|
+
@workbook.set_tempdir
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_set_tempdir_with_invalid_dir
|
45
|
+
# invalid dir raise RuntimeError
|
46
|
+
while true do
|
47
|
+
dir = Time.now.to_s
|
48
|
+
break unless FileTest.directory?(dir)
|
49
|
+
sleep 0.1
|
50
|
+
end
|
51
|
+
assert_raise(RuntimeError, "set_tempdir() doesn't raise invalid dir:#{dir}."){
|
52
|
+
@workbook.set_tempdir(dir)
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
=begin
|
57
|
+
#
|
58
|
+
# Comment out because Workbook#check_sheetname was set to private method.
|
59
|
+
#
|
60
|
+
def test_check_sheetname
|
61
|
+
valids = valid_sheetname
|
62
|
+
invalids = invalid_sheetname
|
63
|
+
worksheet1 = @workbook.add_worksheet # implicit name 'Sheet1'
|
64
|
+
worksheet2 = @workbook.add_worksheet # implicit name 'Sheet2'
|
65
|
+
worksheet3 = @workbook.add_worksheet 'Sheet3' # implicit name 'Sheet3'
|
66
|
+
worksheet1 = @workbook.add_worksheet 'Sheetz' # implicit name 'Sheetz'
|
67
|
+
|
68
|
+
valids.each do |test|
|
69
|
+
target = test[0]
|
70
|
+
sheetname = test[1]
|
71
|
+
caption = test[2]
|
72
|
+
assert_nothing_raised { @workbook.check_sheetname(sheetname) }
|
73
|
+
end
|
74
|
+
invalids.each do |test|
|
75
|
+
target = test[0]
|
76
|
+
sheetname = test[1]
|
77
|
+
caption = test[2]
|
78
|
+
assert_raise(RuntimeError, "sheetname: #{sheetname}") {
|
79
|
+
@workbook.check_sheetname(sheetname)
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
=end
|
84
|
+
|
85
|
+
def test_raise_set_compatibility_after_sheet_creation
|
86
|
+
@workbook.add_worksheet
|
87
|
+
assert_raise(RuntimeError) { @workbook.compatibility_mode }
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_write_to_io
|
91
|
+
# write to @test_file
|
92
|
+
@workbook.add_worksheet
|
93
|
+
@workbook.close
|
94
|
+
file = ''
|
95
|
+
File.open(@test_file, "rb") do |f|
|
96
|
+
file = f.read
|
97
|
+
end
|
98
|
+
|
99
|
+
# write to io
|
100
|
+
io = StringIO.new
|
101
|
+
wb = Workbook.new(io)
|
102
|
+
wb.add_worksheet
|
103
|
+
wb.close
|
104
|
+
|
105
|
+
# compare @test_file and io
|
106
|
+
assert_equal(file, io.string)
|
107
|
+
end
|
108
|
+
|
109
|
+
def valid_sheetname
|
110
|
+
[
|
111
|
+
# Tests for valid names
|
112
|
+
[ 'PASS', nil, 'No worksheet name' ],
|
113
|
+
[ 'PASS', '', 'Blank worksheet name' ],
|
114
|
+
[ 'PASS', 'Sheet10', 'Valid worksheet name' ],
|
115
|
+
[ 'PASS', 'a' * 31, 'Valid 31 char name' ]
|
116
|
+
]
|
117
|
+
end
|
118
|
+
|
119
|
+
def invalid_sheetname
|
120
|
+
[
|
121
|
+
# Tests for invalid names
|
122
|
+
[ 'FAIL', 'Sheet1', 'Caught duplicate name' ],
|
123
|
+
[ 'FAIL', 'Sheet2', 'Caught duplicate name' ],
|
124
|
+
[ 'FAIL', 'Sheet3', 'Caught duplicate name' ],
|
125
|
+
[ 'FAIL', 'sheet1', 'Caught case-insensitive name'],
|
126
|
+
[ 'FAIL', 'SHEET1', 'Caught case-insensitive name'],
|
127
|
+
[ 'FAIL', 'sheetz', 'Caught case-insensitive name'],
|
128
|
+
[ 'FAIL', 'SHEETZ', 'Caught case-insensitive name'],
|
129
|
+
[ 'FAIL', 'a' * 32, 'Caught long name' ],
|
130
|
+
[ 'FAIL', '[', 'Caught invalid char' ],
|
131
|
+
[ 'FAIL', ']', 'Caught invalid char' ],
|
132
|
+
[ 'FAIL', ':', 'Caught invalid char' ],
|
133
|
+
[ 'FAIL', '*', 'Caught invalid char' ],
|
134
|
+
[ 'FAIL', '?', 'Caught invalid char' ],
|
135
|
+
[ 'FAIL', '/', 'Caught invalid char' ],
|
136
|
+
[ 'FAIL', '\\', 'Caught invalid char' ]
|
137
|
+
]
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
data/test/tc_worksheet.rb
CHANGED
@@ -1,115 +1,115 @@
|
|
1
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require "writeexcel"
|
5
|
-
|
6
|
-
class TC_Worksheet < Test::Unit::TestCase
|
7
|
-
TEST_DIR = File.expand_path(File.dirname(__FILE__))
|
8
|
-
PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
|
9
|
-
|
10
|
-
def setup
|
11
|
-
t = Time.now.strftime("%Y%m%d")
|
12
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
13
|
-
@test_file = File.join(Dir.tmpdir, path)
|
14
|
-
@workbook =
|
15
|
-
@sheetname = 'test'
|
16
|
-
@ws = @workbook.add_worksheet(@sheetname,0)
|
17
|
-
@perldir = "#{PERL_OUTDIR}/"
|
18
|
-
@format = Format.new(:color=>"green")
|
19
|
-
end
|
20
|
-
|
21
|
-
def teardown
|
22
|
-
@ws = nil
|
23
|
-
@format = nil
|
24
|
-
@workbook.close
|
25
|
-
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_methods_exist
|
29
|
-
assert_respond_to(@ws, :write)
|
30
|
-
assert_respond_to(@ws, :write_blank)
|
31
|
-
assert_respond_to(@ws, :write_row)
|
32
|
-
assert_respond_to(@ws, :write_col)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_methods_no_error
|
36
|
-
assert_nothing_raised{ @ws.write(0,0,nil) }
|
37
|
-
assert_nothing_raised{ @ws.write(0,0,"Hello") }
|
38
|
-
assert_nothing_raised{ @ws.write(0,0,888) }
|
39
|
-
assert_nothing_raised{ @ws.write_row(0,0,["one","two","three"]) }
|
40
|
-
assert_nothing_raised{ @ws.write_row(0,0,[1,2,3]) }
|
41
|
-
assert_nothing_raised{ @ws.write_col(0,0,["one","two","three"]) }
|
42
|
-
assert_nothing_raised{ @ws.write_col(0,0,[1,2,3]) }
|
43
|
-
assert_nothing_raised{ @ws.write_blank(0,0,nil) }
|
44
|
-
assert_nothing_raised{ @ws.write_url(0,0,"http://www.ruby-lang.org") }
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_write_syntax
|
48
|
-
assert_nothing_raised{@ws.write(0,0,"Hello")}
|
49
|
-
assert_nothing_raised{@ws.write(0,0,666)}
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_store_dimensions
|
53
|
-
file = "delete_this"
|
54
|
-
File.open(file,"w+"){ |f| f.print @ws.store_dimensions }
|
55
|
-
pf = @perldir + "ws_store_dimensions"
|
56
|
-
p_od = IO.readlines(pf).to_s.dump
|
57
|
-
r_od = IO.readlines(file).to_s.dump
|
58
|
-
assert_equal_filesize(pf ,file, "Invalid size for store_selection")
|
59
|
-
assert_equal(p_od, r_od,"Octal dumps are not identical")
|
60
|
-
File.delete(file)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_store_colinfo
|
64
|
-
file = "delete_this"
|
65
|
-
File.open(file,"w+"){ |f| f.print @ws.store_colinfo }
|
66
|
-
pf = @perldir + "ws_store_colinfo"
|
67
|
-
p_od = IO.readlines(pf).to_s.dump
|
68
|
-
r_od = IO.readlines(file).to_s.dump
|
69
|
-
assert_equal_filesize(pf, file, "Invalid size for store_colinfo")
|
70
|
-
assert_equal(p_od,r_od,"Perl and Ruby octal dumps don't match")
|
71
|
-
File.delete(file)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_store_selection
|
75
|
-
file = "delete_this"
|
76
|
-
File.open(file,"w+"){ |f| f.print @ws.store_selection(1,1,2,2) }
|
77
|
-
pf = @perldir + "ws_store_selection"
|
78
|
-
p_od = IO.readlines(pf).to_s.dump
|
79
|
-
r_od = IO.readlines(file).to_s.dump
|
80
|
-
assert_equal_filesize(pf, file, "Invalid size for store_selection")
|
81
|
-
assert_equal(p_od, r_od,"Octal dumps are not identical")
|
82
|
-
File.delete(file)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_store_filtermode
|
86
|
-
file = "delete_this"
|
87
|
-
File.open(file,"w+"){ |f| f.print @ws.store_filtermode }
|
88
|
-
pf = @perldir + "ws_store_filtermode_off"
|
89
|
-
p_od = IO.readlines(pf).to_s.dump
|
90
|
-
r_od = IO.readlines(file).to_s.dump
|
91
|
-
assert_equal_filesize(pf, file, "Invalid size for store_filtermode_off")
|
92
|
-
assert_equal(p_od, r_od,"Octal dumps are not identical")
|
93
|
-
File.delete(file)
|
94
|
-
|
95
|
-
@ws.autofilter(1,1,2,2)
|
96
|
-
@ws.filter_column(1, 'x < 2000')
|
97
|
-
File.open(file,"w+"){ |f| f.print @ws.store_filtermode }
|
98
|
-
pf = @perldir + "ws_store_filtermode_on"
|
99
|
-
p_od = IO.readlines(pf).to_s.dump
|
100
|
-
r_od = IO.readlines(file).to_s.dump
|
101
|
-
assert_equal_filesize(pf, file, "Invalid size for store_filtermode_off")
|
102
|
-
assert_equal(p_od, r_od,"Octal dumps are not identical")
|
103
|
-
File.delete(file)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_new
|
107
|
-
assert_equal(@sheetname, @ws.name)
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
def assert_equal_filesize(target, test, msg = "Bad file size")
|
112
|
-
assert_equal(File.size(target),File.size(test),msg)
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "writeexcel"
|
5
|
+
|
6
|
+
class TC_Worksheet < Test::Unit::TestCase
|
7
|
+
TEST_DIR = File.expand_path(File.dirname(__FILE__))
|
8
|
+
PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
|
9
|
+
|
10
|
+
def setup
|
11
|
+
t = Time.now.strftime("%Y%m%d")
|
12
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
13
|
+
@test_file = File.join(Dir.tmpdir, path)
|
14
|
+
@workbook = WriteExcel.new(@test_file)
|
15
|
+
@sheetname = 'test'
|
16
|
+
@ws = @workbook.add_worksheet(@sheetname,0)
|
17
|
+
@perldir = "#{PERL_OUTDIR}/"
|
18
|
+
@format = Format.new(:color=>"green")
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
@ws = nil
|
23
|
+
@format = nil
|
24
|
+
@workbook.close
|
25
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_methods_exist
|
29
|
+
assert_respond_to(@ws, :write)
|
30
|
+
assert_respond_to(@ws, :write_blank)
|
31
|
+
assert_respond_to(@ws, :write_row)
|
32
|
+
assert_respond_to(@ws, :write_col)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_methods_no_error
|
36
|
+
assert_nothing_raised{ @ws.write(0,0,nil) }
|
37
|
+
assert_nothing_raised{ @ws.write(0,0,"Hello") }
|
38
|
+
assert_nothing_raised{ @ws.write(0,0,888) }
|
39
|
+
assert_nothing_raised{ @ws.write_row(0,0,["one","two","three"]) }
|
40
|
+
assert_nothing_raised{ @ws.write_row(0,0,[1,2,3]) }
|
41
|
+
assert_nothing_raised{ @ws.write_col(0,0,["one","two","three"]) }
|
42
|
+
assert_nothing_raised{ @ws.write_col(0,0,[1,2,3]) }
|
43
|
+
assert_nothing_raised{ @ws.write_blank(0,0,nil) }
|
44
|
+
assert_nothing_raised{ @ws.write_url(0,0,"http://www.ruby-lang.org") }
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_write_syntax
|
48
|
+
assert_nothing_raised{@ws.write(0,0,"Hello")}
|
49
|
+
assert_nothing_raised{@ws.write(0,0,666)}
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_store_dimensions
|
53
|
+
file = "delete_this"
|
54
|
+
File.open(file,"w+"){ |f| f.print @ws.store_dimensions }
|
55
|
+
pf = @perldir + "ws_store_dimensions"
|
56
|
+
p_od = IO.readlines(pf).to_s.dump
|
57
|
+
r_od = IO.readlines(file).to_s.dump
|
58
|
+
assert_equal_filesize(pf ,file, "Invalid size for store_selection")
|
59
|
+
assert_equal(p_od, r_od,"Octal dumps are not identical")
|
60
|
+
File.delete(file)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_store_colinfo
|
64
|
+
file = "delete_this"
|
65
|
+
File.open(file,"w+"){ |f| f.print @ws.store_colinfo }
|
66
|
+
pf = @perldir + "ws_store_colinfo"
|
67
|
+
p_od = IO.readlines(pf).to_s.dump
|
68
|
+
r_od = IO.readlines(file).to_s.dump
|
69
|
+
assert_equal_filesize(pf, file, "Invalid size for store_colinfo")
|
70
|
+
assert_equal(p_od,r_od,"Perl and Ruby octal dumps don't match")
|
71
|
+
File.delete(file)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_store_selection
|
75
|
+
file = "delete_this"
|
76
|
+
File.open(file,"w+"){ |f| f.print @ws.store_selection(1,1,2,2) }
|
77
|
+
pf = @perldir + "ws_store_selection"
|
78
|
+
p_od = IO.readlines(pf).to_s.dump
|
79
|
+
r_od = IO.readlines(file).to_s.dump
|
80
|
+
assert_equal_filesize(pf, file, "Invalid size for store_selection")
|
81
|
+
assert_equal(p_od, r_od,"Octal dumps are not identical")
|
82
|
+
File.delete(file)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_store_filtermode
|
86
|
+
file = "delete_this"
|
87
|
+
File.open(file,"w+"){ |f| f.print @ws.store_filtermode }
|
88
|
+
pf = @perldir + "ws_store_filtermode_off"
|
89
|
+
p_od = IO.readlines(pf).to_s.dump
|
90
|
+
r_od = IO.readlines(file).to_s.dump
|
91
|
+
assert_equal_filesize(pf, file, "Invalid size for store_filtermode_off")
|
92
|
+
assert_equal(p_od, r_od,"Octal dumps are not identical")
|
93
|
+
File.delete(file)
|
94
|
+
|
95
|
+
@ws.autofilter(1,1,2,2)
|
96
|
+
@ws.filter_column(1, 'x < 2000')
|
97
|
+
File.open(file,"w+"){ |f| f.print @ws.store_filtermode }
|
98
|
+
pf = @perldir + "ws_store_filtermode_on"
|
99
|
+
p_od = IO.readlines(pf).to_s.dump
|
100
|
+
r_od = IO.readlines(file).to_s.dump
|
101
|
+
assert_equal_filesize(pf, file, "Invalid size for store_filtermode_off")
|
102
|
+
assert_equal(p_od, r_od,"Octal dumps are not identical")
|
103
|
+
File.delete(file)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_new
|
107
|
+
assert_equal(@sheetname, @ws.name)
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def assert_equal_filesize(target, test, msg = "Bad file size")
|
112
|
+
assert_equal(File.size(target),File.size(test),msg)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|