WriteExcel 0.2.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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/examples/a_simple.rb +42 -0
- data/examples/autofilters.rb +266 -0
- data/examples/bigfile.rb +30 -0
- data/examples/copyformat.rb +51 -0
- data/examples/data_validate.rb +278 -0
- data/examples/date_time.rb +86 -0
- data/examples/demo.rb +118 -0
- data/examples/diag_border.rb +35 -0
- data/examples/formats.rb +489 -0
- data/examples/header.rb +136 -0
- data/examples/hidden.rb +28 -0
- data/examples/hyperlink.rb +42 -0
- data/examples/images.rb +52 -0
- data/examples/merge1.rb +39 -0
- data/examples/merge2.rb +44 -0
- data/examples/merge3.rb +65 -0
- data/examples/merge4.rb +82 -0
- data/examples/merge5.rb +79 -0
- data/examples/protection.rb +46 -0
- data/examples/regions.rb +52 -0
- data/examples/repeat.rb +42 -0
- data/examples/stats.rb +75 -0
- data/examples/stocks.rb +80 -0
- data/examples/tab_colors.rb +30 -0
- data/lib/WriteExcel.rb +30 -0
- data/lib/WriteExcel/biffwriter.rb +259 -0
- data/lib/WriteExcel/chart.rb +217 -0
- data/lib/WriteExcel/excelformula.y +138 -0
- data/lib/WriteExcel/excelformulaparser.rb +573 -0
- data/lib/WriteExcel/format.rb +1108 -0
- data/lib/WriteExcel/formula.rb +986 -0
- data/lib/WriteExcel/olewriter.rb +322 -0
- data/lib/WriteExcel/properties.rb +250 -0
- data/lib/WriteExcel/storage_lite.rb +590 -0
- data/lib/WriteExcel/workbook.rb +2602 -0
- data/lib/WriteExcel/worksheet.rb +6378 -0
- data/spec/WriteExcel_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/test/tc_all.rb +31 -0
- data/test/tc_biff.rb +104 -0
- data/test/tc_chart.rb +22 -0
- data/test/tc_example_match.rb +1280 -0
- data/test/tc_format.rb +1264 -0
- data/test/tc_formula.rb +63 -0
- data/test/tc_ole.rb +110 -0
- data/test/tc_storage_lite.rb +102 -0
- data/test/tc_workbook.rb +115 -0
- data/test/tc_worksheet.rb +115 -0
- data/test/test_00_IEEE_double.rb +14 -0
- data/test/test_01_add_worksheet.rb +12 -0
- data/test/test_02_merge_formats.rb +58 -0
- data/test/test_04_dimensions.rb +397 -0
- data/test/test_05_rows.rb +182 -0
- data/test/test_06_extsst.rb +80 -0
- data/test/test_11_date_time.rb +484 -0
- data/test/test_12_date_only.rb +506 -0
- data/test/test_13_date_seconds.rb +486 -0
- data/test/test_21_escher.rb +629 -0
- data/test/test_22_mso_drawing_group.rb +739 -0
- data/test/test_23_note.rb +78 -0
- data/test/test_24_txo.rb +80 -0
- data/test/test_26_autofilter.rb +327 -0
- data/test/test_27_autofilter.rb +144 -0
- data/test/test_28_autofilter.rb +174 -0
- data/test/test_29_process_jpg.rb +131 -0
- data/test/test_30_validation_dval.rb +82 -0
- data/test/test_31_validation_dv_strings.rb +131 -0
- data/test/test_32_validation_dv_formula.rb +211 -0
- data/test/test_40_property_types.rb +191 -0
- data/test/test_41_properties.rb +238 -0
- data/test/test_42_set_properties.rb +430 -0
- data/test/ts_all.rb +34 -0
- metadata +154 -0
data/test/tc_formula.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "WriteExcel"
|
5
|
+
|
6
|
+
class TC_Formula < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@formula = Formula.new(0)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_scan
|
13
|
+
# scan must return array of token info
|
14
|
+
string01 = '1 + 2 * LEN("String")'
|
15
|
+
expected01 = [
|
16
|
+
[:NUMBER, '1'],
|
17
|
+
['+', '+'],
|
18
|
+
[:NUMBER, '2'],
|
19
|
+
['*', '*'],
|
20
|
+
[:FUNC, 'LEN'],
|
21
|
+
['(', '('],
|
22
|
+
[:STRING, '"String"'],
|
23
|
+
[')', ')'],
|
24
|
+
[:EOL, nil]
|
25
|
+
]
|
26
|
+
assert_kind_of(Array, @formula.scan(string01))
|
27
|
+
assert_equal(expected01, @formula.scan(string01))
|
28
|
+
|
29
|
+
string02 = 'IF(A1>=0,SIN(0),COS(90))'
|
30
|
+
expected02 = [
|
31
|
+
[:FUNC, 'IF'],
|
32
|
+
['(', '('],
|
33
|
+
[:REF2D, 'A1'],
|
34
|
+
[:GE, '>='],
|
35
|
+
[:NUMBER, '0'],
|
36
|
+
[',', ','],
|
37
|
+
[:FUNC, 'SIN'],
|
38
|
+
['(', '('],
|
39
|
+
[:NUMBER, '0'],
|
40
|
+
[')', ')'],
|
41
|
+
[',', ','],
|
42
|
+
[:FUNC, 'COS'],
|
43
|
+
['(', '('],
|
44
|
+
[:NUMBER, '90'],
|
45
|
+
[')', ')'],
|
46
|
+
[')', ')'],
|
47
|
+
[:EOL, nil]
|
48
|
+
]
|
49
|
+
assert_kind_of(Array, @formula.scan(string02))
|
50
|
+
assert_equal(expected02, @formula.scan(string02))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_reverse
|
54
|
+
testcase = [
|
55
|
+
[ [0,1,2,3,4], [0,[1,[2,3,[4]]]] ],
|
56
|
+
[ [0,1,2,3,4,5], [[0,1,[2,3]],[4,5]] ]
|
57
|
+
]
|
58
|
+
testcase.each do |t|
|
59
|
+
assert_equal(t[0], @formula.reverse(t[1]))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/test/tc_ole.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "WriteExcel"
|
5
|
+
|
6
|
+
class TC_OLE < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
t = Time.now.strftime("%Y%m%d")
|
10
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
11
|
+
@file = File.join(Dir.tmpdir, path)
|
12
|
+
@ole = OLEWriter.new(@file)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_constructor
|
16
|
+
assert_kind_of(OLEWriter, @ole)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_constants
|
20
|
+
assert_equal(7087104, OLEWriter::MaxSize)
|
21
|
+
assert_equal(4096, OLEWriter::BlockSize)
|
22
|
+
assert_equal(512, OLEWriter::BlockDiv)
|
23
|
+
assert_equal(127, OLEWriter::ListBlocks)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_calculate_sizes
|
27
|
+
assert_respond_to(@ole, :calculate_sizes)
|
28
|
+
assert_nothing_raised{ @ole.calculate_sizes }
|
29
|
+
assert_equal(0, @ole.big_blocks)
|
30
|
+
assert_equal(1, @ole.list_blocks)
|
31
|
+
assert_equal(0, @ole.root_start)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_set_size_too_big
|
35
|
+
assert(!@ole.set_size(999999999))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_book_size_large
|
39
|
+
assert_nothing_raised{ @ole.set_size(8192) }
|
40
|
+
assert_equal(8192, @ole.book_size)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_book_size_small
|
44
|
+
assert_nothing_raised{ @ole.set_size(2048) }
|
45
|
+
assert_equal(4096, @ole.book_size)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_biff_size
|
49
|
+
assert_nothing_raised{ @ole.set_size(2048) }
|
50
|
+
assert_equal(2048, @ole.biff_size)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_size_allowed
|
54
|
+
assert_nothing_raised{ @ole.set_size }
|
55
|
+
assert_equal(true, @ole.size_allowed)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_big_block_size_default
|
59
|
+
assert_nothing_raised{ @ole.set_size }
|
60
|
+
assert_nothing_raised{ @ole.calculate_sizes }
|
61
|
+
assert_equal(8, @ole.big_blocks, "Bad big block size")
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_big_block_size_rounded_up
|
65
|
+
assert_nothing_raised{ @ole.set_size(4099) }
|
66
|
+
assert_nothing_raised{ @ole.calculate_sizes }
|
67
|
+
assert_equal(9, @ole.big_blocks, "Bad big block size")
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_list_block_size
|
71
|
+
assert_nothing_raised{ @ole.set_size }
|
72
|
+
assert_nothing_raised{ @ole.calculate_sizes }
|
73
|
+
assert_equal(1, @ole.list_blocks, "Bad list block size")
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_root_start_size_default
|
77
|
+
assert_nothing_raised{ @ole.set_size }
|
78
|
+
assert_nothing_raised{ @ole.calculate_sizes }
|
79
|
+
assert_equal(8, @ole.big_blocks, "Bad root start size")
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_root_start_size_rounded_up
|
83
|
+
assert_nothing_raised{ @ole.set_size(4099) }
|
84
|
+
assert_nothing_raised{ @ole.calculate_sizes }
|
85
|
+
assert_equal(9, @ole.big_blocks, "Bad root start size")
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_write_header
|
89
|
+
assert_nothing_raised{ @ole.write_header }
|
90
|
+
#assert_nothing_raised{ @ole.close }
|
91
|
+
#assert_equal(512, File.size(@file))
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_write_big_block_depot
|
95
|
+
assert_nothing_raised{ @ole.write_big_block_depot }
|
96
|
+
#assert_nothing_raised{ @ole.close }
|
97
|
+
#assert_equal(8, File.size(@file))
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_write_property_storage_size
|
101
|
+
assert_nothing_raised{ @ole.write_property_storage }
|
102
|
+
#assert_nothing_raised{ @ole.close }
|
103
|
+
#assert_equal(512, File.size(@file))
|
104
|
+
end
|
105
|
+
|
106
|
+
def teardown
|
107
|
+
@ole.close rescue nil
|
108
|
+
File.unlink(@file) if File.exists?(@file)
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "WriteExcel/storage_lite"
|
5
|
+
|
6
|
+
def unpack_record(data)
|
7
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
8
|
+
end
|
9
|
+
|
10
|
+
class TC_OLEStorageLite < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@ole = OLEStorageLite.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_asc2ucs
|
19
|
+
result = @ole.asc2ucs('Root Entry')
|
20
|
+
target = %w(
|
21
|
+
52 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00
|
22
|
+
).join(" ")
|
23
|
+
assert_equal(target, unpack_record(result))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_ucs2asc
|
27
|
+
strings = [
|
28
|
+
'Root Entry',
|
29
|
+
''
|
30
|
+
]
|
31
|
+
strings.each do |str|
|
32
|
+
result = @ole.ucs2asc(@ole.asc2ucs(str))
|
33
|
+
assert_equal(str, result)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class TC_OLEStorageLitePPSFile < Test::Unit::TestCase
|
39
|
+
def setup
|
40
|
+
end
|
41
|
+
|
42
|
+
def teardown
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_constructor
|
46
|
+
data = [
|
47
|
+
{ :name => 'name', :data => 'data' },
|
48
|
+
{ :name => '', :data => 'data' },
|
49
|
+
{ :name => 'name', :data => '' },
|
50
|
+
{ :name => '', :data => '' },
|
51
|
+
]
|
52
|
+
data.each do |d|
|
53
|
+
olefile = OLEStorageLitePPSFile.new(d[:name])
|
54
|
+
assert_equal(d[:name], olefile.name)
|
55
|
+
end
|
56
|
+
data.each do |d|
|
57
|
+
olefile = OLEStorageLitePPSFile.new(d[:name], d[:data])
|
58
|
+
assert_equal(d[:name], olefile.name)
|
59
|
+
assert_equal(d[:data], olefile.data)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_append_no_file
|
64
|
+
olefile = OLEStorageLitePPSFile.new('name')
|
65
|
+
assert_equal('', olefile.data)
|
66
|
+
|
67
|
+
data = [ "data", "\r\n", "\r", "\n" ]
|
68
|
+
data.each do |d|
|
69
|
+
olefile = OLEStorageLitePPSFile.new('name')
|
70
|
+
olefile.append(d)
|
71
|
+
assert_equal(d, olefile.data)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_append_tempfile
|
76
|
+
data = [ "data", "\r\n", "\r", "\n" ]
|
77
|
+
data.each do |d|
|
78
|
+
olefile = OLEStorageLitePPSFile.new('name')
|
79
|
+
olefile.set_file
|
80
|
+
pps_file = olefile.pps_file
|
81
|
+
|
82
|
+
olefile.append(d)
|
83
|
+
pps_file.open
|
84
|
+
pps_file.binmode
|
85
|
+
assert_equal(d, pps_file.read)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_append_stringio
|
90
|
+
data = [ "data", "\r\n", "\r", "\n" ]
|
91
|
+
data.each do |d|
|
92
|
+
sio = StringIO.new
|
93
|
+
olefile = OLEStorageLitePPSFile.new('name')
|
94
|
+
olefile.set_file(sio)
|
95
|
+
pps_file = olefile.pps_file
|
96
|
+
|
97
|
+
olefile.append(d)
|
98
|
+
pps_file.rewind
|
99
|
+
assert_equal(d, pps_file.read)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/test/tc_workbook.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "WriteExcel"
|
5
|
+
|
6
|
+
class TC_Workbook < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
t = Time.now.strftime("%Y%m%d")
|
10
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
11
|
+
@test_file = File.join(Dir.tmpdir, path)
|
12
|
+
@workbook = Workbook.new(@test_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
@workbook.close
|
17
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_new
|
21
|
+
assert_kind_of(Workbook, @workbook)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_add_worksheet
|
25
|
+
sheetnames = ['sheet1', 'sheet2']
|
26
|
+
(0 .. sheetnames.size-1).each do |i|
|
27
|
+
sheets = @workbook.sheets
|
28
|
+
assert_equal(i, sheets.size)
|
29
|
+
@workbook.add_worksheet(sheetnames[i])
|
30
|
+
sheets = @workbook.sheets
|
31
|
+
assert_equal(i+1, sheets.size)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_set_tempdir_after_sheet_added
|
36
|
+
# after shees added, call set_tempdir raise RuntimeError
|
37
|
+
@workbook.add_worksheet('name')
|
38
|
+
assert_raise(RuntimeError, "already sheet exists, but set_tempdir() doesn't raise"){
|
39
|
+
@workbook.set_tempdir
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_set_tempdir_with_invalid_dir
|
44
|
+
# invalid dir raise RuntimeError
|
45
|
+
while true do
|
46
|
+
dir = Time.now.to_s
|
47
|
+
break unless FileTest.directory?(dir)
|
48
|
+
sleep 0.1
|
49
|
+
end
|
50
|
+
assert_raise(RuntimeError, "set_tempdir() doesn't raise invalid dir:#{dir}."){
|
51
|
+
@workbook.set_tempdir(dir)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_check_sheetname
|
56
|
+
valids = valid_sheetname
|
57
|
+
invalids = invalid_sheetname
|
58
|
+
worksheet1 = @workbook.add_worksheet # implicit name 'Sheet1'
|
59
|
+
worksheet2 = @workbook.add_worksheet # implicit name 'Sheet2'
|
60
|
+
worksheet3 = @workbook.add_worksheet 'Sheet3' # implicit name 'Sheet3'
|
61
|
+
worksheet1 = @workbook.add_worksheet 'Sheetz' # implicit name 'Sheetz'
|
62
|
+
|
63
|
+
valids.each do |test|
|
64
|
+
target = test[0]
|
65
|
+
sheetname = test[1]
|
66
|
+
caption = test[2]
|
67
|
+
assert_nothing_raised { @workbook.check_sheetname(sheetname) }
|
68
|
+
end
|
69
|
+
invalids.each do |test|
|
70
|
+
target = test[0]
|
71
|
+
sheetname = test[1]
|
72
|
+
caption = test[2]
|
73
|
+
assert_raise(RuntimeError, "sheetname: #{sheetname}") {
|
74
|
+
@workbook.check_sheetname(sheetname)
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_raise_set_compatibility_after_sheet_creation
|
80
|
+
@workbook.add_worksheet
|
81
|
+
assert_raise(RuntimeError) { @workbook.compatibility_mode }
|
82
|
+
end
|
83
|
+
|
84
|
+
def valid_sheetname
|
85
|
+
[
|
86
|
+
# Tests for valid names
|
87
|
+
[ 'PASS', nil, 'No worksheet name' ],
|
88
|
+
[ 'PASS', '', 'Blank worksheet name' ],
|
89
|
+
[ 'PASS', 'Sheet10', 'Valid worksheet name' ],
|
90
|
+
[ 'PASS', 'a' * 31, 'Valid 31 char name' ]
|
91
|
+
]
|
92
|
+
end
|
93
|
+
|
94
|
+
def invalid_sheetname
|
95
|
+
[
|
96
|
+
# Tests for invalid names
|
97
|
+
[ 'FAIL', 'Sheet1', 'Caught duplicate name' ],
|
98
|
+
[ 'FAIL', 'Sheet2', 'Caught duplicate name' ],
|
99
|
+
[ 'FAIL', 'Sheet3', 'Caught duplicate name' ],
|
100
|
+
[ 'FAIL', 'sheet1', 'Caught case-insensitive name'],
|
101
|
+
[ 'FAIL', 'SHEET1', 'Caught case-insensitive name'],
|
102
|
+
[ 'FAIL', 'sheetz', 'Caught case-insensitive name'],
|
103
|
+
[ 'FAIL', 'SHEETZ', 'Caught case-insensitive name'],
|
104
|
+
[ 'FAIL', 'a' * 32, 'Caught long name' ],
|
105
|
+
[ 'FAIL', '[', 'Caught invalid char' ],
|
106
|
+
[ 'FAIL', ']', 'Caught invalid char' ],
|
107
|
+
[ 'FAIL', ':', 'Caught invalid char' ],
|
108
|
+
[ 'FAIL', '*', 'Caught invalid char' ],
|
109
|
+
[ 'FAIL', '?', 'Caught invalid char' ],
|
110
|
+
[ 'FAIL', '/', 'Caught invalid char' ],
|
111
|
+
[ 'FAIL', '\\', 'Caught invalid char' ]
|
112
|
+
]
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +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 = Spreadsheet::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
|