caxlsx 3.1.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -1
  3. data/README.md +4 -11
  4. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  5. data/lib/axlsx/doc_props/app.rb +1 -1
  6. data/lib/axlsx/drawing/chart.rb +25 -2
  7. data/lib/axlsx/drawing/d_lbls.rb +3 -2
  8. data/lib/axlsx/drawing/scatter_series.rb +31 -0
  9. data/lib/axlsx/drawing/title.rb +11 -1
  10. data/lib/axlsx/drawing/view_3D.rb +1 -1
  11. data/lib/axlsx/package.rb +15 -5
  12. data/lib/axlsx/rels/relationship.rb +1 -1
  13. data/lib/axlsx/stylesheet/border.rb +2 -0
  14. data/lib/axlsx/stylesheet/font.rb +1 -1
  15. data/lib/axlsx/stylesheet/styles.rb +139 -24
  16. data/lib/axlsx/util/constants.rb +16 -1
  17. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  18. data/lib/axlsx/util/storage.rb +9 -9
  19. data/lib/axlsx/version.rb +1 -1
  20. data/lib/axlsx/workbook/workbook.rb +55 -0
  21. data/lib/axlsx/workbook/worksheet/border_creator.rb +76 -0
  22. data/lib/axlsx/workbook/worksheet/cell.rb +29 -2
  23. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  24. data/lib/axlsx/workbook/worksheet/col.rb +4 -4
  25. data/lib/axlsx/workbook/worksheet/data_validation.rb +26 -5
  26. data/lib/axlsx/workbook/worksheet/pivot_table.rb +55 -14
  27. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +1 -1
  28. data/lib/axlsx/workbook/worksheet/worksheet.rb +68 -7
  29. data/lib/axlsx.rb +43 -10
  30. metadata +6 -253
  31. data/test/benchmark.rb +0 -72
  32. data/test/content_type/tc_content_type.rb +0 -76
  33. data/test/content_type/tc_default.rb +0 -16
  34. data/test/content_type/tc_override.rb +0 -14
  35. data/test/doc_props/tc_app.rb +0 -43
  36. data/test/doc_props/tc_core.rb +0 -42
  37. data/test/drawing/tc_area_chart.rb +0 -39
  38. data/test/drawing/tc_area_series.rb +0 -71
  39. data/test/drawing/tc_axes.rb +0 -8
  40. data/test/drawing/tc_axis.rb +0 -112
  41. data/test/drawing/tc_bar_3D_chart.rb +0 -86
  42. data/test/drawing/tc_bar_chart.rb +0 -86
  43. data/test/drawing/tc_bar_series.rb +0 -46
  44. data/test/drawing/tc_bubble_chart.rb +0 -44
  45. data/test/drawing/tc_bubble_series.rb +0 -21
  46. data/test/drawing/tc_cat_axis.rb +0 -31
  47. data/test/drawing/tc_cat_axis_data.rb +0 -27
  48. data/test/drawing/tc_chart.rb +0 -123
  49. data/test/drawing/tc_d_lbls.rb +0 -57
  50. data/test/drawing/tc_data_source.rb +0 -23
  51. data/test/drawing/tc_drawing.rb +0 -80
  52. data/test/drawing/tc_graphic_frame.rb +0 -27
  53. data/test/drawing/tc_hyperlink.rb +0 -64
  54. data/test/drawing/tc_line_3d_chart.rb +0 -47
  55. data/test/drawing/tc_line_chart.rb +0 -39
  56. data/test/drawing/tc_line_series.rb +0 -71
  57. data/test/drawing/tc_marker.rb +0 -44
  58. data/test/drawing/tc_named_axis_data.rb +0 -27
  59. data/test/drawing/tc_num_data.rb +0 -31
  60. data/test/drawing/tc_num_val.rb +0 -29
  61. data/test/drawing/tc_one_cell_anchor.rb +0 -66
  62. data/test/drawing/tc_pic.rb +0 -103
  63. data/test/drawing/tc_picture_locking.rb +0 -72
  64. data/test/drawing/tc_pie_3D_chart.rb +0 -28
  65. data/test/drawing/tc_pie_series.rb +0 -33
  66. data/test/drawing/tc_scaling.rb +0 -36
  67. data/test/drawing/tc_scatter_chart.rb +0 -48
  68. data/test/drawing/tc_scatter_series.rb +0 -56
  69. data/test/drawing/tc_ser_axis.rb +0 -31
  70. data/test/drawing/tc_series.rb +0 -23
  71. data/test/drawing/tc_series_title.rb +0 -54
  72. data/test/drawing/tc_str_data.rb +0 -18
  73. data/test/drawing/tc_str_val.rb +0 -30
  74. data/test/drawing/tc_title.rb +0 -70
  75. data/test/drawing/tc_two_cell_anchor.rb +0 -36
  76. data/test/drawing/tc_val_axis.rb +0 -24
  77. data/test/drawing/tc_view_3D.rb +0 -54
  78. data/test/drawing/tc_vml_drawing.rb +0 -25
  79. data/test/drawing/tc_vml_shape.rb +0 -106
  80. data/test/fixtures/image1.gif +0 -0
  81. data/test/fixtures/image1.jpeg +0 -0
  82. data/test/fixtures/image1.jpg +0 -0
  83. data/test/fixtures/image1.png +0 -0
  84. data/test/fixtures/image1_fake.jpg +0 -0
  85. data/test/profile.rb +0 -24
  86. data/test/rels/tc_relationship.rb +0 -52
  87. data/test/rels/tc_relationships.rb +0 -37
  88. data/test/stylesheet/tc_border.rb +0 -37
  89. data/test/stylesheet/tc_border_pr.rb +0 -32
  90. data/test/stylesheet/tc_cell_alignment.rb +0 -81
  91. data/test/stylesheet/tc_cell_protection.rb +0 -29
  92. data/test/stylesheet/tc_cell_style.rb +0 -57
  93. data/test/stylesheet/tc_color.rb +0 -43
  94. data/test/stylesheet/tc_dxf.rb +0 -81
  95. data/test/stylesheet/tc_fill.rb +0 -18
  96. data/test/stylesheet/tc_font.rb +0 -133
  97. data/test/stylesheet/tc_gradient_fill.rb +0 -72
  98. data/test/stylesheet/tc_gradient_stop.rb +0 -31
  99. data/test/stylesheet/tc_num_fmt.rb +0 -30
  100. data/test/stylesheet/tc_pattern_fill.rb +0 -43
  101. data/test/stylesheet/tc_styles.rb +0 -261
  102. data/test/stylesheet/tc_table_style.rb +0 -44
  103. data/test/stylesheet/tc_table_style_element.rb +0 -45
  104. data/test/stylesheet/tc_table_styles.rb +0 -29
  105. data/test/stylesheet/tc_xf.rb +0 -120
  106. data/test/tc_axlsx.rb +0 -109
  107. data/test/tc_helper.rb +0 -10
  108. data/test/tc_package.rb +0 -314
  109. data/test/util/tc_mime_type_utils.rb +0 -13
  110. data/test/util/tc_serialized_attributes.rb +0 -19
  111. data/test/util/tc_simple_typed_list.rb +0 -77
  112. data/test/util/tc_validators.rb +0 -210
  113. data/test/workbook/tc_defined_name.rb +0 -49
  114. data/test/workbook/tc_shared_strings_table.rb +0 -59
  115. data/test/workbook/tc_workbook.rb +0 -160
  116. data/test/workbook/tc_workbook_view.rb +0 -50
  117. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +0 -38
  118. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +0 -76
  119. data/test/workbook/worksheet/auto_filter/tc_filters.rb +0 -50
  120. data/test/workbook/worksheet/tc_break.rb +0 -49
  121. data/test/workbook/worksheet/tc_cell.rb +0 -453
  122. data/test/workbook/worksheet/tc_cfvo.rb +0 -31
  123. data/test/workbook/worksheet/tc_col.rb +0 -93
  124. data/test/workbook/worksheet/tc_color_scale.rb +0 -58
  125. data/test/workbook/worksheet/tc_comment.rb +0 -72
  126. data/test/workbook/worksheet/tc_comments.rb +0 -57
  127. data/test/workbook/worksheet/tc_conditional_formatting.rb +0 -224
  128. data/test/workbook/worksheet/tc_data_bar.rb +0 -46
  129. data/test/workbook/worksheet/tc_data_validation.rb +0 -265
  130. data/test/workbook/worksheet/tc_date_time_converter.rb +0 -124
  131. data/test/workbook/worksheet/tc_header_footer.rb +0 -151
  132. data/test/workbook/worksheet/tc_icon_set.rb +0 -45
  133. data/test/workbook/worksheet/tc_outline_pr.rb +0 -19
  134. data/test/workbook/worksheet/tc_page_margins.rb +0 -97
  135. data/test/workbook/worksheet/tc_page_set_up_pr.rb +0 -15
  136. data/test/workbook/worksheet/tc_page_setup.rb +0 -143
  137. data/test/workbook/worksheet/tc_pane.rb +0 -54
  138. data/test/workbook/worksheet/tc_pivot_table.rb +0 -143
  139. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +0 -62
  140. data/test/workbook/worksheet/tc_print_options.rb +0 -72
  141. data/test/workbook/worksheet/tc_protected_range.rb +0 -17
  142. data/test/workbook/worksheet/tc_rich_text.rb +0 -44
  143. data/test/workbook/worksheet/tc_rich_text_run.rb +0 -173
  144. data/test/workbook/worksheet/tc_row.rb +0 -160
  145. data/test/workbook/worksheet/tc_selection.rb +0 -55
  146. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +0 -18
  147. data/test/workbook/worksheet/tc_sheet_format_pr.rb +0 -88
  148. data/test/workbook/worksheet/tc_sheet_pr.rb +0 -49
  149. data/test/workbook/worksheet/tc_sheet_protection.rb +0 -117
  150. data/test/workbook/worksheet/tc_sheet_view.rb +0 -214
  151. data/test/workbook/worksheet/tc_table.rb +0 -77
  152. data/test/workbook/worksheet/tc_table_style_info.rb +0 -53
  153. data/test/workbook/worksheet/tc_worksheet.rb +0 -601
  154. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +0 -55
