caxlsx 3.1.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (294) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -9
  3. data/.yardopts_guide +18 -18
  4. data/CHANGELOG.md +354 -343
  5. data/LICENSE +21 -21
  6. data/README.md +168 -172
  7. data/Rakefile +29 -29
  8. data/examples/generate.rb +15 -15
  9. data/lib/axlsx/content_type/abstract_content_type.rb +32 -32
  10. data/lib/axlsx/content_type/content_type.rb +26 -26
  11. data/lib/axlsx/content_type/default.rb +25 -25
  12. data/lib/axlsx/content_type/override.rb +25 -25
  13. data/lib/axlsx/doc_props/app.rb +235 -235
  14. data/lib/axlsx/doc_props/core.rb +39 -39
  15. data/lib/axlsx/drawing/area_chart.rb +99 -99
  16. data/lib/axlsx/drawing/area_series.rb +110 -110
  17. data/lib/axlsx/drawing/ax_data_source.rb +26 -26
  18. data/lib/axlsx/drawing/axes.rb +61 -61
  19. data/lib/axlsx/drawing/axis.rb +190 -190
  20. data/lib/axlsx/drawing/bar_3D_chart.rb +148 -148
  21. data/lib/axlsx/drawing/bar_chart.rb +138 -138
  22. data/lib/axlsx/drawing/bar_series.rb +97 -97
  23. data/lib/axlsx/drawing/bubble_chart.rb +59 -59
  24. data/lib/axlsx/drawing/bubble_series.rb +63 -63
  25. data/lib/axlsx/drawing/cat_axis.rb +85 -85
  26. data/lib/axlsx/drawing/chart.rb +276 -276
  27. data/lib/axlsx/drawing/d_lbls.rb +90 -90
  28. data/lib/axlsx/drawing/drawing.rb +167 -167
  29. data/lib/axlsx/drawing/graphic_frame.rb +54 -54
  30. data/lib/axlsx/drawing/hyperlink.rb +100 -100
  31. data/lib/axlsx/drawing/line_3D_chart.rb +68 -68
  32. data/lib/axlsx/drawing/line_chart.rb +99 -99
  33. data/lib/axlsx/drawing/line_series.rb +110 -110
  34. data/lib/axlsx/drawing/marker.rb +84 -84
  35. data/lib/axlsx/drawing/num_data.rb +52 -52
  36. data/lib/axlsx/drawing/num_data_source.rb +62 -62
  37. data/lib/axlsx/drawing/num_val.rb +34 -34
  38. data/lib/axlsx/drawing/one_cell_anchor.rb +99 -99
  39. data/lib/axlsx/drawing/pic.rb +211 -211
  40. data/lib/axlsx/drawing/picture_locking.rb +42 -42
  41. data/lib/axlsx/drawing/pie_3D_chart.rb +47 -47
  42. data/lib/axlsx/drawing/pie_series.rb +74 -74
  43. data/lib/axlsx/drawing/scaling.rb +60 -60
  44. data/lib/axlsx/drawing/scatter_chart.rb +74 -74
  45. data/lib/axlsx/drawing/scatter_series.rb +129 -98
  46. data/lib/axlsx/drawing/ser_axis.rb +45 -45
  47. data/lib/axlsx/drawing/series.rb +69 -69
  48. data/lib/axlsx/drawing/series_title.rb +25 -25
  49. data/lib/axlsx/drawing/str_data.rb +42 -42
  50. data/lib/axlsx/drawing/str_val.rb +34 -34
  51. data/lib/axlsx/drawing/title.rb +97 -97
  52. data/lib/axlsx/drawing/two_cell_anchor.rb +97 -97
  53. data/lib/axlsx/drawing/val_axis.rb +37 -37
  54. data/lib/axlsx/drawing/view_3D.rb +115 -115
  55. data/lib/axlsx/drawing/vml_drawing.rb +42 -42
  56. data/lib/axlsx/drawing/vml_shape.rb +66 -66
  57. data/lib/axlsx/package.rb +388 -388
  58. data/lib/axlsx/rels/relationship.rb +130 -130
  59. data/lib/axlsx/rels/relationships.rb +32 -32
  60. data/lib/axlsx/stylesheet/border.rb +73 -71
  61. data/lib/axlsx/stylesheet/border_pr.rb +71 -71
  62. data/lib/axlsx/stylesheet/cell_alignment.rb +132 -132
  63. data/lib/axlsx/stylesheet/cell_protection.rb +41 -41
  64. data/lib/axlsx/stylesheet/cell_style.rb +72 -72
  65. data/lib/axlsx/stylesheet/color.rb +76 -76
  66. data/lib/axlsx/stylesheet/dxf.rb +79 -79
  67. data/lib/axlsx/stylesheet/fill.rb +35 -35
  68. data/lib/axlsx/stylesheet/font.rb +156 -156
  69. data/lib/axlsx/stylesheet/gradient_fill.rb +103 -103
  70. data/lib/axlsx/stylesheet/gradient_stop.rb +37 -37
  71. data/lib/axlsx/stylesheet/num_fmt.rb +86 -86
  72. data/lib/axlsx/stylesheet/pattern_fill.rb +73 -73
  73. data/lib/axlsx/stylesheet/styles.rb +494 -420
  74. data/lib/axlsx/stylesheet/table_style.rb +54 -54
  75. data/lib/axlsx/stylesheet/table_style_element.rb +77 -77
  76. data/lib/axlsx/stylesheet/table_styles.rb +46 -46
  77. data/lib/axlsx/stylesheet/xf.rb +147 -147
  78. data/lib/axlsx/util/accessors.rb +64 -64
  79. data/lib/axlsx/util/constants.rb +410 -401
  80. data/lib/axlsx/util/mime_type_utils.rb +11 -11
  81. data/lib/axlsx/util/options_parser.rb +16 -16
  82. data/lib/axlsx/util/serialized_attributes.rb +89 -89
  83. data/lib/axlsx/util/simple_typed_list.rb +179 -179
  84. data/lib/axlsx/util/storage.rb +146 -146
  85. data/lib/axlsx/util/validators.rb +312 -312
  86. data/lib/axlsx/util/zip_command.rb +73 -73
  87. data/lib/axlsx/version.rb +5 -5
  88. data/lib/axlsx/workbook/defined_name.rb +128 -128
  89. data/lib/axlsx/workbook/defined_names.rb +21 -21
  90. data/lib/axlsx/workbook/shared_strings_table.rb +77 -77
  91. data/lib/axlsx/workbook/workbook.rb +395 -370
  92. data/lib/axlsx/workbook/workbook_view.rb +80 -80
  93. data/lib/axlsx/workbook/workbook_views.rb +22 -22
  94. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -77
  95. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -94
  96. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +244 -244
  97. data/lib/axlsx/workbook/worksheet/break.rb +35 -35
  98. data/lib/axlsx/workbook/worksheet/cell.rb +506 -505
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +164 -164
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +60 -60
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -18
  102. data/lib/axlsx/workbook/worksheet/col.rb +145 -145
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -35
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +110 -110
  105. data/lib/axlsx/workbook/worksheet/cols.rb +23 -23
  106. data/lib/axlsx/workbook/worksheet/comment.rb +91 -91
  107. data/lib/axlsx/workbook/worksheet/comments.rb +82 -82
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -82
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +220 -220
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -25
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +129 -129
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +246 -246
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -28
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +30 -30
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +64 -64
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +52 -52
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +81 -81
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +37 -37
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -33
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -97
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -44
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +240 -240
  123. data/lib/axlsx/workbook/worksheet/pane.rb +139 -139
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +296 -294
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -66
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -24
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +39 -39
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +47 -47
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +37 -37
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -55
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -250
  132. data/lib/axlsx/workbook/worksheet/row.rb +164 -164
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -33
  134. data/lib/axlsx/workbook/worksheet/selection.rb +101 -101
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -29
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +27 -27
  137. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +87 -87
  138. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +118 -118
  139. data/lib/axlsx/workbook/worksheet/sheet_view.rb +213 -213
  140. data/lib/axlsx/workbook/worksheet/table.rb +102 -102
  141. data/lib/axlsx/workbook/worksheet/table_style_info.rb +49 -49
  142. data/lib/axlsx/workbook/worksheet/tables.rb +34 -34
  143. data/lib/axlsx/workbook/worksheet/worksheet.rb +786 -768
  144. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +58 -58
  145. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +58 -58
  146. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -74
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -38
  148. data/lib/axlsx.rb +185 -171
  149. data/lib/caxlsx.rb +2 -2
  150. data/lib/schema/dc.xsd +118 -118
  151. data/lib/schema/dcmitype.xsd +51 -51
  152. data/lib/schema/dcterms.xsd +331 -331
  153. data/lib/schema/dml-chartDrawing.xsd +146 -146
  154. data/lib/schema/dml-compatibility.xsd +14 -14
  155. data/lib/schema/dml-lockedCanvas.xsd +11 -11
  156. data/lib/schema/dml-main.xsd +3048 -3048
  157. data/lib/schema/dml-picture.xsd +23 -23
  158. data/lib/schema/dml-spreadsheetDrawing.xsd +185 -185
  159. data/lib/schema/dml-wordprocessingDrawing.xsd +185 -185
  160. data/lib/schema/shared-additionalCharacteristics.xsd +28 -28
  161. data/lib/schema/shared-bibliography.xsd +144 -144
  162. data/lib/schema/shared-commonSimpleTypes.xsd +166 -166
  163. data/lib/schema/shared-customXmlDataProperties.xsd +25 -25
  164. data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -18
  165. data/lib/schema/shared-documentPropertiesCustom.xsd +59 -59
  166. data/lib/schema/shared-documentPropertiesExtended.xsd +56 -56
  167. data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -195
  168. data/lib/schema/shared-relationshipReference.xsd +25 -25
  169. data/lib/schema/vml-main.xsd +569 -569
  170. data/lib/schema/vml-officeDrawing.xsd +509 -509
  171. data/lib/schema/vml-presentationDrawing.xsd +12 -12
  172. data/lib/schema/vml-spreadsheetDrawing.xsd +108 -108
  173. data/lib/schema/vml-wordprocessingDrawing.xsd +96 -96
  174. data/lib/schema/xml.xsd +116 -116
  175. data/test/benchmark.rb +72 -72
  176. data/test/content_type/tc_content_type.rb +76 -76
  177. data/test/content_type/tc_default.rb +16 -16
  178. data/test/content_type/tc_override.rb +14 -14
  179. data/test/doc_props/tc_app.rb +43 -43
  180. data/test/doc_props/tc_core.rb +42 -42
  181. data/test/drawing/tc_area_chart.rb +39 -39
  182. data/test/drawing/tc_area_series.rb +71 -71
  183. data/test/drawing/tc_axes.rb +7 -7
  184. data/test/drawing/tc_axis.rb +112 -112
  185. data/test/drawing/tc_bar_3D_chart.rb +86 -86
  186. data/test/drawing/tc_bar_chart.rb +86 -86
  187. data/test/drawing/tc_bar_series.rb +46 -46
  188. data/test/drawing/tc_bubble_chart.rb +44 -44
  189. data/test/drawing/tc_bubble_series.rb +21 -21
  190. data/test/drawing/tc_cat_axis.rb +31 -31
  191. data/test/drawing/tc_cat_axis_data.rb +27 -27
  192. data/test/drawing/tc_chart.rb +123 -123
  193. data/test/drawing/tc_d_lbls.rb +57 -57
  194. data/test/drawing/tc_data_source.rb +23 -23
  195. data/test/drawing/tc_drawing.rb +80 -80
  196. data/test/drawing/tc_graphic_frame.rb +27 -27
  197. data/test/drawing/tc_hyperlink.rb +64 -64
  198. data/test/drawing/tc_line_3d_chart.rb +47 -47
  199. data/test/drawing/tc_line_chart.rb +39 -39
  200. data/test/drawing/tc_line_series.rb +71 -71
  201. data/test/drawing/tc_marker.rb +44 -44
  202. data/test/drawing/tc_named_axis_data.rb +27 -27
  203. data/test/drawing/tc_num_data.rb +31 -31
  204. data/test/drawing/tc_num_val.rb +29 -29
  205. data/test/drawing/tc_one_cell_anchor.rb +66 -66
  206. data/test/drawing/tc_pic.rb +103 -103
  207. data/test/drawing/tc_picture_locking.rb +72 -72
  208. data/test/drawing/tc_pie_3D_chart.rb +28 -28
  209. data/test/drawing/tc_pie_series.rb +33 -33
  210. data/test/drawing/tc_scaling.rb +36 -36
  211. data/test/drawing/tc_scatter_chart.rb +48 -48
  212. data/test/drawing/tc_scatter_series.rb +74 -56
  213. data/test/drawing/tc_ser_axis.rb +31 -31
  214. data/test/drawing/tc_series.rb +23 -23
  215. data/test/drawing/tc_series_title.rb +54 -54
  216. data/test/drawing/tc_str_data.rb +18 -18
  217. data/test/drawing/tc_str_val.rb +30 -30
  218. data/test/drawing/tc_title.rb +70 -70
  219. data/test/drawing/tc_two_cell_anchor.rb +36 -36
  220. data/test/drawing/tc_val_axis.rb +24 -24
  221. data/test/drawing/tc_view_3D.rb +54 -54
  222. data/test/drawing/tc_vml_drawing.rb +25 -25
  223. data/test/drawing/tc_vml_shape.rb +106 -106
  224. data/test/profile.rb +24 -24
  225. data/test/rels/tc_relationship.rb +52 -52
  226. data/test/rels/tc_relationships.rb +37 -37
  227. data/test/stylesheet/tc_border.rb +37 -37
  228. data/test/stylesheet/tc_border_pr.rb +32 -32
  229. data/test/stylesheet/tc_cell_alignment.rb +81 -81
  230. data/test/stylesheet/tc_cell_protection.rb +29 -29
  231. data/test/stylesheet/tc_cell_style.rb +57 -57
  232. data/test/stylesheet/tc_color.rb +43 -43
  233. data/test/stylesheet/tc_dxf.rb +81 -81
  234. data/test/stylesheet/tc_fill.rb +18 -18
  235. data/test/stylesheet/tc_font.rb +133 -133
  236. data/test/stylesheet/tc_gradient_fill.rb +72 -72
  237. data/test/stylesheet/tc_gradient_stop.rb +31 -31
  238. data/test/stylesheet/tc_num_fmt.rb +30 -30
  239. data/test/stylesheet/tc_pattern_fill.rb +43 -43
  240. data/test/stylesheet/tc_styles.rb +309 -261
  241. data/test/stylesheet/tc_table_style.rb +44 -44
  242. data/test/stylesheet/tc_table_style_element.rb +45 -45
  243. data/test/stylesheet/tc_table_styles.rb +29 -29
  244. data/test/stylesheet/tc_xf.rb +120 -120
  245. data/test/tc_axlsx.rb +109 -109
  246. data/test/tc_helper.rb +10 -10
  247. data/test/tc_package.rb +317 -314
  248. data/test/util/tc_mime_type_utils.rb +13 -13
  249. data/test/util/tc_serialized_attributes.rb +19 -19
  250. data/test/util/tc_simple_typed_list.rb +77 -77
  251. data/test/util/tc_validators.rb +210 -210
  252. data/test/workbook/tc_defined_name.rb +49 -49
  253. data/test/workbook/tc_shared_strings_table.rb +59 -59
  254. data/test/workbook/tc_workbook.rb +165 -160
  255. data/test/workbook/tc_workbook_view.rb +50 -50
  256. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -38
  257. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -76
  258. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -50
  259. data/test/workbook/worksheet/tc_break.rb +49 -49
  260. data/test/workbook/worksheet/tc_cell.rb +465 -453
  261. data/test/workbook/worksheet/tc_cfvo.rb +31 -31
  262. data/test/workbook/worksheet/tc_col.rb +93 -93
  263. data/test/workbook/worksheet/tc_color_scale.rb +58 -58
  264. data/test/workbook/worksheet/tc_comment.rb +72 -72
  265. data/test/workbook/worksheet/tc_comments.rb +57 -57
  266. data/test/workbook/worksheet/tc_conditional_formatting.rb +224 -224
  267. data/test/workbook/worksheet/tc_data_bar.rb +46 -46
  268. data/test/workbook/worksheet/tc_data_validation.rb +265 -265
  269. data/test/workbook/worksheet/tc_date_time_converter.rb +124 -124
  270. data/test/workbook/worksheet/tc_header_footer.rb +151 -151
  271. data/test/workbook/worksheet/tc_icon_set.rb +45 -45
  272. data/test/workbook/worksheet/tc_outline_pr.rb +19 -19
  273. data/test/workbook/worksheet/tc_page_margins.rb +97 -97
  274. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -15
  275. data/test/workbook/worksheet/tc_page_setup.rb +143 -143
  276. data/test/workbook/worksheet/tc_pane.rb +54 -54
  277. data/test/workbook/worksheet/tc_pivot_table.rb +180 -143
  278. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +62 -62
  279. data/test/workbook/worksheet/tc_print_options.rb +72 -72
  280. data/test/workbook/worksheet/tc_protected_range.rb +17 -17
  281. data/test/workbook/worksheet/tc_rich_text.rb +44 -44
  282. data/test/workbook/worksheet/tc_rich_text_run.rb +173 -173
  283. data/test/workbook/worksheet/tc_row.rb +160 -160
  284. data/test/workbook/worksheet/tc_selection.rb +55 -55
  285. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -18
  286. data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -88
  287. data/test/workbook/worksheet/tc_sheet_pr.rb +49 -49
  288. data/test/workbook/worksheet/tc_sheet_protection.rb +117 -117
  289. data/test/workbook/worksheet/tc_sheet_view.rb +214 -214
  290. data/test/workbook/worksheet/tc_table.rb +77 -77
  291. data/test/workbook/worksheet/tc_table_style_info.rb +53 -53
  292. data/test/workbook/worksheet/tc_worksheet.rb +632 -601
  293. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -55
  294. metadata +101 -101
