bonio-axlsx 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/.yardopts_guide +19 -0
- data/CHANGELOG.md +239 -0
- data/LICENSE +22 -0
- data/README.md +258 -0
- data/Rakefile +30 -0
- data/examples/2010_comments.rb +17 -0
- data/examples/anchor_swapping.rb +28 -0
- data/examples/auto_filter.rb +25 -0
- data/examples/basic_charts.rb +58 -0
- data/examples/chart_colors.rb +88 -0
- data/examples/colored_links.rb +59 -0
- data/examples/conditional_formatting/example_conditional_formatting.rb +89 -0
- data/examples/conditional_formatting/getting_barred.rb +37 -0
- data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
- data/examples/conditional_formatting/scaled_colors.rb +39 -0
- data/examples/conditional_formatting/stop_and_go.rb +37 -0
- data/examples/data_validation.rb +50 -0
- data/examples/example.rb +875 -0
- data/examples/extractive.rb +45 -0
- data/examples/image1.jpeg +0 -0
- data/examples/ios_preview.rb +14 -0
- data/examples/merge_cells.rb +17 -0
- data/examples/no_grid_with_borders.rb +18 -0
- data/examples/page_setup.rb +11 -0
- data/examples/pivot_table.rb +39 -0
- data/examples/pivot_test.rb +63 -0
- data/examples/sheet_protection.rb +10 -0
- data/examples/skydrive/real_example.rb +63 -0
- data/examples/split.rb +16 -0
- data/examples/styles.rb +66 -0
- data/examples/underline.rb +13 -0
- data/examples/wrap_text.rb +21 -0
- data/lib/axlsx.rb +168 -0
- data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
- data/lib/axlsx/content_type/content_type.rb +26 -0
- data/lib/axlsx/content_type/default.rb +25 -0
- data/lib/axlsx/content_type/override.rb +25 -0
- data/lib/axlsx/doc_props/app.rb +235 -0
- data/lib/axlsx/doc_props/core.rb +39 -0
- data/lib/axlsx/drawing/ax_data_source.rb +26 -0
- data/lib/axlsx/drawing/axes.rb +61 -0
- data/lib/axlsx/drawing/axis.rb +190 -0
- data/lib/axlsx/drawing/bar_3D_chart.rb +151 -0
- data/lib/axlsx/drawing/bar_series.rb +82 -0
- data/lib/axlsx/drawing/bubble_chart.rb +59 -0
- data/lib/axlsx/drawing/bubble_series.rb +63 -0
- data/lib/axlsx/drawing/cat_axis.rb +85 -0
- data/lib/axlsx/drawing/chart.rb +274 -0
- data/lib/axlsx/drawing/d_lbls.rb +90 -0
- data/lib/axlsx/drawing/drawing.rb +164 -0
- data/lib/axlsx/drawing/graphic_frame.rb +54 -0
- data/lib/axlsx/drawing/hyperlink.rb +100 -0
- data/lib/axlsx/drawing/line_3D_chart.rb +68 -0
- data/lib/axlsx/drawing/line_chart.rb +99 -0
- data/lib/axlsx/drawing/line_series.rb +110 -0
- data/lib/axlsx/drawing/marker.rb +84 -0
- data/lib/axlsx/drawing/num_data.rb +52 -0
- data/lib/axlsx/drawing/num_data_source.rb +62 -0
- data/lib/axlsx/drawing/num_val.rb +34 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +98 -0
- data/lib/axlsx/drawing/pic.rb +213 -0
- data/lib/axlsx/drawing/picture_locking.rb +42 -0
- data/lib/axlsx/drawing/pie_3D_chart.rb +47 -0
- data/lib/axlsx/drawing/pie_series.rb +74 -0
- data/lib/axlsx/drawing/scaling.rb +60 -0
- data/lib/axlsx/drawing/scatter_chart.rb +74 -0
- data/lib/axlsx/drawing/scatter_series.rb +98 -0
- data/lib/axlsx/drawing/ser_axis.rb +45 -0
- data/lib/axlsx/drawing/series.rb +69 -0
- data/lib/axlsx/drawing/series_title.rb +23 -0
- data/lib/axlsx/drawing/str_data.rb +42 -0
- data/lib/axlsx/drawing/str_val.rb +34 -0
- data/lib/axlsx/drawing/title.rb +96 -0
- data/lib/axlsx/drawing/two_cell_anchor.rb +92 -0
- data/lib/axlsx/drawing/val_axis.rb +37 -0
- data/lib/axlsx/drawing/view_3D.rb +115 -0
- data/lib/axlsx/drawing/vml_drawing.rb +42 -0
- data/lib/axlsx/drawing/vml_shape.rb +66 -0
- data/lib/axlsx/package.rb +363 -0
- data/lib/axlsx/rels/relationship.rb +129 -0
- data/lib/axlsx/rels/relationships.rb +29 -0
- data/lib/axlsx/stylesheet/border.rb +71 -0
- data/lib/axlsx/stylesheet/border_pr.rb +71 -0
- data/lib/axlsx/stylesheet/cell_alignment.rb +132 -0
- data/lib/axlsx/stylesheet/cell_protection.rb +41 -0
- data/lib/axlsx/stylesheet/cell_style.rb +72 -0
- data/lib/axlsx/stylesheet/color.rb +76 -0
- data/lib/axlsx/stylesheet/dxf.rb +79 -0
- data/lib/axlsx/stylesheet/fill.rb +35 -0
- data/lib/axlsx/stylesheet/font.rb +148 -0
- data/lib/axlsx/stylesheet/gradient_fill.rb +103 -0
- data/lib/axlsx/stylesheet/gradient_stop.rb +37 -0
- data/lib/axlsx/stylesheet/num_fmt.rb +86 -0
- data/lib/axlsx/stylesheet/pattern_fill.rb +73 -0
- data/lib/axlsx/stylesheet/styles.rb +420 -0
- data/lib/axlsx/stylesheet/table_style.rb +54 -0
- data/lib/axlsx/stylesheet/table_style_element.rb +77 -0
- data/lib/axlsx/stylesheet/table_styles.rb +46 -0
- data/lib/axlsx/stylesheet/xf.rb +147 -0
- data/lib/axlsx/util/accessors.rb +64 -0
- data/lib/axlsx/util/constants.rb +397 -0
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/options_parser.rb +16 -0
- data/lib/axlsx/util/parser.rb +44 -0
- data/lib/axlsx/util/serialized_attributes.rb +89 -0
- data/lib/axlsx/util/simple_typed_list.rb +179 -0
- data/lib/axlsx/util/storage.rb +146 -0
- data/lib/axlsx/util/string.rb +7 -0
- data/lib/axlsx/util/validators.rb +311 -0
- data/lib/axlsx/version.rb +5 -0
- data/lib/axlsx/workbook/defined_name.rb +128 -0
- data/lib/axlsx/workbook/defined_names.rb +21 -0
- data/lib/axlsx/workbook/shared_strings_table.rb +77 -0
- data/lib/axlsx/workbook/workbook.rb +375 -0
- data/lib/axlsx/workbook/workbook_view.rb +78 -0
- data/lib/axlsx/workbook/workbook_views.rb +22 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +244 -0
- data/lib/axlsx/workbook/worksheet/break.rb +35 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +475 -0
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +166 -0
- data/lib/axlsx/workbook/worksheet/cfvo.rb +60 -0
- data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
- data/lib/axlsx/workbook/worksheet/col.rb +141 -0
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb +110 -0
- data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
- data/lib/axlsx/workbook/worksheet/comment.rb +91 -0
- data/lib/axlsx/workbook/worksheet/comments.rb +82 -0
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +220 -0
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
- data/lib/axlsx/workbook/worksheet/data_bar.rb +129 -0
- data/lib/axlsx/workbook/worksheet/data_validation.rb +246 -0
- data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +30 -0
- data/lib/axlsx/workbook/worksheet/dimension.rb +64 -0
- data/lib/axlsx/workbook/worksheet/header_footer.rb +52 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb +81 -0
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +37 -0
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +240 -0
- data/lib/axlsx/workbook/worksheet/pane.rb +139 -0
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +289 -0
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
- data/lib/axlsx/workbook/worksheet/print_options.rb +39 -0
- data/lib/axlsx/workbook/worksheet/protected_range.rb +47 -0
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
- data/lib/axlsx/workbook/worksheet/rich_text.rb +35 -0
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +254 -0
- data/lib/axlsx/workbook/worksheet/row.rb +161 -0
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
- data/lib/axlsx/workbook/worksheet/selection.rb +101 -0
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +27 -0
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +87 -0
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +118 -0
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +213 -0
- data/lib/axlsx/workbook/worksheet/table.rb +102 -0
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +49 -0
- data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +799 -0
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +58 -0
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +58 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
- data/lib/schema/dc.xsd +118 -0
- data/lib/schema/dcmitype.xsd +52 -0
- data/lib/schema/dcterms.xsd +331 -0
- data/lib/schema/dml-chart.xsd +1499 -0
- data/lib/schema/dml-chartDrawing.xsd +146 -0
- data/lib/schema/dml-compatibility.xsd +14 -0
- data/lib/schema/dml-diagram.xsd +1091 -0
- data/lib/schema/dml-lockedCanvas.xsd +11 -0
- data/lib/schema/dml-main.xsd +3048 -0
- data/lib/schema/dml-picture.xsd +23 -0
- data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
- data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
- data/lib/schema/opc-contentTypes.xsd +42 -0
- data/lib/schema/opc-coreProperties.xsd +54 -0
- data/lib/schema/opc-digSig.xsd +49 -0
- data/lib/schema/opc-relationships.xsd +33 -0
- data/lib/schema/pml.xsd +1676 -0
- data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
- data/lib/schema/shared-bibliography.xsd +144 -0
- data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
- data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
- data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
- data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
- data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
- data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
- data/lib/schema/shared-math.xsd +582 -0
- data/lib/schema/shared-relationshipReference.xsd +25 -0
- data/lib/schema/sml.xsd +4434 -0
- data/lib/schema/vml-main.xsd +569 -0
- data/lib/schema/vml-officeDrawing.xsd +509 -0
- data/lib/schema/vml-presentationDrawing.xsd +12 -0
- data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
- data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
- data/lib/schema/wml.xsd +3644 -0
- data/lib/schema/xml.xsd +116 -0
- data/test/benchmark.rb +72 -0
- data/test/content_type/tc_content_type.rb +76 -0
- data/test/content_type/tc_default.rb +16 -0
- data/test/content_type/tc_override.rb +14 -0
- data/test/doc_props/tc_app.rb +43 -0
- data/test/doc_props/tc_core.rb +42 -0
- data/test/drawing/tc_axes.rb +8 -0
- data/test/drawing/tc_axis.rb +112 -0
- data/test/drawing/tc_bar_3D_chart.rb +71 -0
- data/test/drawing/tc_bar_series.rb +37 -0
- data/test/drawing/tc_bubble_chart.rb +44 -0
- data/test/drawing/tc_bubble_series.rb +21 -0
- data/test/drawing/tc_cat_axis.rb +31 -0
- data/test/drawing/tc_cat_axis_data.rb +27 -0
- data/test/drawing/tc_chart.rb +110 -0
- data/test/drawing/tc_d_lbls.rb +57 -0
- data/test/drawing/tc_data_source.rb +23 -0
- data/test/drawing/tc_drawing.rb +80 -0
- data/test/drawing/tc_graphic_frame.rb +27 -0
- data/test/drawing/tc_hyperlink.rb +64 -0
- data/test/drawing/tc_line_3d_chart.rb +47 -0
- data/test/drawing/tc_line_chart.rb +39 -0
- data/test/drawing/tc_line_series.rb +71 -0
- data/test/drawing/tc_marker.rb +44 -0
- data/test/drawing/tc_named_axis_data.rb +27 -0
- data/test/drawing/tc_num_data.rb +31 -0
- data/test/drawing/tc_num_val.rb +29 -0
- data/test/drawing/tc_one_cell_anchor.rb +66 -0
- data/test/drawing/tc_pic.rb +106 -0
- data/test/drawing/tc_picture_locking.rb +72 -0
- data/test/drawing/tc_pie_3D_chart.rb +28 -0
- data/test/drawing/tc_pie_series.rb +32 -0
- data/test/drawing/tc_scaling.rb +36 -0
- data/test/drawing/tc_scatter_chart.rb +48 -0
- data/test/drawing/tc_scatter_series.rb +45 -0
- data/test/drawing/tc_ser_axis.rb +31 -0
- data/test/drawing/tc_series.rb +23 -0
- data/test/drawing/tc_series_title.rb +33 -0
- data/test/drawing/tc_str_data.rb +18 -0
- data/test/drawing/tc_str_val.rb +30 -0
- data/test/drawing/tc_title.rb +49 -0
- data/test/drawing/tc_two_cell_anchor.rb +36 -0
- data/test/drawing/tc_val_axis.rb +24 -0
- data/test/drawing/tc_view_3D.rb +54 -0
- data/test/drawing/tc_vml_drawing.rb +25 -0
- data/test/drawing/tc_vml_shape.rb +106 -0
- data/test/profile.rb +24 -0
- data/test/rels/tc_relationship.rb +44 -0
- data/test/rels/tc_relationships.rb +37 -0
- data/test/stylesheet/tc_border.rb +37 -0
- data/test/stylesheet/tc_border_pr.rb +32 -0
- data/test/stylesheet/tc_cell_alignment.rb +81 -0
- data/test/stylesheet/tc_cell_protection.rb +29 -0
- data/test/stylesheet/tc_cell_style.rb +57 -0
- data/test/stylesheet/tc_color.rb +43 -0
- data/test/stylesheet/tc_dxf.rb +81 -0
- data/test/stylesheet/tc_fill.rb +18 -0
- data/test/stylesheet/tc_font.rb +121 -0
- data/test/stylesheet/tc_gradient_fill.rb +72 -0
- data/test/stylesheet/tc_gradient_stop.rb +31 -0
- data/test/stylesheet/tc_num_fmt.rb +30 -0
- data/test/stylesheet/tc_pattern_fill.rb +43 -0
- data/test/stylesheet/tc_styles.rb +235 -0
- data/test/stylesheet/tc_table_style.rb +44 -0
- data/test/stylesheet/tc_table_style_element.rb +45 -0
- data/test/stylesheet/tc_table_styles.rb +29 -0
- data/test/stylesheet/tc_xf.rb +120 -0
- data/test/tc_axlsx.rb +82 -0
- data/test/tc_helper.rb +10 -0
- data/test/tc_package.rb +233 -0
- data/test/util/tc_mime_type_utils.rb +13 -0
- data/test/util/tc_serialized_attributes.rb +19 -0
- data/test/util/tc_simple_typed_list.rb +77 -0
- data/test/util/tc_validators.rb +210 -0
- data/test/workbook/tc_defined_name.rb +49 -0
- data/test/workbook/tc_shared_strings_table.rb +58 -0
- data/test/workbook/tc_workbook.rb +145 -0
- data/test/workbook/tc_workbook_view.rb +50 -0
- data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
- data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
- data/test/workbook/worksheet/tc_break.rb +49 -0
- data/test/workbook/worksheet/tc_cell.rb +373 -0
- data/test/workbook/worksheet/tc_cfvo.rb +31 -0
- data/test/workbook/worksheet/tc_col.rb +78 -0
- data/test/workbook/worksheet/tc_color_scale.rb +58 -0
- data/test/workbook/worksheet/tc_comment.rb +72 -0
- data/test/workbook/worksheet/tc_comments.rb +57 -0
- data/test/workbook/worksheet/tc_conditional_formatting.rb +224 -0
- data/test/workbook/worksheet/tc_data_bar.rb +46 -0
- data/test/workbook/worksheet/tc_data_validation.rb +265 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb +124 -0
- data/test/workbook/worksheet/tc_header_footer.rb +151 -0
- data/test/workbook/worksheet/tc_icon_set.rb +45 -0
- data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
- data/test/workbook/worksheet/tc_page_margins.rb +97 -0
- data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
- data/test/workbook/worksheet/tc_page_setup.rb +143 -0
- data/test/workbook/worksheet/tc_pane.rb +54 -0
- data/test/workbook/worksheet/tc_pivot_table.rb +140 -0
- data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
- data/test/workbook/worksheet/tc_print_options.rb +72 -0
- data/test/workbook/worksheet/tc_protected_range.rb +17 -0
- data/test/workbook/worksheet/tc_rich_text.rb +44 -0
- data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
- data/test/workbook/worksheet/tc_row.rb +122 -0
- data/test/workbook/worksheet/tc_selection.rb +55 -0
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
- data/test/workbook/worksheet/tc_sheet_pr.rb +49 -0
- data/test/workbook/worksheet/tc_sheet_protection.rb +117 -0
- data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
- data/test/workbook/worksheet/tc_table.rb +68 -0
- data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
- data/test/workbook/worksheet/tc_worksheet.rb +594 -0
- data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
- metadata +582 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
class TestMimeTypeUtils < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
@test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
|
5
|
+
end
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_mime_type_utils
|
11
|
+
assert_equal(Axlsx::MimeTypeUtils::get_mime_type(@test_img), 'image/jpeg')
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
class Funk
|
3
|
+
include Axlsx::Accessors
|
4
|
+
include Axlsx::SerializedAttributes
|
5
|
+
serializable_attributes :camel_symbol, :boolean, :integer
|
6
|
+
|
7
|
+
attr_accessor :camel_symbol, :boolean, :integer
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestSeralizedAttributes < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@object = Funk.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_camel_symbol
|
16
|
+
@object.camel_symbol = :foo_bar
|
17
|
+
assert_equal('camelSymbol="fooBar" ', @object.serialized_attributes)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
class TestSimpleTypedList < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
@list = Axlsx::SimpleTypedList.new Integer
|
5
|
+
end
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_type_is_a_class_or_array_of_class
|
11
|
+
assert_nothing_raised { Axlsx::SimpleTypedList.new Integer }
|
12
|
+
assert_nothing_raised { Axlsx::SimpleTypedList.new [Integer,String] }
|
13
|
+
assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new }
|
14
|
+
assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new "1" }
|
15
|
+
assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new [Integer, "Class"] }
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_indexed_based_assignment
|
19
|
+
#should not allow nil assignment
|
20
|
+
assert_raise(ArgumentError) { @list[0] = nil }
|
21
|
+
assert_raise(ArgumentError) { @list[0] = "1" }
|
22
|
+
assert_nothing_raised { @list[0] = 1 }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_concat_assignment
|
26
|
+
assert_raise(ArgumentError) { @list << nil }
|
27
|
+
assert_raise(ArgumentError) { @list << "1" }
|
28
|
+
assert_nothing_raised { @list << 1 }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_concat_should_return_index
|
32
|
+
assert( @list.size == 0 )
|
33
|
+
assert( @list << 1 == 0 )
|
34
|
+
assert( @list << 2 == 1 )
|
35
|
+
@list.delete_at 0
|
36
|
+
assert( @list << 3 == 1 )
|
37
|
+
assert( @list.index(2) == 0 )
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_push_should_return_index
|
41
|
+
assert( @list.push(1) == 0 )
|
42
|
+
assert( @list.push(2) == 1 )
|
43
|
+
@list.delete_at 0
|
44
|
+
assert( @list.push(3) == 1 )
|
45
|
+
assert( @list.index(2) == 0 )
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_locking
|
49
|
+
@list.push 1
|
50
|
+
@list.push 2
|
51
|
+
@list.push 3
|
52
|
+
@list.lock
|
53
|
+
|
54
|
+
assert_raise(ArgumentError) { @list.delete 1 }
|
55
|
+
assert_raise(ArgumentError) { @list.delete_at 1 }
|
56
|
+
assert_raise(ArgumentError) { @list.delete_at 2 }
|
57
|
+
@list.push 4
|
58
|
+
assert_nothing_raised { @list.delete_at 3 }
|
59
|
+
@list.unlock
|
60
|
+
#ignore garbage
|
61
|
+
assert_nothing_raised { @list.delete 0 }
|
62
|
+
assert_nothing_raised { @list.delete 9 }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_delete
|
66
|
+
@list.push 1
|
67
|
+
assert(@list.size == 1)
|
68
|
+
@list.delete 1
|
69
|
+
assert(@list.empty?)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_equality
|
73
|
+
@list.push 1
|
74
|
+
@list.push 2
|
75
|
+
assert_equal(@list.to_ary, [1,2])
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
class TestValidators < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
end
|
5
|
+
def teardown
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_validators
|
9
|
+
#unsigned_int
|
10
|
+
assert_nothing_raised { Axlsx.validate_unsigned_int 1 }
|
11
|
+
assert_nothing_raised { Axlsx.validate_unsigned_int(+1) }
|
12
|
+
assert_raise(ArgumentError) { Axlsx.validate_unsigned_int(-1)}
|
13
|
+
assert_raise(ArgumentError) { Axlsx.validate_unsigned_int('1') }
|
14
|
+
|
15
|
+
#int
|
16
|
+
assert_nothing_raised { Axlsx.validate_int(1) }
|
17
|
+
assert_nothing_raised { Axlsx.validate_int(-1) }
|
18
|
+
assert_raise(ArgumentError) { Axlsx.validate_int('a')}
|
19
|
+
assert_raise(ArgumentError) { Axlsx.validate_int(Array) }
|
20
|
+
|
21
|
+
#boolean (as 0 or 1, :true, :false, true, false, or "true," "false")
|
22
|
+
[0,1,:true, :false, true, false, "true", "false"].each do |v|
|
23
|
+
assert_nothing_raised { Axlsx.validate_boolean 0 }
|
24
|
+
end
|
25
|
+
assert_raise(ArgumentError) { Axlsx.validate_boolean 2 }
|
26
|
+
|
27
|
+
#string
|
28
|
+
assert_nothing_raised { Axlsx.validate_string "1" }
|
29
|
+
assert_raise(ArgumentError) { Axlsx.validate_string 2 }
|
30
|
+
assert_raise(ArgumentError) { Axlsx.validate_string false }
|
31
|
+
|
32
|
+
#float
|
33
|
+
assert_nothing_raised { Axlsx.validate_float 1.0 }
|
34
|
+
assert_raise(ArgumentError) { Axlsx.validate_float 2 }
|
35
|
+
assert_raise(ArgumentError) { Axlsx.validate_float false }
|
36
|
+
|
37
|
+
#pattern_type
|
38
|
+
assert_nothing_raised { Axlsx.validate_pattern_type :none }
|
39
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type "none" }
|
40
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type "crazy_pattern" }
|
41
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type false }
|
42
|
+
|
43
|
+
#gradient_type
|
44
|
+
assert_nothing_raised { Axlsx.validate_gradient_type :path }
|
45
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type nil }
|
46
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type "fractal" }
|
47
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type false }
|
48
|
+
|
49
|
+
#horizontal alignment
|
50
|
+
assert_nothing_raised { Axlsx.validate_horizontal_alignment :general }
|
51
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment nil }
|
52
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment "wavy" }
|
53
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment false }
|
54
|
+
|
55
|
+
#vertical alignment
|
56
|
+
assert_nothing_raised { Axlsx.validate_vertical_alignment :top }
|
57
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment nil }
|
58
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment "dynamic" }
|
59
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment false }
|
60
|
+
|
61
|
+
#contentType
|
62
|
+
assert_nothing_raised { Axlsx.validate_content_type Axlsx::WORKBOOK_CT }
|
63
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type nil }
|
64
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type "http://some.url" }
|
65
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type false }
|
66
|
+
|
67
|
+
#relationshipType
|
68
|
+
assert_nothing_raised { Axlsx.validate_relationship_type Axlsx::WORKBOOK_R }
|
69
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type nil }
|
70
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type "http://some.url" }
|
71
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type false }
|
72
|
+
|
73
|
+
#number_with_unit
|
74
|
+
assert_nothing_raised { Axlsx.validate_number_with_unit "210mm" }
|
75
|
+
assert_nothing_raised { Axlsx.validate_number_with_unit "8.5in" }
|
76
|
+
assert_nothing_raised { Axlsx.validate_number_with_unit "29.7cm" }
|
77
|
+
assert_nothing_raised { Axlsx.validate_number_with_unit "120pt" }
|
78
|
+
assert_nothing_raised { Axlsx.validate_number_with_unit "0pc" }
|
79
|
+
assert_nothing_raised { Axlsx.validate_number_with_unit "12.34pi" }
|
80
|
+
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit nil }
|
81
|
+
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "210" }
|
82
|
+
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit 210 }
|
83
|
+
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "mm" }
|
84
|
+
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "-29cm" }
|
85
|
+
|
86
|
+
#scale_10_400
|
87
|
+
assert_nothing_raised { Axlsx.validate_scale_10_400 10 }
|
88
|
+
assert_nothing_raised { Axlsx.validate_scale_10_400 100 }
|
89
|
+
assert_nothing_raised { Axlsx.validate_scale_10_400 400 }
|
90
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 9 }
|
91
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 10.0 }
|
92
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 400.1 }
|
93
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 "99" }
|
94
|
+
|
95
|
+
#scale_0_10_400
|
96
|
+
assert_nothing_raised { Axlsx.validate_scale_0_10_400 0 }
|
97
|
+
assert_nothing_raised { Axlsx.validate_scale_0_10_400 10 }
|
98
|
+
assert_nothing_raised { Axlsx.validate_scale_0_10_400 100 }
|
99
|
+
assert_nothing_raised { Axlsx.validate_scale_0_10_400 400 }
|
100
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 9 }
|
101
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 10.0 }
|
102
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 400.1 }
|
103
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 "99" }
|
104
|
+
|
105
|
+
#page_orientation
|
106
|
+
assert_nothing_raised { Axlsx.validate_page_orientation :default }
|
107
|
+
assert_nothing_raised { Axlsx.validate_page_orientation :landscape }
|
108
|
+
assert_nothing_raised { Axlsx.validate_page_orientation :portrait }
|
109
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_orientation nil }
|
110
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_orientation 1 }
|
111
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_orientation "landscape" }
|
112
|
+
|
113
|
+
#data_validation_error_style
|
114
|
+
[:information, :stop, :warning].each do |sym|
|
115
|
+
assert_nothing_raised { Axlsx.validate_data_validation_error_style sym }
|
116
|
+
end
|
117
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
118
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'warning' }
|
119
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
120
|
+
|
121
|
+
#data_validation_operator
|
122
|
+
[:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween].each do |sym|
|
123
|
+
assert_nothing_raised { Axlsx.validate_data_validation_operator sym }
|
124
|
+
end
|
125
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
126
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'lessThan' }
|
127
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
128
|
+
|
129
|
+
#data_validation_type
|
130
|
+
[:custom, :data, :decimal, :list, :none, :textLength, :time, :whole].each do |sym|
|
131
|
+
assert_nothing_raised { Axlsx.validate_data_validation_type sym }
|
132
|
+
end
|
133
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
134
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'decimal' }
|
135
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
136
|
+
|
137
|
+
#sheet_view_type
|
138
|
+
[:normal, :page_break_preview, :page_layout].each do |sym|
|
139
|
+
assert_nothing_raised { Axlsx.validate_sheet_view_type sym }
|
140
|
+
end
|
141
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
142
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'page_layout' }
|
143
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
144
|
+
|
145
|
+
#active_pane_type
|
146
|
+
[:bottom_left, :bottom_right, :top_left, :top_right].each do |sym|
|
147
|
+
assert_nothing_raised { Axlsx.validate_pane_type sym }
|
148
|
+
end
|
149
|
+
assert_raise(ArgumentError) { Axlsx.validate_pane_type :other_symbol }
|
150
|
+
assert_raise(ArgumentError) { Axlsx.validate_pane_type 'bottom_left' }
|
151
|
+
assert_raise(ArgumentError) { Axlsx.validate_pane_type 0 }
|
152
|
+
|
153
|
+
#split_state_type
|
154
|
+
[:frozen, :frozen_split, :split].each do |sym|
|
155
|
+
assert_nothing_raised { Axlsx.validate_split_state_type sym }
|
156
|
+
end
|
157
|
+
assert_raise(ArgumentError) { Axlsx.validate_split_state_type :other_symbol }
|
158
|
+
assert_raise(ArgumentError) { Axlsx.validate_split_state_type 'frozen_split' }
|
159
|
+
assert_raise(ArgumentError) { Axlsx.validate_split_state_type 0 }
|
160
|
+
|
161
|
+
#display_blanks_as
|
162
|
+
[:gap, :span, :zero].each do |sym|
|
163
|
+
assert_nothing_raised { Axlsx.validate_display_blanks_as sym }
|
164
|
+
end
|
165
|
+
assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as :other_symbol }
|
166
|
+
assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as 'other_blank' }
|
167
|
+
assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as 0 }
|
168
|
+
|
169
|
+
#view_visibility
|
170
|
+
[:visible, :hidden, :very_hidden].each do |sym|
|
171
|
+
assert_nothing_raised { Axlsx.validate_view_visibility sym }
|
172
|
+
end
|
173
|
+
assert_raise(ArgumentError) { Axlsx.validate_view_visibility :other_symbol }
|
174
|
+
assert_raise(ArgumentError) { Axlsx.validate_view_visibility 'other_visibility' }
|
175
|
+
assert_raise(ArgumentError) { Axlsx.validate_view_visibility 0 }
|
176
|
+
|
177
|
+
#marker_symbol
|
178
|
+
[:default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x].each do |sym|
|
179
|
+
assert_nothing_raised { Axlsx.validate_marker_symbol sym }
|
180
|
+
end
|
181
|
+
assert_raise(ArgumentError) { Axlsx.validate_marker_symbol :other_symbol }
|
182
|
+
assert_raise(ArgumentError) { Axlsx.validate_marker_symbol 'other_marker' }
|
183
|
+
assert_raise(ArgumentError) { Axlsx.validate_marker_symbol 0 }
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_validate_integerish
|
187
|
+
assert_raise(ArgumentError) { Axlsx.validate_integerish Axlsx }
|
188
|
+
[1, 1.4, "a"].each { |test_value| assert_nothing_raised { Axlsx.validate_integerish test_value } }
|
189
|
+
end
|
190
|
+
def test_validate_family
|
191
|
+
assert_raise(ArgumentError) { Axlsx.validate_family 0 }
|
192
|
+
(1..5).each do |item|
|
193
|
+
assert_nothing_raised { Axlsx.validate_family item }
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_validate_u
|
198
|
+
assert_raise(ArgumentError) { Axlsx.validate_cell_u :hoge }
|
199
|
+
[:none, :single, :double, :singleAccounting, :doubleAccounting].each do |sym|
|
200
|
+
assert_nothing_raised { Axlsx.validate_cell_u sym }
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_range_validation
|
205
|
+
# exclusive
|
206
|
+
assert_raise(ArgumentError) { Axlsx::RangeValidator.validate('foo', 1, 10, 10, false) }
|
207
|
+
# inclusive by default
|
208
|
+
assert_nothing_raised { Axlsx::RangeValidator.validate('foo', 1, 10, 10) }
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'tc_helper'
|
2
|
+
|
3
|
+
class TestDefinedNames < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@dn = Axlsx::DefinedName.new('Sheet1!A1:A1')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_initialize
|
9
|
+
assert_equal('Sheet1!A1:A1', @dn.formula)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_string_attributes
|
13
|
+
%w(short_cut_key status_bar help description custom_menu comment).each do |attr|
|
14
|
+
assert_raise(ArgumentError, 'only strings allowed in string attributes') { @dn.send("#{attr}=", 1) }
|
15
|
+
assert_nothing_raised { @dn.send("#{attr}=", '_xlnm.Sheet_Title') }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_boolean_attributes
|
20
|
+
%w(workbook_parameter publish_to_server xlm vb_proceedure function hidden).each do |attr|
|
21
|
+
assert_raise(ArgumentError, 'only booleanish allowed in string attributes') { @dn.send("#{attr}=", 'foo') }
|
22
|
+
assert_nothing_raised { @dn.send("#{attr}=", 1) }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_local_sheet_id
|
28
|
+
assert_raise(ArgumentError, 'local_sheet_id must be an unsigned int') { @dn.local_sheet_id = -1 }
|
29
|
+
assert_nothing_raised { @dn.local_sheet_id = 1 }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_do_not_camelcase_value_for_name
|
33
|
+
@dn.name = '_xlnm._FilterDatabase'
|
34
|
+
doc = Nokogiri::XML(@dn.to_xml_string)
|
35
|
+
assert_equal(doc.xpath("//definedName[@name='_xlnm._FilterDatabase']").size, 1)
|
36
|
+
assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_to_xml_string
|
40
|
+
assert_raise(ArgumentError, 'name is required for serialization') { @dn.to_xml_string }
|
41
|
+
@dn.name = '_xlnm.Print_Titles'
|
42
|
+
@dn.hidden = true
|
43
|
+
doc = Nokogiri::XML(@dn.to_xml_string)
|
44
|
+
assert_equal(doc.xpath("//definedName[@name='_xlnm.Print_Titles']").size, 1)
|
45
|
+
assert_equal(doc.xpath("//definedName[@hidden='1']").size, 1)
|
46
|
+
assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestSharedStringsTable < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@p = Axlsx::Package.new :use_shared_strings=>true
|
7
|
+
ws = @p.workbook.add_worksheet
|
8
|
+
ws.add_row ['a', 1, 'b']
|
9
|
+
ws.add_row ['b', 1, 'c']
|
10
|
+
ws.add_row ['c', 1, 'd']
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_workbook_has_shared_strings
|
14
|
+
assert(@p.workbook.shared_strings.is_a?(Axlsx::SharedStringsTable), "shared string table was not created")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_count
|
18
|
+
sst = @p.workbook.shared_strings
|
19
|
+
assert_equal(sst.count, 6)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_unique_count
|
23
|
+
sst = @p.workbook.shared_strings
|
24
|
+
assert_equal(sst.unique_count, 4)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_uses_workbook_xml_space
|
28
|
+
assert_equal(@p.workbook.xml_space, @p.workbook.shared_strings.xml_space)
|
29
|
+
@p.workbook.xml_space = :default
|
30
|
+
assert_equal(:default, @p.workbook.shared_strings.xml_space)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_valid_document
|
34
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
35
|
+
doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml_string)
|
36
|
+
errors = []
|
37
|
+
schema.validate(doc).each do |error|
|
38
|
+
puts error.message
|
39
|
+
errors << error
|
40
|
+
end
|
41
|
+
assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map{ |e| e.message }.to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_remove_control_characters_in_xml_serialization
|
45
|
+
nasties = "hello\x10\x00\x1C\x1Eworld"
|
46
|
+
@p.workbook.worksheets[0].add_row [nasties]
|
47
|
+
|
48
|
+
# test that the nasty string was added to the shared strings
|
49
|
+
assert @p.workbook.shared_strings.unique_cells.has_key?(nasties)
|
50
|
+
|
51
|
+
# test that none of the control characters are in the XML output for shared strings
|
52
|
+
assert_no_match(/#{Axlsx::CONTROL_CHARS}/, @p.workbook.shared_strings.to_xml_string)
|
53
|
+
|
54
|
+
# assert that the shared string was normalized to remove the control characters
|
55
|
+
assert_not_nil @p.workbook.shared_strings.to_xml_string.index("helloworld")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestWorkbook < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
p = Axlsx::Package.new
|
6
|
+
@wb = p.workbook
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_worksheet_users_xml_space
|
13
|
+
sheet = @wb.add_worksheet(:name => 'foo')
|
14
|
+
ws_xml = Nokogiri::XML(sheet.to_xml_string)
|
15
|
+
assert(ws_xml.xpath("//xmlns:worksheet/@xml:space='preserve'"))
|
16
|
+
|
17
|
+
@wb.xml_space = :default
|
18
|
+
ws_xml = Nokogiri::XML(sheet.to_xml_string)
|
19
|
+
assert(ws_xml.xpath("//xmlns:worksheet/@xml:space='default'"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_xml_space
|
23
|
+
assert_equal(:preserve, @wb.xml_space)
|
24
|
+
@wb.xml_space = :default
|
25
|
+
assert_equal(:default, @wb.xml_space)
|
26
|
+
assert_raise(ArgumentError) { @wb.xml_space = :none }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_no_autowidth
|
30
|
+
assert_equal(@wb.use_autowidth, true)
|
31
|
+
assert_raise(ArgumentError) {@wb.use_autowidth = 0.1}
|
32
|
+
assert_nothing_raised {@wb.use_autowidth = false}
|
33
|
+
assert_equal(@wb.use_autowidth, false)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def test_sheet_by_name_retrieval
|
38
|
+
@wb.add_worksheet(:name=>'foo')
|
39
|
+
@wb.add_worksheet(:name=>'bar')
|
40
|
+
assert_equal('foo', @wb.sheet_by_name('foo').name)
|
41
|
+
|
42
|
+
end
|
43
|
+
def test_date1904
|
44
|
+
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
45
|
+
@wb.date1904 = :false
|
46
|
+
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
47
|
+
Axlsx::Workbook.date1904 = :true
|
48
|
+
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_add_defined_name
|
52
|
+
@wb.add_defined_name 'Sheet1!1:1', :name => '_xlnm.Print_Titles', :hidden => true
|
53
|
+
assert_equal(1, @wb.defined_names.size)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_add_view
|
57
|
+
@wb.add_view visibility: :hidden, window_width: 800
|
58
|
+
assert_equal(1, @wb.views.size)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_shared_strings
|
62
|
+
assert_equal(@wb.use_shared_strings, nil)
|
63
|
+
assert_raise(ArgumentError) {@wb.use_shared_strings = 'bpb'}
|
64
|
+
assert_nothing_raised {@wb.use_shared_strings = :true}
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_add_worksheet
|
68
|
+
assert(@wb.worksheets.empty?, "worbook has no worksheets by default")
|
69
|
+
ws = @wb.add_worksheet(:name=>"bob")
|
70
|
+
assert_equal(@wb.worksheets.size, 1, "add_worksheet adds a worksheet!")
|
71
|
+
assert_equal(@wb.worksheets.first, ws, "the worksheet returned is the worksheet added")
|
72
|
+
assert_equal(ws.name, "bob", "name option gets passed to worksheet")
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_insert_worksheet
|
76
|
+
@wb.add_worksheet(:name => 'A')
|
77
|
+
@wb.add_worksheet(:name => 'B')
|
78
|
+
ws3 = @wb.insert_worksheet(0, :name => 'C')
|
79
|
+
assert_equal(ws3.name, @wb.worksheets.first.name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_relationships
|
83
|
+
#current relationship size is 1 due to style relation
|
84
|
+
assert(@wb.relationships.size == 1)
|
85
|
+
@wb.add_worksheet
|
86
|
+
assert(@wb.relationships.size == 2)
|
87
|
+
@wb.use_shared_strings = true
|
88
|
+
assert(@wb.relationships.size == 3)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_to_xml
|
92
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
93
|
+
doc = Nokogiri::XML(@wb.to_xml_string)
|
94
|
+
errors = []
|
95
|
+
schema.validate(doc).each do |error|
|
96
|
+
errors.push error
|
97
|
+
puts error.message
|
98
|
+
end
|
99
|
+
assert(errors.empty?, "error free validation")
|
100
|
+
end
|
101
|
+
def test_range_requires__valid_sheet
|
102
|
+
ws = @wb.add_worksheet :name=>'fish'
|
103
|
+
ws.add_row [1,2,3]
|
104
|
+
ws.add_row [4,5,6]
|
105
|
+
assert_raise(ArgumentError, "no sheet name part") { @wb["A1:C2"]}
|
106
|
+
assert_equal @wb['fish!A1:C2'].size, 6
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_to_xml_adds_worksheet_when_worksheets_is_empty
|
110
|
+
assert(@wb.worksheets.empty?)
|
111
|
+
@wb.to_xml_string
|
112
|
+
assert(@wb.worksheets.size == 1)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_to_xml_string_defined_names
|
116
|
+
@wb.add_worksheet do |sheet|
|
117
|
+
sheet.add_row [1, "two"]
|
118
|
+
sheet.auto_filter = "A1:B1"
|
119
|
+
end
|
120
|
+
doc = Nokogiri::XML(@wb.to_xml_string)
|
121
|
+
assert_equal(doc.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, @wb.worksheets[0].auto_filter.defined_name)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_to_xml_string_book_views
|
125
|
+
@wb.add_worksheet do |sheet|
|
126
|
+
sheet.add_row [1, "two"]
|
127
|
+
end
|
128
|
+
@wb.add_view active_tab: 0, first_sheet: 0
|
129
|
+
doc = Nokogiri::XML(@wb.to_xml_string)
|
130
|
+
assert_equal(1, doc.xpath('//xmlns:workbook/xmlns:bookViews/xmlns:workbookView[@activeTab=0]').size)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_to_xml_uses_correct_rIds_for_pivotCache
|
134
|
+
ws = @wb.add_worksheet
|
135
|
+
pivot_table = ws.add_pivot_table('G5:G6', 'A1:D5')
|
136
|
+
doc = Nokogiri::XML(@wb.to_xml_string)
|
137
|
+
assert_equal pivot_table.cache_definition.rId, doc.xpath("//xmlns:pivotCache").first["r:id"]
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_worksheet_name_is_intact_after_serialized_into_xml
|
141
|
+
sheet = @wb.add_worksheet(:name => '_Example')
|
142
|
+
wb_xml = Nokogiri::XML(@wb.to_xml_string)
|
143
|
+
assert_equal sheet.name, wb_xml.xpath('//xmlns:workbook/xmlns:sheets/*[1]/@name').to_s
|
144
|
+
end
|
145
|
+
end
|