@@ -1,453 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestCell < Test::Unit::TestCase
4
-
5
- def setup
6
- p = Axlsx::Package.new
7
- p.use_shared_strings = true
8
- @ws = p.workbook.add_worksheet :name=>"hmmm"
9
- p.workbook.styles.add_style :sz=>20
10
- @row = @ws.add_row
11
- @c = @row.add_cell 1, :type=>:float, :style=>1, :escape_formulas=>true
12
- data = (0..26).map { |index| index }
13
- @ws.add_row data
14
- @cAA = @ws["AA2"]
15
- end
16
-
17
- def test_initialize
18
- assert_equal(@row.cells.last, @c, "the cell was added to the row")
19
- assert_equal(@c.type, :float, "type option is applied")
20
- assert_equal(@c.style, 1, "style option is applied")
21
- assert_equal(@c.value, 1.0, "type option is applied and value is casted")
22
- assert_equal(@c.escape_formulas, true, "escape formulas option is applied")
23
- end
24
-
25
- def test_style_date_data
26
- c = Axlsx::Cell.new(@c.row, Time.now)
27
- assert_equal(Axlsx::STYLE_DATE, c.style)
28
- end
29
-
30
- def test_row
31
- assert_equal(@c.row, @row)
32
- end
33
-
34
- def test_index
35
- assert_equal(@c.index, @row.cells.index(@c))
36
- end
37
-
38
- def test_pos
39
- assert_equal(@c.pos, [@c.index, @c.row.index(@c)])
40
- end
41
-
42
- def test_r
43
- assert_equal(@c.r, "A1", "calculate cell reference")
44
- end
45
-
46
- def test_wide_r
47
- assert_equal(@cAA.r, "AA2", "calculate cell reference")
48
- end
49
-
50
- def test_r_abs
51
- assert_equal(@c.r_abs,"$A$1", "calculate absolute cell reference")
52
- assert_equal(@cAA.r_abs,"$AA$2", "needs to accept multi-digit columns")
53
- end
54
-
55
- def test_name
56
- @c.name = 'foo'
57
- assert_equal(1, @ws.workbook.defined_names.size)
58
- assert_equal('foo', @ws.workbook.defined_names.last.name)
59
- end
60
-
61
- def test_autowidth
62
- style = @c.row.worksheet.workbook.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} )
63
- @c.style = style
64
- assert_in_delta(6.6, @c.autowidth, 0.01)
65
- end
66
-
67
- def test_time
68
- @c.type = :time
69
- now = DateTime.now
70
- @c.value = now
71
- assert_equal(@c.value, now.to_time)
72
- end
73
-
74
- def test_date
75
- @c.type = :date
76
- now = Time.now
77
- @c.value = now
78
- assert_equal(@c.value, now.to_date)
79
- end
80
-
81
- def test_style
82
- assert_raise(ArgumentError, "must reject invalid style indexes") { @c.style=@c.row.worksheet.workbook.styles.cellXfs.size }
83
- assert_nothing_raised("must allow valid style index changes") {@c.style=1}
84
- assert_equal(@c.style, 1)
85
- end
86
-
87
- def test_type
88
- assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
89
- assert_nothing_raised("type can be changed") { @c.type = :string }
90
- assert_equal(@c.value, "1.0", "changing type casts the value")
91
- assert_equal(:float, @row.add_cell(1.0/10**7).type, 'properly identify exponential floats as float type')
92
- assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
93
- assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date')
94
- assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean')
95
- end
96
-
97
- def test_value
98
- assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
99
- assert_nothing_raised("type can be changed") { @c.type = :string }
100
- assert_equal(@c.value, "1.0", "changing type casts the value")
101
- end
102
-
103
- def test_col_ref
104
- #TODO move to axlsx spec
105
- assert_equal(Axlsx.col_ref(0), "A")
106
- end
107
-
108
- def test_cell_type_from_value
109
- assert_equal(@c.send(:cell_type_from_value, 1.0), :float)
110
- assert_equal(@c.send(:cell_type_from_value, "1e1"), :float)
111
- assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP}"), :float)
112
- assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP + 1}"), :string)
113
- assert_equal(@c.send(:cell_type_from_value, "1e-1"), :float)
114
- assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP}"), :float)
115
- assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP - 1}"), :string)
116
- assert_equal(@c.send(:cell_type_from_value, 1), :integer)
117
- assert_equal(@c.send(:cell_type_from_value, Date.today), :date)
118
- assert_equal(@c.send(:cell_type_from_value, Time.now), :time)
119
- assert_equal(@c.send(:cell_type_from_value, []), :string)
120
- assert_equal(@c.send(:cell_type_from_value, "d"), :string)
121
- assert_equal(@c.send(:cell_type_from_value, nil), :string)
122
- assert_equal(@c.send(:cell_type_from_value, -1), :integer)
123
- assert_equal(@c.send(:cell_type_from_value, true), :boolean)
124
- assert_equal(@c.send(:cell_type_from_value, false), :boolean)
125
- assert_equal(@c.send(:cell_type_from_value, 1.0/10**6), :float)
126
- assert_equal(@c.send(:cell_type_from_value, Axlsx::RichText.new), :richtext)
127
- assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00'))
128
- end
129
-
130
- def test_cell_type_from_value_looks_like_number_but_is_not
131
- mimic_number = Class.new do
132
- def initialize(to_s_value)
133
- @to_s_value = to_s_value
134
- end
135
-
136
- def to_s
137
- @to_s_value
138
- end
139
- end
140
-
141
- number_strings = [
142
- '1',
143
- '1234567890',
144
- '1.0',
145
- '1e1',
146
- '0',
147
- "1e#{Float::MIN_10_EXP}"
148
- ]
149
-
150
- number_strings.each do |number_string|
151
- assert_equal(@c.send(:cell_type_from_value, mimic_number.new(number_string)), :string)
152
- end
153
- end
154
-
155
- def test_cast_value
156
- @c.type = :string
157
- assert_equal(@c.send(:cast_value, 1.0), "1.0")
158
- @c.type = :integer
159
- assert_equal(@c.send(:cast_value, 1.0), 1)
160
- @c.type = :float
161
- assert_equal(@c.send(:cast_value, "1.0"), 1.0)
162
- @c.type = :string
163
- assert_equal(@c.send(:cast_value, nil), nil)
164
- @c.type = :richtext
165
- assert_equal(@c.send(:cast_value, nil), nil)
166
- @c.type = :float
167
- assert_equal(@c.send(:cast_value, nil), nil)
168
- @c.type = :boolean
169
- assert_equal(@c.send(:cast_value, true), 1)
170
- assert_equal(@c.send(:cast_value, false), 0)
171
- @c.type = :iso_8601
172
- assert_equal("2012-10-10T12:24", @c.send(:cast_value, "2012-10-10T12:24"))
173
- end
174
-
175
- def test_cast_time_subclass
176
- subtime = Class.new(Time) do
177
- def to_time
178
- raise "#to_time of Time subclass should not be called"
179
- end
180
- end
181
-
182
- time = subtime.now
183
-
184
- @c.type = :time
185
- assert_equal(time, @c.send(:cast_value, time))
186
- end
187
-
188
- def test_color
189
- assert_raise(ArgumentError) { @c.color = -1.1 }
190
- assert_nothing_raised { @c.color = "FF00FF00" }
191
- assert_equal(@c.color.rgb, "FF00FF00")
192
- end
193
-
194
- def test_scheme
195
- assert_raise(ArgumentError) { @c.scheme = -1.1 }
196
- assert_nothing_raised { @c.scheme = :major }
197
- assert_equal(@c.scheme, :major)
198
- end
199
-
200
- def test_vertAlign
201
- assert_raise(ArgumentError) { @c.vertAlign = -1.1 }
202
- assert_nothing_raised { @c.vertAlign = :baseline }
203
- assert_equal(@c.vertAlign, :baseline)
204
- end
205
-
206
- def test_sz
207
- assert_raise(ArgumentError) { @c.sz = -1.1 }
208
- assert_nothing_raised { @c.sz = 12 }
209
- assert_equal(@c.sz, 12)
210
- end
211
-
212
- def test_extend
213
- assert_raise(ArgumentError) { @c.extend = -1.1 }
214
- assert_nothing_raised { @c.extend = false }
215
- assert_equal(@c.extend, false)
216
- end
217
-
218
- def test_condense
219
- assert_raise(ArgumentError) { @c.condense = -1.1 }
220
- assert_nothing_raised { @c.condense = false }
221
- assert_equal(@c.condense, false)
222
- end
223
-
224
- def test_shadow
225
- assert_raise(ArgumentError) { @c.shadow = -1.1 }
226
- assert_nothing_raised { @c.shadow = false }
227
- assert_equal(@c.shadow, false)
228
- end
229
-
230
- def test_outline
231
- assert_raise(ArgumentError) { @c.outline = -1.1 }
232
- assert_nothing_raised { @c.outline = false }
233
- assert_equal(@c.outline, false)
234
- end
235
-
236
- def test_strike
237
- assert_raise(ArgumentError) { @c.strike = -1.1 }
238
- assert_nothing_raised { @c.strike = false }
239
- assert_equal(@c.strike, false)
240
- end
241
-
242
- def test_u
243
- @c.type = :string
244
- assert_raise(ArgumentError) { @c.u = -1.1 }
245
- assert_nothing_raised { @c.u = :single }
246
- assert_equal(@c.u, :single)
247
- doc = Nokogiri::XML(@c.to_xml_string(1,1))
248
- assert(doc.xpath('//u[@val="single"]'))
249
- end
250
-
251
- def test_i
252
- assert_raise(ArgumentError) { @c.i = -1.1 }
253
- assert_nothing_raised { @c.i = false }
254
- assert_equal(@c.i, false)
255
- end
256
-
257
- def test_rFont
258
- assert_raise(ArgumentError) { @c.font_name = -1.1 }
259
- assert_nothing_raised { @c.font_name = "Arial" }
260
- assert_equal(@c.font_name, "Arial")
261
- end
262
-
263
- def test_charset
264
- assert_raise(ArgumentError) { @c.charset = -1.1 }
265
- assert_nothing_raised { @c.charset = 1 }
266
- assert_equal(@c.charset, 1)
267
- end
268
-
269
- def test_family
270
- assert_raise(ArgumentError) { @c.family = -1.1 }
271
- assert_nothing_raised { @c.family = 5 }
272
- assert_equal(@c.family, 5)
273
- end
274
-
275
- def test_b
276
- assert_raise(ArgumentError) { @c.b = -1.1 }
277
- assert_nothing_raised { @c.b = false }
278
- assert_equal(@c.b, false)
279
- end
280
-
281
- def test_merge_with_string
282
- @c.row.add_cell 2
283
- @c.row.add_cell 3
284
- @c.merge "A2"
285
- assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:A2")
286
- end
287
-
288
- def test_merge_with_cell
289
- @c.row.add_cell 2
290
- @c.row.add_cell 3
291
- @c.merge @row.cells.last
292
- assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
293
- end
294
-
295
- def test_reverse_merge_with_cell
296
- @c.row.add_cell 2
297
- @c.row.add_cell 3
298
- @row.cells.last.merge @c
299
- assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
300
- end
301
-
302
- def test_ssti
303
- assert_raise(ArgumentError, "ssti must be an unsigned integer!") { @c.send(:ssti=, -1) }
304
- @c.send :ssti=, 1
305
- assert_equal(@c.ssti, 1)
306
- end
307
-
308
- def test_plain_string
309
- @c.type = :integer
310
- assert_equal(@c.plain_string?, false)
311
-
312
- @c.type = :string
313
- @c.value = 'plain string'
314
- assert_equal(@c.plain_string?, true)
315
-
316
- @c.value = nil
317
- assert_equal(@c.plain_string?, false)
318
-
319
- @c.value = ''
320
- assert_equal(@c.plain_string?, false)
321
-
322
- @c.value = '=sum'
323
- assert_equal(@c.plain_string?, false)
324
-
325
- @c.value = 'plain string'
326
- @c.font_name = 'Arial'
327
- assert_equal(@c.plain_string?, false)
328
- end
329
-
330
- def test_to_xml_string
331
- c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
332
- assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
333
- end
334
-
335
- def test_to_xml_string_nil
336
- @c.value = nil
337
- c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
338
- assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
339
- end
340
-
341
- def test_to_xml_string_with_run
342
- # Actually quite a number of similar run styles
343
- # but the processing should be the same
344
- @c.b = true
345
- @c.type = :string
346
- @c.value = "a"
347
- @c.font_name = 'arial'
348
- @c.color = 'FF0000'
349
- c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
350
- assert(c_xml.xpath("//b").any?)
351
- end
352
-
353
- def test_to_xml_string_formula
354
- p = Axlsx::Package.new
355
- ws = p.workbook.add_worksheet do |sheet|
356
- sheet.add_row ["=IF(2+2=4,4,5)"]
357
- end
358
- doc = Nokogiri::XML(ws.to_xml_string)
359
- doc.remove_namespaces!
360
- assert(doc.xpath("//f[text()='IF(2+2=4,4,5)']").any?)
361
- end
362
-
363
- def test_to_xml_string_formula_escaped
364
- p = Axlsx::Package.new
365
- ws = p.workbook.add_worksheet do |sheet|
366
- sheet.add_row ["=IF(2+2=4,4,5)"], escape_formulas: true
367
- end
368
- doc = Nokogiri::XML(ws.to_xml_string)
369
- doc.remove_namespaces!
370
- assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?)
371
- end
372
-
373
- def test_to_xml_string_formula_escape_array_parameter
374
- p = Axlsx::Package.new
375
- ws = p.workbook.add_worksheet do |sheet|
376
- sheet.add_row [
377
- "=IF(2+2=4,4,5)",
378
- "=IF(13+13=4,4,5)",
379
- "=IF(99+99=4,4,5)"
380
- ], escape_formulas: [true, false, true]
381
- end
382
- doc = Nokogiri::XML(ws.to_xml_string)
383
- doc.remove_namespaces!
384
-
385
- assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?)
386
- assert(doc.xpath("//f[text()='IF(13+13=4,4,5)']").any?)
387
- assert(doc.xpath("//t[text()='=IF(99+99=4,4,5)']").any?)
388
- end
389
-
390
- def test_to_xml_string_array_formula
391
- p = Axlsx::Package.new
392
- ws = p.workbook.add_worksheet do |sheet|
393
- sheet.add_row ["{=SUM(C2:C11*D2:D11)}"]
394
- end
395
- doc = Nokogiri::XML(ws.to_xml_string)
396
- doc.remove_namespaces!
397
- assert(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']").any?)
398
- assert(doc.xpath("//f[@t='array']").any?)
399
- assert(doc.xpath("//f[@ref='A1']").any?)
400
- end
401
-
402
- def test_to_xml_string_text_formula
403
- p = Axlsx::Package.new
404
- ws = p.workbook.add_worksheet do |sheet|
405
- sheet.add_row ["=1+1", "-1+1"], type: :text
406
- end
407
- doc = Nokogiri::XML(ws.to_xml_string)
408
- doc.remove_namespaces!
409
-
410
- assert(doc.xpath("//f[text()='1+1']").empty?)
411
- assert(doc.xpath("//t[text()='=1+1']").any?)
412
-
413
- assert(doc.xpath("//f[text()='1+1']").empty?)
414
- assert(doc.xpath("//t[text()='-1+1']").any?)
415
- end
416
-
417
- def test_font_size_with_custom_style_and_no_sz
418
- @c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
419
- sz = @c.send(:font_size)
420
- assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz)
421
- end
422
-
423
- def test_font_size_with_bolding
424
- @c.style = @c.row.worksheet.workbook.styles.add_style :b => true
425
- assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @c.send(:font_size))
426
- end
427
-
428
- def test_font_size_with_custom_sz
429
- @c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52
430
- sz = @c.send(:font_size)
431
- assert_equal(sz, 52)
432
- end
433
-
434
- def test_cell_with_sz
435
- @c.sz = 25
436
- assert_equal(25, @c.send(:font_size))
437
- end
438
-
439
- def test_to_xml
440
- # TODO This could use some much more stringent testing related to the xml content generated!
441
- @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)", "2013-01-13T13:31:25.123"]
442
- @ws.rows.last.cells[5].u = true
443
-
444
- schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
445
- doc = Nokogiri::XML(@ws.to_xml_string)
446
- errors = []
447
- schema.validate(doc).each do |error|
448
- errors.push error
449
- puts error.message
450
- end
451
- assert(errors.empty?, "error free validation")
452
- end
453
- end
@@ -1,31 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestCfvo < Test::Unit::TestCase
4
- def setup
5
- @cfvo = Axlsx::Cfvo.new(:val => "0", :type => :min)
6
- end
7
-
8
- def test_val
9
- assert_nothing_raised { @cfvo.val = "abc" }
10
- assert_equal(@cfvo.val, "abc")
11
- end
12
-
13
- def test_type
14
- assert_raise(ArgumentError) { @cfvo.type = :invalid_type }
15
- assert_nothing_raised { @cfvo.type = :max }
16
- assert_equal(@cfvo.type, :max)
17
- end
18
-
19
- def test_gte
20
- assert_raise(ArgumentError) { @cfvo.gte = :bob }
21
- assert_equal(@cfvo.gte, true)
22
- assert_nothing_raised { @cfvo.gte = false }
23
- assert_equal(@cfvo.gte, false)
24
- end
25
-
26
- def test_to_xml_string
27
- doc = Nokogiri::XML.parse(@cfvo.to_xml_string)
28
- assert doc.xpath(".//cfvo[@type='min'][@val=0][@gte=true]")
29
- end
30
-
31
- end
@@ -1,93 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestCol < Test::Unit::TestCase
4
-
5
- def setup
6
- @col = Axlsx::Col.new 1, 1
7
- end
8
-
9
- def test_initialize
10
- options = { :width => 12, :collapsed => true, :hidden => true, :outline_level => 1, :phonetic => true, :style => 1}
11
-
12
- col = Axlsx::Col.new 0, 0, options
13
- options.each{ |key, value| assert_equal(col.send(key.to_sym), value) }
14
- end
15
-
16
- def test_min_max_required
17
- assert_raise(ArgumentError, 'min and max must be specified when creating a new column') { Axlsx::Col.new }
18
- assert_raise(ArgumentError, 'min and max must be specified when creating a new column') { Axlsx::Col.new nil, nil }
19
- assert_nothing_raised { Axlsx::Col.new 1, 1 }
20
- end
21
-
22
- def test_bestFit
23
- assert_equal(@col.bestFit, nil)
24
- assert_raise(NoMethodError, 'bestFit is read only') { @col.bestFit = 'bob' }
25
- @col.width = 1.999
26
- assert_equal(@col.bestFit, true, 'bestFit should be true when width has been set')
27
- end
28
-
29
- def test_collapsed
30
- assert_equal(@col.collapsed, nil)
31
- assert_raise(ArgumentError, 'collapsed must be boolean(ish)') { @col.collapsed = 'bob' }
32
- assert_nothing_raised('collapsed must be boolean(ish)') { @col.collapsed = true }
33
- end
34
-
35
- def test_customWidth
36
- assert_equal(@col.customWidth, nil)
37
- @col.width = 3
38
- assert_raise(NoMethodError, 'customWidth is read only') { @col.customWidth = 3 }
39
- assert_equal(@col.customWidth, true, 'customWidth is true when width is set')
40
- end
41
-
42
- def test_widthUnderLimit
43
- @col.width = 3
44
- assert_equal(@col.width, 3, 'width is set to exact value')
45
- end
46
-
47
- def test_widthOverLimit
48
- @col.width = 31337
49
- assert_equal(@col.width, 255, 'width is set to maximum allowed value')
50
- end
51
-
52
- def test_widthSetToNil
53
- @col.width = nil
54
- assert_equal(@col.width, nil, 'width is set to unspecified value')
55
- end
56
-
57
- def test_hidden
58
- assert_equal(@col.hidden, nil)
59
- assert_raise(ArgumentError, 'hidden must be boolean(ish)') { @col.hidden = 'bob' }
60
- assert_nothing_raised(ArgumentError, 'hidden must be boolean(ish)') { @col.hidden = true }
61
- end
62
-
63
- def test_outlineLevel
64
- assert_equal(@col.outlineLevel, nil)
65
- assert_raise(ArgumentError, 'outline level cannot be negative') { @col.outlineLevel = -1 }
66
- assert_raise(ArgumentError, 'outline level cannot be greater than 7') { @col.outlineLevel = 8 }
67
- assert_nothing_raised('can set outlineLevel') { @col.outlineLevel = 1 }
68
- end
69
-
70
- def test_phonetic
71
- assert_equal(@col.phonetic, nil)
72
- assert_raise(ArgumentError, 'phonetic must be boolean(ish)') { @col.phonetic = 'bob' }
73
- assert_nothing_raised(ArgumentError, 'phonetic must be boolean(ish)') { @col.phonetic = true }
74
- end
75
-
76
- def test_to_xml_string
77
- @col.width = 100
78
- doc = Nokogiri::XML(@col.to_xml_string)
79
- assert_equal(1, doc.xpath("//col [@bestFit='#{@col.best_fit ? 1 : 0}']").size)
80
- assert_equal(1, doc.xpath("//col [@max=#{@col.max}]").size)
81
- assert_equal(1, doc.xpath("//col [@min=#{@col.min}]").size)
82
- assert_equal(1, doc.xpath("//col [@width=#{@col.width}]").size)
83
- assert_equal(1, doc.xpath("//col [@customWidth='#{@col.custom_width ? 1 : 0}']").size)
84
- end
85
-
86
- def test_style
87
- assert_equal(@col.style, nil)
88
- @col.style = 1
89
- assert_equal(@col.style, 1)
90
- #TODO check that the style specified is actually in the styles xfs collection
91
- end
92
-
93
- end
@@ -1,58 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestColorScale < Test::Unit::TestCase
4
- def setup
5
- @color_scale = Axlsx::ColorScale.new
6
- end
7
-
8
- def test_three_tone
9
- color_scale = Axlsx::ColorScale.three_tone
10
- assert_equal 3, color_scale.value_objects.size
11
- assert_equal 3, color_scale.colors.size
12
- end
13
-
14
- def test_two_tone
15
- color_scale = Axlsx::ColorScale.two_tone
16
- assert_equal 2, color_scale.value_objects.size
17
- assert_equal 2, color_scale.colors.size
18
- end
19
- def test_default_cfvo
20
- first = Axlsx::ColorScale.default_cfvos.first
21
- second = Axlsx::ColorScale.default_cfvos.last
22
- assert_equal 'FFFF7128', first[:color]
23
- assert_equal :min,first[:type]
24
- assert_equal 0, first[:val]
25
-
26
- assert_equal 'FFFFEF9C', second[:color]
27
- assert_equal :max, second[:type]
28
- assert_equal 0, second[:val]
29
- end
30
-
31
- def test_partial_default_cfvo_override
32
- first_def = {:type => :percent, :val => "10.0", :color => 'FF00FF00'}
33
- color_scale = Axlsx::ColorScale.new(first_def)
34
- assert_equal color_scale.value_objects.first.val, first_def[:val]
35
- assert_equal color_scale.value_objects.first.type, first_def[:type]
36
- assert_equal color_scale.colors.first.rgb, first_def[:color]
37
- end
38
-
39
- def test_add
40
- @color_scale.add :type => :max, :val => 5, :color => "FFDEDEDE"
41
- assert_equal(@color_scale.value_objects.size,3)
42
- assert_equal(@color_scale.colors.size,3)
43
- end
44
-
45
- def test_delete_at
46
- @color_scale.add :type => :max, :val => 5, :color => "FFDEDEDE"
47
- assert_nothing_raised {@color_scale.delete_at 2}
48
- assert_equal(@color_scale.value_objects.size,2)
49
- assert_equal(@color_scale.colors.size,2)
50
- end
51
-
52
- def test_to_xml_string
53
- doc = Nokogiri::XML.parse(@color_scale.to_xml_string)
54
- assert_equal(doc.xpath(".//colorScale//cfvo").size, 2)
55
- assert_equal(doc.xpath(".//colorScale//color").size, 2)
56
- end
57
-
58
- end
@@ -1,72 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestComment < Test::Unit::TestCase
4
- def setup
5
- p = Axlsx::Package.new
6
- wb = p.workbook
7
- @ws = wb.add_worksheet
8
- @c1 = @ws.add_comment :ref => 'A1', :text => 'text with special char <', :author => 'author with special char <', :visible => false
9
- @c2 = @ws.add_comment :ref => 'C3', :text => 'rust bucket', :author => 'PO'
10
- end
11
-
12
- def test_initailize
13
- assert_raise(ArgumentError) { Axlsx::Comment.new }
14
- end
15
-
16
- def test_author
17
- assert(@c1.author == 'author with special char <')
18
- assert(@c2.author == 'PO')
19
- end
20
-
21
- def test_text
22
- assert(@c1.text == 'text with special char <')
23
- assert(@c2.text == 'rust bucket')
24
- end
25
-
26
- def test_author_index
27
- assert_equal(@c1.author_index, 1)
28
- assert_equal(@c2.author_index, 0)
29
- end
30
-
31
- def test_visible
32
- assert_equal(false, @c1.visible)
33
- assert_equal(true, @c2.visible)
34
- end
35
- def test_ref
36
- assert(@c1.ref == 'A1')
37
- assert(@c2.ref == 'C3')
38
- end
39
-
40
- def test_vml_shape
41
- pos = Axlsx::name_to_indices(@c1.ref)
42
- assert(@c1.vml_shape.is_a?(Axlsx::VmlShape))
43
- assert(@c1.vml_shape.column == pos[0])
44
- assert(@c1.vml_shape.row == pos[1])
45
- assert(@c1.vml_shape.row == pos[1])
46
- assert_equal(pos[0], @c1.vml_shape.left_column)
47
- assert(@c1.vml_shape.top_row == pos[1])
48
- assert_equal(pos[0] + 2 , @c1.vml_shape.right_column)
49
- assert(@c1.vml_shape.bottom_row == pos[1]+4)
50
- end
51
-
52
- def test_to_xml_string
53
- doc = Nokogiri::XML(@c1.to_xml_string)
54
- assert_equal(doc.xpath("//comment[@ref='#{@c1.ref}']").size, 1)
55
- assert_equal(doc.xpath("//comment[@authorId='#{@c1.author_index.to_s}']").size, 1)
56
- assert_equal(doc.xpath("//t[text()='#{@c1.author}:\n']").size, 1)
57
- assert_equal(doc.xpath("//t[text()='#{@c1.text}']").size, 1)
58
- end
59
-
60
- def test_comment_text_contain_author_and_text
61
- comment = @ws.add_comment :ref => 'C4', :text => 'some text', :author => 'Bob'
62
- doc = Nokogiri::XML(comment.to_xml_string)
63
- assert_equal("Bob:\nsome text", doc.xpath("//comment/text").text)
64
- end
65
-
66
- def test_comment_text_does_not_contain_stray_colon_if_author_blank
67
- comment = @ws.add_comment :ref => 'C5', :text => 'some text', :author => ''
68
- doc = Nokogiri::XML(comment.to_xml_string)
69
- assert_equal("some text", doc.xpath("//comment/text").text)
70
- end
71
- end
72
-