writeexcel 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/test_27_autofilter.rb
CHANGED
@@ -1,144 +1,144 @@
|
|
1
|
-
##########################################################################
|
2
|
-
# test_27_autofilter.rb
|
3
|
-
#
|
4
|
-
# Tests for the token extraction method used to parse autofilter expressions.
|
5
|
-
#
|
6
|
-
# reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
|
7
|
-
#
|
8
|
-
# original written in Perl by John McNamara
|
9
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
10
|
-
#
|
11
|
-
#########################################################################
|
12
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
13
|
-
|
14
|
-
require "test/unit"
|
15
|
-
require 'writeexcel'
|
16
|
-
|
17
|
-
class TC_27_autofilter < Test::Unit::TestCase
|
18
|
-
|
19
|
-
def test_27_autofilter
|
20
|
-
@tests.each do |test|
|
21
|
-
expression = test[0]
|
22
|
-
expected = test[1]
|
23
|
-
result = @worksheet.extract_filter_tokens(expression)
|
24
|
-
|
25
|
-
testname = expression || 'none'
|
26
|
-
|
27
|
-
assert_equal(expected, result, testname)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
###############################################################################
|
32
|
-
#
|
33
|
-
# Unpack the binary data into a format suitable for printing in tests.
|
34
|
-
#
|
35
|
-
def unpack_record(data)
|
36
|
-
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
37
|
-
end
|
38
|
-
|
39
|
-
def setup
|
40
|
-
t = Time.now.strftime("%Y%m%d")
|
41
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
42
|
-
@test_file = File.join(Dir.tmpdir, path)
|
43
|
-
@workbook =
|
44
|
-
@worksheet = @workbook.add_worksheet
|
45
|
-
@tests = [
|
46
|
-
[
|
47
|
-
nil,
|
48
|
-
[],
|
49
|
-
],
|
50
|
-
|
51
|
-
[
|
52
|
-
'',
|
53
|
-
[],
|
54
|
-
],
|
55
|
-
|
56
|
-
[
|
57
|
-
'0 < 2000',
|
58
|
-
[0, '<', 2000],
|
59
|
-
],
|
60
|
-
|
61
|
-
[
|
62
|
-
'x < 2000',
|
63
|
-
['x', '<', 2000],
|
64
|
-
],
|
65
|
-
|
66
|
-
[
|
67
|
-
'x > 2000',
|
68
|
-
['x', '>', 2000],
|
69
|
-
],
|
70
|
-
|
71
|
-
[
|
72
|
-
'x == 2000',
|
73
|
-
['x', '==', 2000],
|
74
|
-
],
|
75
|
-
|
76
|
-
[
|
77
|
-
'x > 2000 and x < 5000',
|
78
|
-
['x', '>', 2000, 'and', 'x', '<', 5000],
|
79
|
-
],
|
80
|
-
|
81
|
-
[
|
82
|
-
'x = "foo"',
|
83
|
-
['x', '=', 'foo'],
|
84
|
-
],
|
85
|
-
|
86
|
-
[
|
87
|
-
'x = foo',
|
88
|
-
['x', '=', 'foo'],
|
89
|
-
],
|
90
|
-
|
91
|
-
[
|
92
|
-
'x = "foo bar"',
|
93
|
-
['x', '=', 'foo bar'],
|
94
|
-
],
|
95
|
-
|
96
|
-
[
|
97
|
-
'x = "foo "" bar"',
|
98
|
-
['x', '=', 'foo " bar'],
|
99
|
-
],
|
100
|
-
|
101
|
-
[
|
102
|
-
'x = "foo bar" or x = "bar foo"',
|
103
|
-
['x', '=', 'foo bar', 'or', 'x', '=', 'bar foo'],
|
104
|
-
],
|
105
|
-
|
106
|
-
[
|
107
|
-
'x = "foo "" bar" or x = "bar "" foo"',
|
108
|
-
['x', '=', 'foo " bar', 'or', 'x', '=', 'bar " foo'],
|
109
|
-
],
|
110
|
-
|
111
|
-
[
|
112
|
-
'x = """"""""',
|
113
|
-
['x', '=', '"""'],
|
114
|
-
],
|
115
|
-
|
116
|
-
[
|
117
|
-
'x = Blanks',
|
118
|
-
['x', '=', 'Blanks'],
|
119
|
-
],
|
120
|
-
|
121
|
-
[
|
122
|
-
'x = NonBlanks',
|
123
|
-
['x', '=', 'NonBlanks'],
|
124
|
-
],
|
125
|
-
|
126
|
-
[
|
127
|
-
'top 10 %',
|
128
|
-
['top', 10, '%'],
|
129
|
-
],
|
130
|
-
|
131
|
-
[
|
132
|
-
'top 10 items',
|
133
|
-
['top', 10, 'items'],
|
134
|
-
],
|
135
|
-
|
136
|
-
]
|
137
|
-
end
|
138
|
-
|
139
|
-
def teardown
|
140
|
-
@workbook.close
|
141
|
-
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
1
|
+
##########################################################################
|
2
|
+
# test_27_autofilter.rb
|
3
|
+
#
|
4
|
+
# Tests for the token extraction method used to parse autofilter expressions.
|
5
|
+
#
|
6
|
+
# reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
|
7
|
+
#
|
8
|
+
# original written in Perl by John McNamara
|
9
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
10
|
+
#
|
11
|
+
#########################################################################
|
12
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
13
|
+
|
14
|
+
require "test/unit"
|
15
|
+
require 'writeexcel'
|
16
|
+
|
17
|
+
class TC_27_autofilter < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def test_27_autofilter
|
20
|
+
@tests.each do |test|
|
21
|
+
expression = test[0]
|
22
|
+
expected = test[1]
|
23
|
+
result = @worksheet.extract_filter_tokens(expression)
|
24
|
+
|
25
|
+
testname = expression || 'none'
|
26
|
+
|
27
|
+
assert_equal(expected, result, testname)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
###############################################################################
|
32
|
+
#
|
33
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
34
|
+
#
|
35
|
+
def unpack_record(data)
|
36
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup
|
40
|
+
t = Time.now.strftime("%Y%m%d")
|
41
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
42
|
+
@test_file = File.join(Dir.tmpdir, path)
|
43
|
+
@workbook = WriteExcel.new(@test_file)
|
44
|
+
@worksheet = @workbook.add_worksheet
|
45
|
+
@tests = [
|
46
|
+
[
|
47
|
+
nil,
|
48
|
+
[],
|
49
|
+
],
|
50
|
+
|
51
|
+
[
|
52
|
+
'',
|
53
|
+
[],
|
54
|
+
],
|
55
|
+
|
56
|
+
[
|
57
|
+
'0 < 2000',
|
58
|
+
[0, '<', 2000],
|
59
|
+
],
|
60
|
+
|
61
|
+
[
|
62
|
+
'x < 2000',
|
63
|
+
['x', '<', 2000],
|
64
|
+
],
|
65
|
+
|
66
|
+
[
|
67
|
+
'x > 2000',
|
68
|
+
['x', '>', 2000],
|
69
|
+
],
|
70
|
+
|
71
|
+
[
|
72
|
+
'x == 2000',
|
73
|
+
['x', '==', 2000],
|
74
|
+
],
|
75
|
+
|
76
|
+
[
|
77
|
+
'x > 2000 and x < 5000',
|
78
|
+
['x', '>', 2000, 'and', 'x', '<', 5000],
|
79
|
+
],
|
80
|
+
|
81
|
+
[
|
82
|
+
'x = "foo"',
|
83
|
+
['x', '=', 'foo'],
|
84
|
+
],
|
85
|
+
|
86
|
+
[
|
87
|
+
'x = foo',
|
88
|
+
['x', '=', 'foo'],
|
89
|
+
],
|
90
|
+
|
91
|
+
[
|
92
|
+
'x = "foo bar"',
|
93
|
+
['x', '=', 'foo bar'],
|
94
|
+
],
|
95
|
+
|
96
|
+
[
|
97
|
+
'x = "foo "" bar"',
|
98
|
+
['x', '=', 'foo " bar'],
|
99
|
+
],
|
100
|
+
|
101
|
+
[
|
102
|
+
'x = "foo bar" or x = "bar foo"',
|
103
|
+
['x', '=', 'foo bar', 'or', 'x', '=', 'bar foo'],
|
104
|
+
],
|
105
|
+
|
106
|
+
[
|
107
|
+
'x = "foo "" bar" or x = "bar "" foo"',
|
108
|
+
['x', '=', 'foo " bar', 'or', 'x', '=', 'bar " foo'],
|
109
|
+
],
|
110
|
+
|
111
|
+
[
|
112
|
+
'x = """"""""',
|
113
|
+
['x', '=', '"""'],
|
114
|
+
],
|
115
|
+
|
116
|
+
[
|
117
|
+
'x = Blanks',
|
118
|
+
['x', '=', 'Blanks'],
|
119
|
+
],
|
120
|
+
|
121
|
+
[
|
122
|
+
'x = NonBlanks',
|
123
|
+
['x', '=', 'NonBlanks'],
|
124
|
+
],
|
125
|
+
|
126
|
+
[
|
127
|
+
'top 10 %',
|
128
|
+
['top', 10, '%'],
|
129
|
+
],
|
130
|
+
|
131
|
+
[
|
132
|
+
'top 10 items',
|
133
|
+
['top', 10, 'items'],
|
134
|
+
],
|
135
|
+
|
136
|
+
]
|
137
|
+
end
|
138
|
+
|
139
|
+
def teardown
|
140
|
+
@workbook.close
|
141
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
data/test/test_28_autofilter.rb
CHANGED
@@ -1,174 +1,174 @@
|
|
1
|
-
##########################################################################
|
2
|
-
# test_28_autofilter.rb
|
3
|
-
#
|
4
|
-
# Tests for the token parsing methods used to parse autofilter expressions.
|
5
|
-
#
|
6
|
-
# reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
|
7
|
-
#
|
8
|
-
# original written in Perl by John McNamara
|
9
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
10
|
-
#
|
11
|
-
#########################################################################
|
12
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
13
|
-
|
14
|
-
require "test/unit"
|
15
|
-
require 'writeexcel'
|
16
|
-
|
17
|
-
class TC_28_autofilter < Test::Unit::TestCase
|
18
|
-
|
19
|
-
def test_28_autofilter
|
20
|
-
@tests.each do |test|
|
21
|
-
expression = test[0]
|
22
|
-
expected = test[1]
|
23
|
-
tokens = @worksheet.extract_filter_tokens(expression)
|
24
|
-
result = @worksheet.parse_filter_expression(expression, tokens)
|
25
|
-
|
26
|
-
testname = expression || 'none'
|
27
|
-
|
28
|
-
assert_equal(expected, result, testname)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
###############################################################################
|
33
|
-
#
|
34
|
-
# Unpack the binary data into a format suitable for printing in tests.
|
35
|
-
#
|
36
|
-
def unpack_record(data)
|
37
|
-
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
38
|
-
end
|
39
|
-
|
40
|
-
def setup
|
41
|
-
t = Time.now.strftime("%Y%m%d")
|
42
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
43
|
-
@test_file = File.join(Dir.tmpdir, path)
|
44
|
-
@workbook =
|
45
|
-
@worksheet = @workbook.add_worksheet
|
46
|
-
@tests = [
|
47
|
-
[
|
48
|
-
'x = 2000',
|
49
|
-
[2, 2000],
|
50
|
-
],
|
51
|
-
|
52
|
-
[
|
53
|
-
'x == 2000',
|
54
|
-
[2, 2000],
|
55
|
-
],
|
56
|
-
|
57
|
-
[
|
58
|
-
'x =~ 2000',
|
59
|
-
[2, 2000],
|
60
|
-
],
|
61
|
-
|
62
|
-
[
|
63
|
-
'x eq 2000',
|
64
|
-
[2, 2000],
|
65
|
-
],
|
66
|
-
|
67
|
-
[
|
68
|
-
'x <> 2000',
|
69
|
-
[5, 2000],
|
70
|
-
],
|
71
|
-
|
72
|
-
[
|
73
|
-
'x != 2000',
|
74
|
-
[5, 2000],
|
75
|
-
],
|
76
|
-
|
77
|
-
[
|
78
|
-
'x ne 2000',
|
79
|
-
[5, 2000],
|
80
|
-
],
|
81
|
-
|
82
|
-
[
|
83
|
-
'x !~ 2000',
|
84
|
-
[5, 2000],
|
85
|
-
],
|
86
|
-
|
87
|
-
[
|
88
|
-
'x > 2000',
|
89
|
-
[4, 2000],
|
90
|
-
],
|
91
|
-
|
92
|
-
[
|
93
|
-
'x < 2000',
|
94
|
-
[1, 2000],
|
95
|
-
],
|
96
|
-
|
97
|
-
[
|
98
|
-
'x >= 2000',
|
99
|
-
[6, 2000],
|
100
|
-
],
|
101
|
-
|
102
|
-
[
|
103
|
-
'x <= 2000',
|
104
|
-
[3, 2000],
|
105
|
-
],
|
106
|
-
|
107
|
-
[
|
108
|
-
'x > 2000 and x < 5000',
|
109
|
-
[4, 2000, 0, 1, 5000],
|
110
|
-
],
|
111
|
-
|
112
|
-
[
|
113
|
-
'x > 2000 && x < 5000',
|
114
|
-
[4, 2000, 0, 1, 5000],
|
115
|
-
],
|
116
|
-
|
117
|
-
[
|
118
|
-
'x > 2000 or x < 5000',
|
119
|
-
[4, 2000, 1, 1, 5000],
|
120
|
-
],
|
121
|
-
|
122
|
-
[
|
123
|
-
'x > 2000 || x < 5000',
|
124
|
-
[4, 2000, 1, 1, 5000],
|
125
|
-
],
|
126
|
-
|
127
|
-
[
|
128
|
-
'x = Blanks',
|
129
|
-
[2, 'blanks'],
|
130
|
-
],
|
131
|
-
|
132
|
-
[
|
133
|
-
'x = NonBlanks',
|
134
|
-
[2, 'nonblanks'],
|
135
|
-
],
|
136
|
-
|
137
|
-
[
|
138
|
-
'x <> Blanks',
|
139
|
-
[2, 'nonblanks'],
|
140
|
-
],
|
141
|
-
|
142
|
-
[
|
143
|
-
'x <> NonBlanks',
|
144
|
-
[2, 'blanks'],
|
145
|
-
],
|
146
|
-
|
147
|
-
[
|
148
|
-
'Top 10 Items',
|
149
|
-
[30, 10],
|
150
|
-
],
|
151
|
-
|
152
|
-
[
|
153
|
-
'Top 20 %',
|
154
|
-
[31, 20],
|
155
|
-
],
|
156
|
-
|
157
|
-
[
|
158
|
-
'Bottom 5 Items',
|
159
|
-
[32, 5],
|
160
|
-
],
|
161
|
-
|
162
|
-
[
|
163
|
-
'Bottom 101 %',
|
164
|
-
[33, 101],
|
165
|
-
],
|
166
|
-
]
|
167
|
-
end
|
168
|
-
|
169
|
-
def teardown
|
170
|
-
@workbook.close
|
171
|
-
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
1
|
+
##########################################################################
|
2
|
+
# test_28_autofilter.rb
|
3
|
+
#
|
4
|
+
# Tests for the token parsing methods used to parse autofilter expressions.
|
5
|
+
#
|
6
|
+
# reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
|
7
|
+
#
|
8
|
+
# original written in Perl by John McNamara
|
9
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
10
|
+
#
|
11
|
+
#########################################################################
|
12
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
13
|
+
|
14
|
+
require "test/unit"
|
15
|
+
require 'writeexcel'
|
16
|
+
|
17
|
+
class TC_28_autofilter < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def test_28_autofilter
|
20
|
+
@tests.each do |test|
|
21
|
+
expression = test[0]
|
22
|
+
expected = test[1]
|
23
|
+
tokens = @worksheet.extract_filter_tokens(expression)
|
24
|
+
result = @worksheet.parse_filter_expression(expression, tokens)
|
25
|
+
|
26
|
+
testname = expression || 'none'
|
27
|
+
|
28
|
+
assert_equal(expected, result, testname)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
###############################################################################
|
33
|
+
#
|
34
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
35
|
+
#
|
36
|
+
def unpack_record(data)
|
37
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup
|
41
|
+
t = Time.now.strftime("%Y%m%d")
|
42
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
43
|
+
@test_file = File.join(Dir.tmpdir, path)
|
44
|
+
@workbook = WriteExcel.new(@test_file)
|
45
|
+
@worksheet = @workbook.add_worksheet
|
46
|
+
@tests = [
|
47
|
+
[
|
48
|
+
'x = 2000',
|
49
|
+
[2, 2000],
|
50
|
+
],
|
51
|
+
|
52
|
+
[
|
53
|
+
'x == 2000',
|
54
|
+
[2, 2000],
|
55
|
+
],
|
56
|
+
|
57
|
+
[
|
58
|
+
'x =~ 2000',
|
59
|
+
[2, 2000],
|
60
|
+
],
|
61
|
+
|
62
|
+
[
|
63
|
+
'x eq 2000',
|
64
|
+
[2, 2000],
|
65
|
+
],
|
66
|
+
|
67
|
+
[
|
68
|
+
'x <> 2000',
|
69
|
+
[5, 2000],
|
70
|
+
],
|
71
|
+
|
72
|
+
[
|
73
|
+
'x != 2000',
|
74
|
+
[5, 2000],
|
75
|
+
],
|
76
|
+
|
77
|
+
[
|
78
|
+
'x ne 2000',
|
79
|
+
[5, 2000],
|
80
|
+
],
|
81
|
+
|
82
|
+
[
|
83
|
+
'x !~ 2000',
|
84
|
+
[5, 2000],
|
85
|
+
],
|
86
|
+
|
87
|
+
[
|
88
|
+
'x > 2000',
|
89
|
+
[4, 2000],
|
90
|
+
],
|
91
|
+
|
92
|
+
[
|
93
|
+
'x < 2000',
|
94
|
+
[1, 2000],
|
95
|
+
],
|
96
|
+
|
97
|
+
[
|
98
|
+
'x >= 2000',
|
99
|
+
[6, 2000],
|
100
|
+
],
|
101
|
+
|
102
|
+
[
|
103
|
+
'x <= 2000',
|
104
|
+
[3, 2000],
|
105
|
+
],
|
106
|
+
|
107
|
+
[
|
108
|
+
'x > 2000 and x < 5000',
|
109
|
+
[4, 2000, 0, 1, 5000],
|
110
|
+
],
|
111
|
+
|
112
|
+
[
|
113
|
+
'x > 2000 && x < 5000',
|
114
|
+
[4, 2000, 0, 1, 5000],
|
115
|
+
],
|
116
|
+
|
117
|
+
[
|
118
|
+
'x > 2000 or x < 5000',
|
119
|
+
[4, 2000, 1, 1, 5000],
|
120
|
+
],
|
121
|
+
|
122
|
+
[
|
123
|
+
'x > 2000 || x < 5000',
|
124
|
+
[4, 2000, 1, 1, 5000],
|
125
|
+
],
|
126
|
+
|
127
|
+
[
|
128
|
+
'x = Blanks',
|
129
|
+
[2, 'blanks'],
|
130
|
+
],
|
131
|
+
|
132
|
+
[
|
133
|
+
'x = NonBlanks',
|
134
|
+
[2, 'nonblanks'],
|
135
|
+
],
|
136
|
+
|
137
|
+
[
|
138
|
+
'x <> Blanks',
|
139
|
+
[2, 'nonblanks'],
|
140
|
+
],
|
141
|
+
|
142
|
+
[
|
143
|
+
'x <> NonBlanks',
|
144
|
+
[2, 'blanks'],
|
145
|
+
],
|
146
|
+
|
147
|
+
[
|
148
|
+
'Top 10 Items',
|
149
|
+
[30, 10],
|
150
|
+
],
|
151
|
+
|
152
|
+
[
|
153
|
+
'Top 20 %',
|
154
|
+
[31, 20],
|
155
|
+
],
|
156
|
+
|
157
|
+
[
|
158
|
+
'Bottom 5 Items',
|
159
|
+
[32, 5],
|
160
|
+
],
|
161
|
+
|
162
|
+
[
|
163
|
+
'Bottom 101 %',
|
164
|
+
[33, 101],
|
165
|
+
],
|
166
|
+
]
|
167
|
+
end
|
168
|
+
|
169
|
+
def teardown
|
170
|
+
@workbook.close
|
171
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|