@@ -1,453 +1,465 @@
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
+ 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_autowidth_with_bold_font_multiplier
68
+ style = @c.row.worksheet.workbook.styles.add_style(b: true)
69
+ @c.row.worksheet.workbook.bold_font_multiplier = 1.05
70
+ @c.style = style
71
+ assert_in_delta(6.93, @c.autowidth, 0.01)
72
+ end
73
+
74
+ def test_autowidth_with_font_scale_divisor
75
+ @c.row.worksheet.workbook.font_scale_divisor = 11.0
76
+ assert_in_delta(6.0, @c.autowidth, 0.01)
77
+ end
78
+
79
+ def test_time
80
+ @c.type = :time
81
+ now = DateTime.now
82
+ @c.value = now
83
+ assert_equal(@c.value, now.to_time)
84
+ end
85
+
86
+ def test_date
87
+ @c.type = :date
88
+ now = Time.now
89
+ @c.value = now
90
+ assert_equal(@c.value, now.to_date)
91
+ end
92
+
93
+ def test_style
94
+ assert_raise(ArgumentError, "must reject invalid style indexes") { @c.style=@c.row.worksheet.workbook.styles.cellXfs.size }
95
+ assert_nothing_raised("must allow valid style index changes") {@c.style=1}
96
+ assert_equal(@c.style, 1)
97
+ end
98
+
99
+ def test_type
100
+ assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
101
+ assert_nothing_raised("type can be changed") { @c.type = :string }
102
+ assert_equal(@c.value, "1.0", "changing type casts the value")
103
+ assert_equal(:float, @row.add_cell(1.0/10**7).type, 'properly identify exponential floats as float type')
104
+ assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
105
+ assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date')
106
+ assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean')
107
+ end
108
+
109
+ def test_value
110
+ assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
111
+ assert_nothing_raised("type can be changed") { @c.type = :string }
112
+ assert_equal(@c.value, "1.0", "changing type casts the value")
113
+ end
114
+
115
+ def test_col_ref
116
+ #TODO move to axlsx spec
117
+ assert_equal(Axlsx.col_ref(0), "A")
118
+ end
119
+
120
+ def test_cell_type_from_value
121
+ assert_equal(@c.send(:cell_type_from_value, 1.0), :float)
122
+ assert_equal(@c.send(:cell_type_from_value, "1e1"), :float)
123
+ assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP}"), :float)
124
+ assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP + 1}"), :string)
125
+ assert_equal(@c.send(:cell_type_from_value, "1e-1"), :float)
126
+ assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP}"), :float)
127
+ assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP - 1}"), :string)
128
+ assert_equal(@c.send(:cell_type_from_value, 1), :integer)
129
+ assert_equal(@c.send(:cell_type_from_value, Date.today), :date)
130
+ assert_equal(@c.send(:cell_type_from_value, Time.now), :time)
131
+ assert_equal(@c.send(:cell_type_from_value, []), :string)
132
+ assert_equal(@c.send(:cell_type_from_value, "d"), :string)
133
+ assert_equal(@c.send(:cell_type_from_value, nil), :string)
134
+ assert_equal(@c.send(:cell_type_from_value, -1), :integer)
135
+ assert_equal(@c.send(:cell_type_from_value, true), :boolean)
136
+ assert_equal(@c.send(:cell_type_from_value, false), :boolean)
137
+ assert_equal(@c.send(:cell_type_from_value, 1.0/10**6), :float)
138
+ assert_equal(@c.send(:cell_type_from_value, Axlsx::RichText.new), :richtext)
139
+ assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00'))
140
+ end
141
+
142
+ def test_cell_type_from_value_looks_like_number_but_is_not
143
+ mimic_number = Class.new do
144
+ def initialize(to_s_value)
145
+ @to_s_value = to_s_value
146
+ end
147
+
148
+ def to_s
149
+ @to_s_value
150
+ end
151
+ end
152
+
153
+ number_strings = [
154
+ '1',
155
+ '1234567890',
156
+ '1.0',
157
+ '1e1',
158
+ '0',
159
+ "1e#{Float::MIN_10_EXP}"
160
+ ]
161
+
162
+ number_strings.each do |number_string|
163
+ assert_equal(@c.send(:cell_type_from_value, mimic_number.new(number_string)), :string)
164
+ end
165
+ end
166
+
167
+ def test_cast_value
168
+ @c.type = :string
169
+ assert_equal(@c.send(:cast_value, 1.0), "1.0")
170
+ @c.type = :integer
171
+ assert_equal(@c.send(:cast_value, 1.0), 1)
172
+ @c.type = :float
173
+ assert_equal(@c.send(:cast_value, "1.0"), 1.0)
174
+ @c.type = :string
175
+ assert_equal(@c.send(:cast_value, nil), nil)
176
+ @c.type = :richtext
177
+ assert_equal(@c.send(:cast_value, nil), nil)
178
+ @c.type = :float
179
+ assert_equal(@c.send(:cast_value, nil), nil)
180
+ @c.type = :boolean
181
+ assert_equal(@c.send(:cast_value, true), 1)
182
+ assert_equal(@c.send(:cast_value, false), 0)
183
+ @c.type = :iso_8601
184
+ assert_equal("2012-10-10T12:24", @c.send(:cast_value, "2012-10-10T12:24"))
185
+ end
186
+
187
+ def test_cast_time_subclass
188
+ subtime = Class.new(Time) do
189
+ def to_time
190
+ raise "#to_time of Time subclass should not be called"
191
+ end
192
+ end
193
+
194
+ time = subtime.now
195
+
196
+ @c.type = :time
197
+ assert_equal(time, @c.send(:cast_value, time))
198
+ end
199
+
200
+ def test_color
201
+ assert_raise(ArgumentError) { @c.color = -1.1 }
202
+ assert_nothing_raised { @c.color = "FF00FF00" }
203
+ assert_equal(@c.color.rgb, "FF00FF00")
204
+ end
205
+
206
+ def test_scheme
207
+ assert_raise(ArgumentError) { @c.scheme = -1.1 }
208
+ assert_nothing_raised { @c.scheme = :major }
209
+ assert_equal(@c.scheme, :major)
210
+ end
211
+
212
+ def test_vertAlign
213
+ assert_raise(ArgumentError) { @c.vertAlign = -1.1 }
214
+ assert_nothing_raised { @c.vertAlign = :baseline }
215
+ assert_equal(@c.vertAlign, :baseline)
216
+ end
217
+
218
+ def test_sz
219
+ assert_raise(ArgumentError) { @c.sz = -1.1 }
220
+ assert_nothing_raised { @c.sz = 12 }
221
+ assert_equal(@c.sz, 12)
222
+ end
223
+
224
+ def test_extend
225
+ assert_raise(ArgumentError) { @c.extend = -1.1 }
226
+ assert_nothing_raised { @c.extend = false }
227
+ assert_equal(@c.extend, false)
228
+ end
229
+
230
+ def test_condense
231
+ assert_raise(ArgumentError) { @c.condense = -1.1 }
232
+ assert_nothing_raised { @c.condense = false }
233
+ assert_equal(@c.condense, false)
234
+ end
235
+
236
+ def test_shadow
237
+ assert_raise(ArgumentError) { @c.shadow = -1.1 }
238
+ assert_nothing_raised { @c.shadow = false }
239
+ assert_equal(@c.shadow, false)
240
+ end
241
+
242
+ def test_outline
243
+ assert_raise(ArgumentError) { @c.outline = -1.1 }
244
+ assert_nothing_raised { @c.outline = false }
245
+ assert_equal(@c.outline, false)
246
+ end
247
+
248
+ def test_strike
249
+ assert_raise(ArgumentError) { @c.strike = -1.1 }
250
+ assert_nothing_raised { @c.strike = false }
251
+ assert_equal(@c.strike, false)
252
+ end
253
+
254
+ def test_u
255
+ @c.type = :string
256
+ assert_raise(ArgumentError) { @c.u = -1.1 }
257
+ assert_nothing_raised { @c.u = :single }
258
+ assert_equal(@c.u, :single)
259
+ doc = Nokogiri::XML(@c.to_xml_string(1,1))
260
+ assert(doc.xpath('//u[@val="single"]'))
261
+ end
262
+
263
+ def test_i
264
+ assert_raise(ArgumentError) { @c.i = -1.1 }
265
+ assert_nothing_raised { @c.i = false }
266
+ assert_equal(@c.i, false)
267
+ end
268
+
269
+ def test_rFont
270
+ assert_raise(ArgumentError) { @c.font_name = -1.1 }
271
+ assert_nothing_raised { @c.font_name = "Arial" }
272
+ assert_equal(@c.font_name, "Arial")
273
+ end
274
+
275
+ def test_charset
276
+ assert_raise(ArgumentError) { @c.charset = -1.1 }
277
+ assert_nothing_raised { @c.charset = 1 }
278
+ assert_equal(@c.charset, 1)
279
+ end
280
+
281
+ def test_family
282
+ assert_raise(ArgumentError) { @c.family = -1.1 }
283
+ assert_nothing_raised { @c.family = 5 }
284
+ assert_equal(@c.family, 5)
285
+ end
286
+
287
+ def test_b
288
+ assert_raise(ArgumentError) { @c.b = -1.1 }
289
+ assert_nothing_raised { @c.b = false }
290
+ assert_equal(@c.b, false)
291
+ end
292
+
293
+ def test_merge_with_string
294
+ @c.row.add_cell 2
295
+ @c.row.add_cell 3
296
+ @c.merge "A2"
297
+ assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:A2")
298
+ end
299
+
300
+ def test_merge_with_cell
301
+ @c.row.add_cell 2
302
+ @c.row.add_cell 3
303
+ @c.merge @row.cells.last
304
+ assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
305
+ end
306
+
307
+ def test_reverse_merge_with_cell
308
+ @c.row.add_cell 2
309
+ @c.row.add_cell 3
310
+ @row.cells.last.merge @c
311
+ assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
312
+ end
313
+
314
+ def test_ssti
315
+ assert_raise(ArgumentError, "ssti must be an unsigned integer!") { @c.send(:ssti=, -1) }
316
+ @c.send :ssti=, 1
317
+ assert_equal(@c.ssti, 1)
318
+ end
319
+
320
+ def test_plain_string
321
+ @c.type = :integer
322
+ assert_equal(@c.plain_string?, false)
323
+
324
+ @c.type = :string
325
+ @c.value = 'plain string'
326
+ assert_equal(@c.plain_string?, true)
327
+
328
+ @c.value = nil
329
+ assert_equal(@c.plain_string?, false)
330
+
331
+ @c.value = ''
332
+ assert_equal(@c.plain_string?, false)
333
+
334
+ @c.value = '=sum'
335
+ assert_equal(@c.plain_string?, false)
336
+
337
+ @c.value = 'plain string'
338
+ @c.font_name = 'Arial'
339
+ assert_equal(@c.plain_string?, false)
340
+ end
341
+
342
+ def test_to_xml_string
343
+ c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
344
+ assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
345
+ end
346
+
347
+ def test_to_xml_string_nil
348
+ @c.value = nil
349
+ c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
350
+ assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
351
+ end
352
+
353
+ def test_to_xml_string_with_run
354
+ # Actually quite a number of similar run styles
355
+ # but the processing should be the same
356
+ @c.b = true
357
+ @c.type = :string
358
+ @c.value = "a"
359
+ @c.font_name = 'arial'
360
+ @c.color = 'FF0000'
361
+ c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
362
+ assert(c_xml.xpath("//b").any?)
363
+ end
364
+
365
+ def test_to_xml_string_formula
366
+ p = Axlsx::Package.new
367
+ ws = p.workbook.add_worksheet do |sheet|
368
+ sheet.add_row ["=IF(2+2=4,4,5)"]
369
+ end
370
+ doc = Nokogiri::XML(ws.to_xml_string)
371
+ doc.remove_namespaces!
372
+ assert(doc.xpath("//f[text()='IF(2+2=4,4,5)']").any?)
373
+ end
374
+
375
+ def test_to_xml_string_formula_escaped
376
+ p = Axlsx::Package.new
377
+ ws = p.workbook.add_worksheet do |sheet|
378
+ sheet.add_row ["=IF(2+2=4,4,5)"], escape_formulas: true
379
+ end
380
+ doc = Nokogiri::XML(ws.to_xml_string)
381
+ doc.remove_namespaces!
382
+ assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?)
383
+ end
384
+
385
+ def test_to_xml_string_formula_escape_array_parameter
386
+ p = Axlsx::Package.new
387
+ ws = p.workbook.add_worksheet do |sheet|
388
+ sheet.add_row [
389
+ "=IF(2+2=4,4,5)",
390
+ "=IF(13+13=4,4,5)",
391
+ "=IF(99+99=4,4,5)"
392
+ ], escape_formulas: [true, false, true]
393
+ end
394
+ doc = Nokogiri::XML(ws.to_xml_string)
395
+ doc.remove_namespaces!
396
+
397
+ assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?)
398
+ assert(doc.xpath("//f[text()='IF(13+13=4,4,5)']").any?)
399
+ assert(doc.xpath("//t[text()='=IF(99+99=4,4,5)']").any?)
400
+ end
401
+
402
+ def test_to_xml_string_array_formula
403
+ p = Axlsx::Package.new
404
+ ws = p.workbook.add_worksheet do |sheet|
405
+ sheet.add_row ["{=SUM(C2:C11*D2:D11)}"]
406
+ end
407
+ doc = Nokogiri::XML(ws.to_xml_string)
408
+ doc.remove_namespaces!
409
+ assert(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']").any?)
410
+ assert(doc.xpath("//f[@t='array']").any?)
411
+ assert(doc.xpath("//f[@ref='A1']").any?)
412
+ end
413
+
414
+ def test_to_xml_string_text_formula
415
+ p = Axlsx::Package.new
416
+ ws = p.workbook.add_worksheet do |sheet|
417
+ sheet.add_row ["=1+1", "-1+1"], type: :text
418
+ end
419
+ doc = Nokogiri::XML(ws.to_xml_string)
420
+ doc.remove_namespaces!
421
+
422
+ assert(doc.xpath("//f[text()='1+1']").empty?)
423
+ assert(doc.xpath("//t[text()='=1+1']").any?)
424
+
425
+ assert(doc.xpath("//f[text()='1+1']").empty?)
426
+ assert(doc.xpath("//t[text()='-1+1']").any?)
427
+ end
428
+
429
+ def test_font_size_with_custom_style_and_no_sz
430
+ @c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
431
+ sz = @c.send(:font_size)
432
+ assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz)
433
+ end
434
+
435
+ def test_font_size_with_bolding
436
+ @c.style = @c.row.worksheet.workbook.styles.add_style :b => true
437
+ assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @c.send(:font_size))
438
+ end
439
+
440
+ def test_font_size_with_custom_sz
441
+ @c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52
442
+ sz = @c.send(:font_size)
443
+ assert_equal(sz, 52)
444
+ end
445
+
446
+ def test_cell_with_sz
447
+ @c.sz = 25
448
+ assert_equal(25, @c.send(:font_size))
449
+ end
450
+
451
+ def test_to_xml
452
+ # TODO This could use some much more stringent testing related to the xml content generated!
453
+ @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)", "2013-01-13T13:31:25.123"]
454
+ @ws.rows.last.cells[5].u = true
455
+
456
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
457
+ doc = Nokogiri::XML(@ws.to_xml_string)
458
+ errors = []
459
+ schema.validate(doc).each do |error|
460
+ errors.push error
461
+ puts error.message
462
+ end
463
+ assert(errors.empty?, "error free validation")
464
+ end
465
+ end