writeexcel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/README +103 -0
  2. data/examples/a_simple.rb +42 -0
  3. data/examples/autofilters.rb +266 -0
  4. data/examples/copyformat.rb +51 -0
  5. data/examples/data_validate.rb +278 -0
  6. data/examples/date_time.rb +86 -0
  7. data/examples/demo.rb +118 -0
  8. data/examples/diag_border.rb +35 -0
  9. data/examples/formats.rb +489 -0
  10. data/examples/header.rb +136 -0
  11. data/examples/hidden.rb +28 -0
  12. data/examples/hyperlink.rb +42 -0
  13. data/examples/images.rb +52 -0
  14. data/examples/merge1.rb +39 -0
  15. data/examples/merge2.rb +44 -0
  16. data/examples/merge3.rb +65 -0
  17. data/examples/merge4.rb +82 -0
  18. data/examples/merge5.rb +79 -0
  19. data/examples/protection.rb +46 -0
  20. data/examples/regions.rb +52 -0
  21. data/examples/repeat.rb +42 -0
  22. data/examples/republic.png +0 -0
  23. data/examples/stats.rb +75 -0
  24. data/examples/stocks.rb +80 -0
  25. data/examples/tab_colors.rb +30 -0
  26. data/lib/writeexcel/biffwriter.rb +260 -0
  27. data/lib/writeexcel/chart.rb +217 -0
  28. data/lib/writeexcel/excelformulaparser.rb +573 -0
  29. data/lib/writeexcel/format.rb +1108 -0
  30. data/lib/writeexcel/formula.rb +986 -0
  31. data/lib/writeexcel/olewriter.rb +322 -0
  32. data/lib/writeexcel/properties.rb +250 -0
  33. data/lib/writeexcel/workbook.rb +2630 -0
  34. data/lib/writeexcel/worksheet.rb +6377 -0
  35. data/lib/writeexcel.rb +18 -0
  36. data/test/perl_output/README +31 -0
  37. data/test/perl_output/a_simple.xls +0 -0
  38. data/test/perl_output/biff_add_continue_testdata +0 -0
  39. data/test/perl_output/data_validate.xls +0 -0
  40. data/test/perl_output/date_time.xls +0 -0
  41. data/test/perl_output/demo.xls +0 -0
  42. data/test/perl_output/diag_border.xls +0 -0
  43. data/test/perl_output/f_font_biff +0 -0
  44. data/test/perl_output/f_font_key +1 -0
  45. data/test/perl_output/f_xf_biff +0 -0
  46. data/test/perl_output/file_font_biff +0 -0
  47. data/test/perl_output/file_font_key +1 -0
  48. data/test/perl_output/file_xf_biff +0 -0
  49. data/test/perl_output/headers.xls +0 -0
  50. data/test/perl_output/hidden.xls +0 -0
  51. data/test/perl_output/hyperlink.xls +0 -0
  52. data/test/perl_output/images.xls +0 -0
  53. data/test/perl_output/merge1.xls +0 -0
  54. data/test/perl_output/merge2.xls +0 -0
  55. data/test/perl_output/merge3.xls +0 -0
  56. data/test/perl_output/merge4.xls +0 -0
  57. data/test/perl_output/merge5.xls +0 -0
  58. data/test/perl_output/ole_write_header +0 -0
  59. data/test/perl_output/protection.xls +0 -0
  60. data/test/perl_output/regions.xls +0 -0
  61. data/test/perl_output/stats.xls +0 -0
  62. data/test/perl_output/stocks.xls +0 -0
  63. data/test/perl_output/tab_colors.xls +0 -0
  64. data/test/perl_output/unicode_cyrillic.xls +0 -0
  65. data/test/perl_output/workbook1.xls +0 -0
  66. data/test/perl_output/workbook2.xls +0 -0
  67. data/test/perl_output/ws_colinfo +1 -0
  68. data/test/perl_output/ws_store_colinfo +0 -0
  69. data/test/perl_output/ws_store_dimensions +0 -0
  70. data/test/perl_output/ws_store_filtermode +0 -0
  71. data/test/perl_output/ws_store_filtermode_off +0 -0
  72. data/test/perl_output/ws_store_filtermode_on +0 -0
  73. data/test/perl_output/ws_store_selection +0 -0
  74. data/test/perl_output/ws_store_window2 +1 -0
  75. data/test/republic.png +0 -0
  76. data/test/tc_all.rb +31 -0
  77. data/test/tc_biff.rb +104 -0
  78. data/test/tc_chart.rb +22 -0
  79. data/test/tc_example_match.rb +1280 -0
  80. data/test/tc_format.rb +1267 -0
  81. data/test/tc_formula.rb +63 -0
  82. data/test/tc_ole.rb +110 -0
  83. data/test/tc_workbook.rb +115 -0
  84. data/test/tc_worksheet.rb +115 -0
  85. data/test/test_00_IEEE_double.rb +14 -0
  86. data/test/test_01_add_worksheet.rb +12 -0
  87. data/test/test_02_merge_formats.rb +58 -0
  88. data/test/test_04_dimensions.rb +397 -0
  89. data/test/test_05_rows.rb +182 -0
  90. data/test/test_06_extsst.rb +80 -0
  91. data/test/test_11_date_time.rb +484 -0
  92. data/test/test_12_date_only.rb +506 -0
  93. data/test/test_13_date_seconds.rb +486 -0
  94. data/test/test_21_escher.rb +629 -0
  95. data/test/test_22_mso_drawing_group.rb +739 -0
  96. data/test/test_23_note.rb +78 -0
  97. data/test/test_24_txo.rb +80 -0
  98. data/test/test_26_autofilter.rb +327 -0
  99. data/test/test_27_autofilter.rb +144 -0
  100. data/test/test_28_autofilter.rb +174 -0
  101. data/test/test_29_process_jpg.rb +131 -0
  102. data/test/test_30_validation_dval.rb +82 -0
  103. data/test/test_31_validation_dv_strings.rb +131 -0
  104. data/test/test_32_validation_dv_formula.rb +211 -0
  105. data/test/test_40_property_types.rb +191 -0
  106. data/test/test_41_properties.rb +238 -0
  107. data/test/test_42_set_properties.rb +419 -0
  108. data/test/ts_all.rb +34 -0
  109. metadata +170 -0
@@ -0,0 +1,78 @@
1
+ ##########################################################################
2
+ # test_23_note.rb
3
+ #
4
+ # Tests for some of the internal method used to write the NOTE record that
5
+ # is used in cell comments.
6
+ #
7
+ # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+ #########################################################################
13
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
+
15
+ require "test/unit"
16
+ require 'writeexcel'
17
+
18
+ class TC_note < Test::Unit::TestCase
19
+
20
+ def setup
21
+ t = Time.now.strftime("%Y%m%d")
22
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
+ @test_file = File.join(Dir.tmpdir, path)
24
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
25
+ @worksheet = @workbook.add_worksheet
26
+ end
27
+
28
+ def teardown
29
+ @workbook.close
30
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
31
+ end
32
+
33
+ def test_blank_author_name
34
+ data = @worksheet.comment_params(2,0,'Test')
35
+ row = data[0]
36
+ col = data[1]
37
+ author = data[4]
38
+ encoding = data[5]
39
+ visible = data[6]
40
+ obj_id = 1
41
+
42
+ caption = sprintf(" \tstore_note")
43
+ target = %w(
44
+ 1C 00 0C 00 02 00 00 00 00 00 01 00 00 00 00 00
45
+ ).join(' ')
46
+ result = unpack_record(
47
+ @worksheet.store_note(row,col,obj_id,author,encoding,visible))
48
+ assert_equal(target, result, caption)
49
+ end
50
+
51
+ def test_defined_author_name
52
+ data = @worksheet.comment_params(2,0,'Test', :author => 'Username')
53
+ row = data[0]
54
+ col = data[1]
55
+ author = data[4]
56
+ encoding = data[5]
57
+ visible = data[6]
58
+ obj_id = 1
59
+
60
+ caption = sprintf(" \tstore_note")
61
+ target = %w(
62
+ 1C 00 14 00 02 00 00 00 00 00 01 00 08 00 00 55
63
+ 73 65 72 6E 61 6D 65 00
64
+ ).join(' ')
65
+ result = unpack_record(
66
+ @worksheet.store_note(row,col,obj_id,author,encoding,visible))
67
+ assert_equal(target, result, caption)
68
+ end
69
+
70
+ ###############################################################################
71
+ #
72
+ # Unpack the binary data into a format suitable for printing in tests.
73
+ #
74
+ def unpack_record(data)
75
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
76
+ end
77
+
78
+ end
@@ -0,0 +1,80 @@
1
+ ##########################################################################
2
+ # test_24_txo.rb
3
+ #
4
+ # Tests for some of the internal method used to write the NOTE record that
5
+ # is used in cell comments.
6
+ #
7
+ # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+ #########################################################################
13
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
+
15
+ require "test/unit"
16
+ require 'writeexcel'
17
+
18
+ class TC_txo < Test::Unit::TestCase
19
+
20
+ def setup
21
+ t = Time.now.strftime("%Y%m%d")
22
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
+ @test_file = File.join(Dir.tmpdir, path)
24
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
25
+ @worksheet = @workbook.add_worksheet
26
+ end
27
+
28
+ def teardown
29
+ @workbook.close
30
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
31
+ end
32
+
33
+ def test_txo
34
+ string = 'aaa'
35
+ caption = " \t_store_txo()"
36
+ target = %w(
37
+ B6 01 12 00 12 02 00 00 00 00 00 00 00 00 03 00
38
+ 10 00 00 00 00 00
39
+ ).join(' ')
40
+
41
+ result = unpack_record(@worksheet.store_txo(string.length))
42
+ assert_equal(target, result, caption)
43
+ end
44
+
45
+ def test_first_continue_record_after_txo
46
+ string = 'aaa'
47
+ caption = " \t_store_txo_continue_1()"
48
+ target = %w(
49
+ 3C 00 04 00 00 61 61 61
50
+ ).join(' ')
51
+
52
+ result = unpack_record(@worksheet.store_txo_continue_1(string))
53
+ assert_equal(target, result, caption)
54
+ end
55
+
56
+ def test_second_continue_record_after_txo
57
+ string = 'aaa'
58
+ caption = " \t_store_txo_continue_2()"
59
+ target = %w(
60
+ 3C 00 10 00 00 00 00 00 00 00 00 00 03 00 00 00
61
+ 00 00 00 00
62
+ ).join(' ')
63
+ formats = [
64
+ [0, 0],
65
+ [string.length, 0]
66
+ ]
67
+
68
+ result = unpack_record(@worksheet.store_txo_continue_2(formats))
69
+ assert_equal(target, result, caption)
70
+ end
71
+
72
+ ###############################################################################
73
+ #
74
+ # Unpack the binary data into a format suitable for printing in tests.
75
+ #
76
+ def unpack_record(data)
77
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
78
+ end
79
+
80
+ end
@@ -0,0 +1,327 @@
1
+ ##########################################################################
2
+ # test_26_autofilter.rb
3
+ #
4
+ # Tests for the internal methods used to write the AUTOFILTER record.
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_26_autofilter < Test::Unit::TestCase
18
+
19
+ def test_26_autofilter
20
+ @tests.each do |test|
21
+ column = test['column']
22
+ expression = test['expression']
23
+ tokens = @worksheet.extract_filter_tokens(expression)
24
+ tokens = @worksheet.parse_filter_expression(expression, tokens)
25
+
26
+ result = @worksheet.store_autofilter(column, *tokens)
27
+
28
+ target = test['data'].join(" ")
29
+
30
+ caption = " \tfilter_column(#{column}, '#{expression}')"
31
+
32
+ result = unpack_record(result)
33
+ assert_equal(target, result, caption)
34
+ end
35
+ end
36
+
37
+ ###############################################################################
38
+ #
39
+ # Unpack the binary data into a format suitable for printing in tests.
40
+ #
41
+ def unpack_record(data)
42
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
43
+ end
44
+
45
+ def setup
46
+ t = Time.now.strftime("%Y%m%d")
47
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
48
+ @test_file = File.join(Dir.tmpdir, path)
49
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
50
+ @worksheet = @workbook.add_worksheet
51
+ @tests = [
52
+ {
53
+ 'column' => 0,
54
+ 'expression' => 'x = Blanks',
55
+ 'data' => [%w(
56
+ 9E 00 18 00 00 00 84 32 0C 02 00 00 00 00 00 00
57
+ 00 00 00 00 00 00 00 00 00 00 00 00
58
+
59
+ )]
60
+ },
61
+ {
62
+ 'column' => 1,
63
+ 'expression' => 'x = Nonblanks',
64
+ 'data' => [%w(
65
+ 9E 00 18 00 01 00 84 32 0E 05 00 00 00 00 00 00
66
+ 00 00 00 00 00 00 00 00 00 00 00 00
67
+
68
+ )]
69
+ },
70
+ {
71
+ 'column' => 2,
72
+ 'expression' => 'x > 1.001',
73
+ 'data' => [%w(
74
+ 9E 00 18 00 02 00 80 32 04 04 6A BC 74 93 18 04
75
+ F0 3F 00 00 00 00 00 00 00 00 00 00
76
+
77
+ )]
78
+ },
79
+ {
80
+ 'column' => 3,
81
+ 'expression' => 'x >= 1.001',
82
+ 'data' => [%w(
83
+ 9E 00 18 00 03 00 80 32 04 06 6A BC 74 93 18 04
84
+ F0 3F 00 00 00 00 00 00 00 00 00 00
85
+
86
+ )]
87
+ },
88
+ {
89
+ 'column' => 4,
90
+ 'expression' => 'x < 1.001',
91
+ 'data' => [%w(
92
+ 9E 00 18 00 04 00 80 32 04 01 6A BC 74 93 18 04
93
+ F0 3F 00 00 00 00 00 00 00 00 00 00
94
+
95
+ )]
96
+ },
97
+ {
98
+ 'column' => 5,
99
+ 'expression' => 'x <= 1.001',
100
+ 'data' => [%w(
101
+ 9E 00 18 00 05 00 80 32 04 03 6A BC 74 93 18 04
102
+ F0 3F 00 00 00 00 00 00 00 00 00 00
103
+
104
+ )]
105
+ },
106
+ {
107
+ 'column' => 6,
108
+ 'expression' => 'x > 1.001 and x <= 5.001',
109
+ 'data' => [%w(
110
+ 9E 00 18 00 06 00 80 32 04 04 6A BC 74 93 18 04
111
+ F0 3F 04 03 1B 2F DD 24 06 01 14 40
112
+
113
+ )]
114
+ },
115
+ {
116
+ 'column' => 7,
117
+ 'expression' => 'x > 1.001 or x <= 5.001',
118
+ 'data' => [%w(
119
+ 9E 00 18 00 07 00 81 32 04 04 6A BC 74 93 18 04
120
+ F0 3F 04 03 1B 2F DD 24 06 01 14 40
121
+
122
+ )]
123
+ },
124
+ {
125
+ 'column' => 8,
126
+ 'expression' => 'x <> 2.001',
127
+ 'data' => [%w(
128
+ 9E 00 18 00 08 00 80 32 04 05 35 5E BA 49 0C 02
129
+ 00 40 00 00 00 00 00 00 00 00 00 00
130
+
131
+ )]
132
+ },
133
+ {
134
+ 'column' => 9,
135
+ 'expression' => 'x = 1.001',
136
+ 'data' => [%w(
137
+ 9E 00 1E 00 09 00 84 32 06 02 00 00 00 00 05 00
138
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 31 2E 30
139
+ 30 31
140
+
141
+ )]
142
+ },
143
+ {
144
+ 'column' => 10,
145
+ 'expression' => 'x = West',
146
+ 'data' => [%w(
147
+ 9E 00 1D 00 0A 00 84 32 06 02 00 00 00 00 04 00
148
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 57 65 73
149
+ 74
150
+
151
+ )]
152
+ },
153
+ {
154
+ 'column' => 11,
155
+ 'expression' => 'x = East',
156
+ 'data' => [%w(
157
+ 9E 00 1D 00 0B 00 84 32 06 02 00 00 00 00 04 00
158
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 45 61 73
159
+ 74
160
+
161
+ )]
162
+ },
163
+ {
164
+ 'column' => 12,
165
+ 'expression' => 'x <> West',
166
+ 'data' => [%w(
167
+ 9E 00 1D 00 0C 00 80 32 06 05 00 00 00 00 04 00
168
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 57 65 73
169
+ 74
170
+
171
+ )]
172
+ },
173
+ {
174
+ 'column' => 13,
175
+ 'expression' => 'x =~ b*',
176
+ 'data' => [%w(
177
+ 9E 00 1B 00 0D 00 80 32 06 02 00 00 00 00 02 00
178
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 62 2A
179
+
180
+ )]
181
+ },
182
+ {
183
+ 'column' => 14,
184
+ 'expression' => 'x !~ b*',
185
+ 'data' => [%w(
186
+ 9E 00 1B 00 0E 00 80 32 06 05 00 00 00 00 02 00
187
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 62 2A
188
+
189
+ )]
190
+ },
191
+ {
192
+ 'column' => 15,
193
+ 'expression' => 'x =~ *b',
194
+ 'data' => [%w(
195
+ 9E 00 1B 00 0F 00 80 32 06 02 00 00 00 00 02 00
196
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62
197
+
198
+ )]
199
+ },
200
+ {
201
+ 'column' => 16,
202
+ 'expression' => 'x !~ *b',
203
+ 'data' => [%w(
204
+ 9E 00 1B 00 10 00 80 32 06 05 00 00 00 00 02 00
205
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62
206
+
207
+ )]
208
+ },
209
+ {
210
+ 'column' => 17,
211
+ 'expression' => 'x =~ *b*',
212
+ 'data' => [%w(
213
+ 9E 00 1C 00 11 00 80 32 06 02 00 00 00 00 03 00
214
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62 2A
215
+
216
+ )]
217
+ },
218
+ {
219
+ 'column' => 18,
220
+ 'expression' => 'x !~ *b*',
221
+ 'data' => [%w(
222
+ 9E 00 1C 00 12 00 80 32 06 05 00 00 00 00 03 00
223
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62 2A
224
+
225
+ )]
226
+ },
227
+ {
228
+ 'column' => 19,
229
+ 'expression' => 'x = fo?',
230
+ 'data' => [%w(
231
+ 9E 00 1C 00 13 00 80 32 06 02 00 00 00 00 03 00
232
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 66 6F 3F
233
+
234
+ )]
235
+ },
236
+ {
237
+ 'column' => 20,
238
+ 'expression' => 'x = fo~?',
239
+ 'data' => [%w(
240
+ 9E 00 1D 00 14 00 80 32 06 02 00 00 00 00 04 00
241
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 66 6F 7E
242
+ 3F
243
+
244
+ )]
245
+ },
246
+ {
247
+ 'column' => 21,
248
+ 'expression' => 'x = East and x = West',
249
+ 'data' => [%w(
250
+ 9E 00 22 00 15 00 8C 32 06 02 00 00 00 00 04 00
251
+ 00 00 06 02 00 00 00 00 04 00 00 00 00 45 61 73
252
+ 74 00 57 65 73 74
253
+
254
+ )]
255
+ },
256
+ {
257
+ 'column' => 22,
258
+ 'expression' => 'top 10 items',
259
+ 'data' => [%w(
260
+ 9E 00 18 00 16 00 30 05 04 06 00 00 00 00 00 00
261
+ 00 00 00 00 00 00 00 00 00 00 00 00
262
+
263
+ )]
264
+ },
265
+ {
266
+ 'column' => 23,
267
+ 'expression' => 'top 10 %',
268
+ 'data' => [%w(
269
+ 9E 00 18 00 17 00 70 05 04 06 00 00 00 00 00 00
270
+ 00 00 00 00 00 00 00 00 00 00 00 00
271
+
272
+ )]
273
+ },
274
+ {
275
+ 'column' => 24,
276
+ 'expression' => 'bottom 10 items',
277
+ 'data' => [%w(
278
+ 9E 00 18 00 18 00 10 05 04 03 00 00 00 00 00 00
279
+ 00 00 00 00 00 00 00 00 00 00 00 00
280
+
281
+ )]
282
+ },
283
+ {
284
+ 'column' => 25,
285
+ 'expression' => 'bottom 10 %',
286
+ 'data' => [%w(
287
+ 9E 00 18 00 19 00 50 05 04 03 00 00 00 00 00 00
288
+ 00 00 00 00 00 00 00 00 00 00 00 00
289
+
290
+ )]
291
+ },
292
+ {
293
+ 'column' => 26,
294
+ 'expression' => 'top 5 items',
295
+ 'data' => [%w(
296
+ 9E 00 18 00 1A 00 B0 02 04 06 00 00 00 00 00 00
297
+ 00 00 00 00 00 00 00 00 00 00 00 00
298
+
299
+ )]
300
+ },
301
+ {
302
+ 'column' => 27,
303
+ 'expression' => 'top 100 items',
304
+ 'data' => [%w(
305
+ 9E 00 18 00 1B 00 30 32 04 06 00 00 00 00 00 00
306
+ 00 00 00 00 00 00 00 00 00 00 00 00
307
+
308
+ )]
309
+ },
310
+ {
311
+ 'column' => 28,
312
+ 'expression' => 'top 101 items',
313
+ 'data' => [%w(
314
+ 9E 00 18 00 1C 00 B0 32 04 06 00 00 00 00 00 00
315
+ 00 00 00 00 00 00 00 00 00 00 00 00
316
+
317
+ )]
318
+ }
319
+ ]
320
+ end
321
+
322
+ def teardown
323
+ @workbook.close
324
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
325
+ end
326
+
327
+ end
@@ -0,0 +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 = Spreadsheet::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