axlsx 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/Rakefile +13 -0
  2. data/lib/axlsx.rb +38 -0
  3. data/lib/axlsx/content_type/content_type.rb +23 -0
  4. data/lib/axlsx/content_type/default.rb +32 -0
  5. data/lib/axlsx/content_type/override.rb +30 -0
  6. data/lib/axlsx/doc_props/app.rb +148 -0
  7. data/lib/axlsx/doc_props/core.rb +34 -0
  8. data/lib/axlsx/drawing/axis.rb +78 -0
  9. data/lib/axlsx/drawing/bar_3D_chart.rb +138 -0
  10. data/lib/axlsx/drawing/bar_series.rb +91 -0
  11. data/lib/axlsx/drawing/cat_axis.rb +58 -0
  12. data/lib/axlsx/drawing/chart.rb +120 -0
  13. data/lib/axlsx/drawing/drawing.rb +121 -0
  14. data/lib/axlsx/drawing/graphic_frame.rb +55 -0
  15. data/lib/axlsx/drawing/marker.rb +57 -0
  16. data/lib/axlsx/drawing/pie_3D_chart.rb +59 -0
  17. data/lib/axlsx/drawing/pie_series.rb +88 -0
  18. data/lib/axlsx/drawing/scaling.rb +53 -0
  19. data/lib/axlsx/drawing/series.rb +70 -0
  20. data/lib/axlsx/drawing/title.rb +69 -0
  21. data/lib/axlsx/drawing/two_cell_anchor.rb +88 -0
  22. data/lib/axlsx/drawing/val_axis.rb +34 -0
  23. data/lib/axlsx/drawing/view_3D.rb +72 -0
  24. data/lib/axlsx/package.rb +181 -0
  25. data/lib/axlsx/rels/relationship.rb +43 -0
  26. data/lib/axlsx/rels/relationships.rb +25 -0
  27. data/lib/axlsx/stylesheet/border.rb +52 -0
  28. data/lib/axlsx/stylesheet/border_pr.rb +65 -0
  29. data/lib/axlsx/stylesheet/cell_alignment.rb +96 -0
  30. data/lib/axlsx/stylesheet/cell_protection.rb +33 -0
  31. data/lib/axlsx/stylesheet/cell_style.rb +60 -0
  32. data/lib/axlsx/stylesheet/color.rb +57 -0
  33. data/lib/axlsx/stylesheet/fill.rb +31 -0
  34. data/lib/axlsx/stylesheet/font.rb +128 -0
  35. data/lib/axlsx/stylesheet/gradient_fill.rb +70 -0
  36. data/lib/axlsx/stylesheet/gradient_stop.rb +31 -0
  37. data/lib/axlsx/stylesheet/num_fmt.rb +61 -0
  38. data/lib/axlsx/stylesheet/pattern_fill.rb +64 -0
  39. data/lib/axlsx/stylesheet/styles.rb +296 -0
  40. data/lib/axlsx/stylesheet/table_style.rb +44 -0
  41. data/lib/axlsx/stylesheet/table_style_element.rb +66 -0
  42. data/lib/axlsx/stylesheet/table_styles.rb +39 -0
  43. data/lib/axlsx/stylesheet/xf.rb +117 -0
  44. data/lib/axlsx/util/constants.rb +189 -0
  45. data/lib/axlsx/util/simple_typed_list.rb +150 -0
  46. data/lib/axlsx/util/validators.rb +132 -0
  47. data/lib/axlsx/workbook/workbook.rb +130 -0
  48. data/lib/axlsx/workbook/worksheet/cell.rb +184 -0
  49. data/lib/axlsx/workbook/worksheet/row.rb +92 -0
  50. data/lib/axlsx/workbook/worksheet/worksheet.rb +194 -0
  51. data/lib/schema/dc.xsd +118 -0
  52. data/lib/schema/dcmitype.xsd +50 -0
  53. data/lib/schema/dcterms.xsd +331 -0
  54. data/lib/schema/dml-chart.xsd +1499 -0
  55. data/lib/schema/dml-chartDrawing.xsd +146 -0
  56. data/lib/schema/dml-compatibility.xsd +14 -0
  57. data/lib/schema/dml-diagram.xsd +1091 -0
  58. data/lib/schema/dml-lockedCanvas.xsd +11 -0
  59. data/lib/schema/dml-main.xsd +3048 -0
  60. data/lib/schema/dml-picture.xsd +23 -0
  61. data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
  62. data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
  63. data/lib/schema/opc-contentTypes.xsd +42 -0
  64. data/lib/schema/opc-coreProperties.xsd +50 -0
  65. data/lib/schema/opc-digSig.xsd +49 -0
  66. data/lib/schema/opc-relationships.xsd +33 -0
  67. data/lib/schema/pml.xsd +1676 -0
  68. data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
  69. data/lib/schema/shared-bibliography.xsd +144 -0
  70. data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
  71. data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
  72. data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
  73. data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
  74. data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
  75. data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
  76. data/lib/schema/shared-math.xsd +582 -0
  77. data/lib/schema/shared-relationshipReference.xsd +25 -0
  78. data/lib/schema/sml.xsd +4430 -0
  79. data/lib/schema/vml-main.xsd +569 -0
  80. data/lib/schema/vml-officeDrawing.xsd +509 -0
  81. data/lib/schema/vml-presentationDrawing.xsd +12 -0
  82. data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
  83. data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
  84. data/lib/schema/wml.xsd +3644 -0
  85. data/lib/schema/xml.xsd +117 -0
  86. data/test/content_type/tc_content_type.rb +81 -0
  87. data/test/content_type/tc_content_type.rb~ +81 -0
  88. data/test/content_type/tc_default.rb +40 -0
  89. data/test/content_type/tc_default.rb~ +40 -0
  90. data/test/content_type/tc_override.rb +40 -0
  91. data/test/content_type/tc_override.rb~ +40 -0
  92. data/test/doc_props/tc_app.rb +19 -0
  93. data/test/doc_props/tc_app.rb~ +19 -0
  94. data/test/doc_props/tc_core.rb +34 -0
  95. data/test/drawing/tc_axis.rb +39 -0
  96. data/test/drawing/tc_axis.rb~ +0 -0
  97. data/test/drawing/tc_bar_3D_chart.rb +66 -0
  98. data/test/drawing/tc_bar_3D_chart.rb~ +4 -0
  99. data/test/drawing/tc_bar_series.rb +34 -0
  100. data/test/drawing/tc_bar_series.rb~ +31 -0
  101. data/test/drawing/tc_cat_axis.rb +32 -0
  102. data/test/drawing/tc_cat_axis.rb~ +39 -0
  103. data/test/drawing/tc_chart.rb +59 -0
  104. data/test/drawing/tc_chart.rb~ +58 -0
  105. data/test/drawing/tc_drawing.rb +71 -0
  106. data/test/drawing/tc_graphic_frame.rb +26 -0
  107. data/test/drawing/tc_graphic_frame.rb~ +21 -0
  108. data/test/drawing/tc_marker.rb +45 -0
  109. data/test/drawing/tc_marker.rb~ +26 -0
  110. data/test/drawing/tc_pie_3D_chart.rb +33 -0
  111. data/test/drawing/tc_pie_3D_chart.rb~ +58 -0
  112. data/test/drawing/tc_pie_series.rb +35 -0
  113. data/test/drawing/tc_pie_series.rb~ +26 -0
  114. data/test/drawing/tc_scaling.rb +37 -0
  115. data/test/drawing/tc_scaling.rb~ +45 -0
  116. data/test/drawing/tc_series.rb +24 -0
  117. data/test/drawing/tc_series.rb~ +31 -0
  118. data/test/drawing/tc_title.rb +34 -0
  119. data/test/drawing/tc_title.rb~ +37 -0
  120. data/test/drawing/tc_two_cell_anchor.rb +37 -0
  121. data/test/drawing/tc_two_cell_anchor.rb~ +35 -0
  122. data/test/drawing/tc_val_axis.rb +20 -0
  123. data/test/drawing/tc_val_axis.rb~ +32 -0
  124. data/test/drawing/tc_view_3D.rb +46 -0
  125. data/test/drawing/tc_view_3D.rb~ +37 -0
  126. data/test/rels/tc_relationship.rb +16 -0
  127. data/test/rels/tc_relationship.rb~ +39 -0
  128. data/test/rels/tc_relationships.rb +32 -0
  129. data/test/rels/tc_relationships.rb~ +37 -0
  130. data/test/stylesheet/tc_border.rb +38 -0
  131. data/test/stylesheet/tc_border.rb~ +31 -0
  132. data/test/stylesheet/tc_border_pr.rb +33 -0
  133. data/test/stylesheet/tc_border_pr.rb~ +31 -0
  134. data/test/stylesheet/tc_cell_alignment.rb +77 -0
  135. data/test/stylesheet/tc_cell_alignment.rb~ +38 -0
  136. data/test/stylesheet/tc_cell_protection.rb +30 -0
  137. data/test/stylesheet/tc_cell_protection.rb~ +77 -0
  138. data/test/stylesheet/tc_cell_style.rb +58 -0
  139. data/test/stylesheet/tc_cell_style.rb~ +30 -0
  140. data/test/stylesheet/tc_color.rb +38 -0
  141. data/test/stylesheet/tc_color.rb~ +38 -0
  142. data/test/stylesheet/tc_fill.rb +19 -0
  143. data/test/stylesheet/tc_fill.rb~ +19 -0
  144. data/test/stylesheet/tc_font.rb +114 -0
  145. data/test/stylesheet/tc_font.rb~ +19 -0
  146. data/test/stylesheet/tc_gradient_fill.rb +65 -0
  147. data/test/stylesheet/tc_gradient_fill.rb~ +114 -0
  148. data/test/stylesheet/tc_gradient_stop.rb +32 -0
  149. data/test/stylesheet/tc_gradient_stop.rb~ +65 -0
  150. data/test/stylesheet/tc_num_fmt.rb +31 -0
  151. data/test/stylesheet/tc_num_fmt.rb~ +32 -0
  152. data/test/stylesheet/tc_pattern_fill.rb +38 -0
  153. data/test/stylesheet/tc_pattern_fill.rb~ +31 -0
  154. data/test/stylesheet/tc_styles.rb +64 -0
  155. data/test/stylesheet/tc_table_style.rb +37 -0
  156. data/test/stylesheet/tc_table_style.rb~ +38 -0
  157. data/test/stylesheet/tc_table_style_element.rb +37 -0
  158. data/test/stylesheet/tc_table_style_element.rb~ +37 -0
  159. data/test/stylesheet/tc_table_styles.rb +30 -0
  160. data/test/stylesheet/tc_table_styles.rb~ +37 -0
  161. data/test/stylesheet/tc_xf.rb +121 -0
  162. data/test/stylesheet/tc_xf.rb~ +30 -0
  163. data/test/tc_app.rb~ +19 -0
  164. data/test/tc_border_pr.rb~ +21 -0
  165. data/test/tc_package.rb +70 -0
  166. data/test/tc_package.rb~ +64 -0
  167. data/test/tc_pie_3D_chart.rb~ +66 -0
  168. data/test/tc_relationships.rb~ +37 -0
  169. data/test/tc_series.rb~ +31 -0
  170. data/test/tc_styles.rb~ +64 -0
  171. data/test/tc_validators.rb~ +77 -0
  172. data/test/tc_worksheet.rb~ +85 -0
  173. data/test/util/tc_simple_typed_list.rb +66 -0
  174. data/test/util/tc_validators.rb +76 -0
  175. data/test/workbook/tc_workbook.rb +53 -0
  176. data/test/workbook/worksheet/tc_cell.rb +78 -0
  177. data/test/workbook/worksheet/tc_row.rb +30 -0
  178. data/test/workbook/worksheet/tc_worksheet.rb +85 -0
  179. metadata +378 -0
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestApp < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+ def teardown
8
+ end
9
+
10
+ def test_valid_document
11
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::APP_XSD))
12
+ doc = Nokogiri::XML(Axlsx::App.new.to_xml)
13
+ errors = []
14
+ schema.validate(doc).each do |error|
15
+ errors << error
16
+ end
17
+ assert_equal(errors.size, 0, "app.xml invalid" + errors.map{ |e| e.message }.to_s)
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestCore < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @core = Axlsx::Core.new
8
+ @doc = Nokogiri::XML(@core.to_xml)
9
+ end
10
+
11
+ def test_valid_document
12
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::CORE_XSD))
13
+ errors = []
14
+ schema.validate(@doc).each do |error|
15
+ puts error.message
16
+ errors << error
17
+ end
18
+ assert_equal(errors.size, 0, "core.xml Invalid" + errors.map{ |e| e.message }.to_s)
19
+ end
20
+
21
+ def test_populates_created
22
+ assert_equal(@doc.xpath('//dcterms:created').text, Time.now.strftime('%Y-%m-%dT%H:%M:%S'), "dcterms:created incorrect")
23
+ end
24
+
25
+ def test_populates_default_name
26
+ assert_equal(@doc.xpath('//dc:creator').text, "axlsx", "Default name not populated")
27
+ end
28
+
29
+ def test_creator_as_option
30
+ c = Axlsx::Core.new :creator => "some guy"
31
+ doc = Nokogiri::XML(c.to_xml)
32
+ assert(doc.xpath('//dc:creator').text == "some guy")
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestAxis < Test::Unit::TestCase
5
+ def setup
6
+ @axis = Axlsx::Axis.new 12345, 54321
7
+ end
8
+ def teardown
9
+ end
10
+
11
+ def test_initialization
12
+ assert_equal(@axis.axPos, :l, "axis position default incorrect")
13
+ assert_equal(@axis.tickLblPos, :nextTo, "tick label position default incorrect")
14
+ assert_equal(@axis.tickLblPos, :nextTo, "tick label position default incorrect")
15
+ assert_equal(@axis.crosses, :autoZero, "tick label position default incorrect")
16
+ assert(@axis.scaling.is_a?(Axlsx::Scaling) && @axis.scaling.orientation == :minMax, "scaling default incorrect")
17
+ end
18
+
19
+ def test_axis_position
20
+ assert_raise(ArgumentError, "requires valid axis position") { @axis.axPos = :nowhere }
21
+ assert_nothing_raised("accepts valid axis position") { @axis.axPos = :r }
22
+ end
23
+
24
+ def test_tick_label_position
25
+ assert_raise(ArgumentError, "requires valid tick label position") { @axis.tickLblPos = :nowhere }
26
+ assert_nothing_raised("accepts valid tick label position") { @axis.tickLblPos = :high }
27
+ end
28
+
29
+ def test_format_code
30
+ assert_raise(ArgumentError, "requires valid format code") { @axis.format_code = 1 }
31
+ assert_nothing_raised("accepts valid format code") { @axis.tickLblPos = :high }
32
+ end
33
+
34
+ def test_crosses
35
+ assert_raise(ArgumentError, "requires valid crosses") { @axis.crosses = 1 }
36
+ assert_nothing_raised("accepts valid crosses") { @axis.crosses = :min }
37
+ end
38
+
39
+ end
File without changes
@@ -0,0 +1,66 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestBar3DChart < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @p = Axlsx::Package.new
8
+ ws = @p.workbook.add_worksheet
9
+ @row = ws.add_row :values=>["one", 1, Time.now]
10
+ @chart = ws.add_chart Axlsx::Bar3DChart, :title => "fishery"
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_initialization
17
+ assert_equal(@chart.grouping, :clustered, "grouping defualt incorrect")
18
+ assert_equal(@chart.series_type, Axlsx::BarSeries, "series type incorrect")
19
+ assert_equal(@chart.barDir, :bar, " bar direction incorrect")
20
+ assert(@chart.catAxis.is_a?(Axlsx::CatAxis), "category axis not created")
21
+ assert(@chart.valAxis.is_a?(Axlsx::ValAxis), "value access not created")
22
+ end
23
+
24
+ def test_bar_direction
25
+ assert_raise(ArgumentError, "require valid bar direction") { @chart.barDir = :left }
26
+ assert_nothing_raised("allow valid bar direction") { @chart.barDir = :col }
27
+ assert(@chart.barDir == :col)
28
+ end
29
+
30
+ def test_grouping
31
+ assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
32
+ assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard }
33
+ assert(@chart.grouping == :standard)
34
+ end
35
+
36
+
37
+ def test_gapWidth
38
+ assert_raise(ArgumentError, "require valid gap width") { @chart.gapWidth = 200 }
39
+ assert_nothing_raised("allow valid gapWidth") { @chart.gapWidth = "200%" }
40
+ assert(@chart.gapWidth == "200%")
41
+ end
42
+
43
+ def test_gapDepth
44
+ assert_raise(ArgumentError, "require valid gapDepth") { @chart.gapDepth = 200 }
45
+ assert_nothing_raised("allow valid gapDepth") { @chart.gapDepth = "200%" }
46
+ assert(@chart.gapDepth == "200%")
47
+ end
48
+
49
+ def test_shape
50
+ assert_raise(ArgumentError, "require valid shape") { @chart.shape = :star }
51
+ assert_nothing_raised("allow valid shape") { @chart.shape = :cone }
52
+ assert(@chart.shape == :cone)
53
+ end
54
+
55
+ def test_to_xml
56
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
57
+ doc = Nokogiri::XML(@chart.to_xml)
58
+ errors = []
59
+ schema.validate(doc).each do |error|
60
+ errors.push error
61
+ puts error.message
62
+ end
63
+ assert(errors.empty?, "error free validation")
64
+ end
65
+
66
+ end
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestBar3DChart < Test::Unit::TestCase
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestBarSeries < Test::Unit::TestCase
5
+
6
+ def setup
7
+ p = Axlsx::Package.new
8
+ @ws = p.workbook.add_worksheet :name=>"hmmm"
9
+ chart = @ws.drawing.add_chart Axlsx::Bar3DChart, :title => "fishery"
10
+ @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob"
11
+ end
12
+
13
+ def test_initialize
14
+ assert_equal(@series.title, "bob", "series title has been applied")
15
+ assert_equal(@series.data, [0,1,2], "data option applied")
16
+ assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
17
+ assert_equal(@series.shape, :box, "series shape has been applied")
18
+ end
19
+
20
+ def test_data
21
+ assert_equal(@series.data, [0,1,2])
22
+ end
23
+
24
+ def test_labels
25
+ assert_equal(@series.labels, ["zero", "one", "two"])
26
+ end
27
+
28
+ def test_shape
29
+ assert_raise(ArgumentError, "require valid shape") { @series.shape = :teardropt }
30
+ assert_nothing_raised("allow valid shape") { @series.shape = :cone }
31
+ assert(@series.shape == :cone)
32
+ end
33
+
34
+ end
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestSeries < Test::Unit::TestCase
5
+
6
+ def setup
7
+ p = Axlsx::Package.new
8
+ @ws = p.workbook.add_worksheet :name=>"hmmm"
9
+ chart = @ws.drawing.add_chart Axlsx::Bar3DChart, :title => "fishery"
10
+ @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob"
11
+ end
12
+
13
+ def test_initialize
14
+ assert_equal(@series.title, "bob", "series title has been applied")
15
+ assert_equal(@series.data, [0,1,2], "data option applied")
16
+ assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
17
+ end
18
+
19
+ def test_range
20
+ labels = @ws.add_row :values=>["one", "two", "three"]
21
+ data = @ws.add_row :values=>[1,2,3]
22
+ s = @series.chart.add_series :data=>data.cells, :labels=>labels.cells
23
+ assert_equal(s.send(:range, s.data), "#{@ws.name}!$A$2:$C$2", "range is created created from cells")
24
+ assert_equal(s.send(:range, s.labels), "#{@ws.name}!$A$1:$C$1", "range is created from cells")
25
+ assert_equal(@series.send(:range, @series.data), "", "no range if the data is a simple array")
26
+ end
27
+
28
+ def test_index
29
+ assert_equal(@series.index, @series.chart.series.index(@series))
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestCatAxis < Test::Unit::TestCase
5
+ def setup
6
+ @axis = Axlsx::CatAxis.new 12345, 54321
7
+ end
8
+ def teardown
9
+ end
10
+
11
+ def test_initialization
12
+ assert_equal(@axis.auto, true, "axis auto default incorrect")
13
+ assert_equal(@axis.lblAlgn, :ctr, "label align default incorrect")
14
+ assert_equal(@axis.lblOffset, "100%", "label offset default incorrect")
15
+ end
16
+
17
+ def test_auto
18
+ assert_raise(ArgumentError, "requires valid auto") { @axis.auto = :nowhere }
19
+ assert_nothing_raised("accepts valid auto") { @axis.auto = false }
20
+ end
21
+
22
+ def test_lblAlgn
23
+ assert_raise(ArgumentError, "requires valid label alignment") { @axis.lblAlgn = :nowhere }
24
+ assert_nothing_raised("accepts valid label alignment") { @axis.lblAlgn = :r }
25
+ end
26
+
27
+ def test_lblOffset
28
+ assert_raise(ArgumentError, "requires valid label offset") { @axis.lblOffset = 100 }
29
+ assert_nothing_raised("accepts valid label offset") { @axis.lblOffset = "20%" }
30
+ end
31
+
32
+ end
@@ -0,0 +1,39 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestAxis < Test::Unit::TestCase
5
+ def setup
6
+ @axis = Axlsx::Axis.new 12345, 54321
7
+ end
8
+ def teardown
9
+ end
10
+
11
+ def test_initialization
12
+ assert_equal(@axis.axPos, :l, "axis position default incorrect")
13
+ assert_equal(@axis.tickLblPos, :nextTo, "tick label position default incorrect")
14
+ assert_equal(@axis.tickLblPos, :nextTo, "tick label position default incorrect")
15
+ assert_equal(@axis.crosses, :autoZero, "tick label position default incorrect")
16
+ assert(@axis.scaling.is_a?(Axlsx::Scaling) && @axis.scaling.orientation == :minMax, "scaling default incorrect")
17
+ end
18
+
19
+ def test_axis_position
20
+ assert_raise(ArgumentError, "requires valid axis position") { @axis.axPos = :nowhere }
21
+ assert_nothing_raised("accepts valid axis position") { @axis.axPos = :r }
22
+ end
23
+
24
+ def test_tick_label_position
25
+ assert_raise(ArgumentError, "requires valid tick label position") { @axis.tickLblPos = :nowhere }
26
+ assert_nothing_raised("accepts valid tick label position") { @axis.tickLblPos = :high }
27
+ end
28
+
29
+ def test_format_code
30
+ assert_raise(ArgumentError, "requires valid format code") { @axis.format_code = 1 }
31
+ assert_nothing_raised("accepts valid format code") { @axis.tickLblPos = :high }
32
+ end
33
+
34
+ def test_crosses
35
+ assert_raise(ArgumentError, "requires valid crosses") { @axis.crosses = 1 }
36
+ assert_nothing_raised("accepts valid crosses") { @axis.crosses = :min }
37
+ end
38
+
39
+ end
@@ -0,0 +1,59 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestChart < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @p = Axlsx::Package.new
8
+ ws = @p.workbook.add_worksheet
9
+ @row = ws.add_row :values=>["one", 1, Time.now]
10
+ @chart = ws.add_chart Axlsx::Bar3DChart, :title => "fishery"
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_initialization
17
+ assert_equal(@p.workbook.charts.last,@chart, "the chart is in the workbook")
18
+ assert_equal(@chart.title.text, "fishery", "the title option has been applied")
19
+ assert((@chart.series.is_a?(Axlsx::SimpleTypedList) && @chart.series.empty?), "The series is initialized and empty")
20
+ end
21
+
22
+ def test_title
23
+ @chart.title.text = 'wowzer'
24
+ assert_equal(@chart.title.text, "wowzer", "the title text via a string")
25
+ assert_equal(@chart.title.cell, nil, "the title cell is nil as we set the title with text.")
26
+ @chart.title.cell = @row.cells.first
27
+ assert_equal(@chart.title.text, "one", "the title text was set via cell reference")
28
+ assert_equal(@chart.title.cell, @row.cells.first)
29
+ end
30
+
31
+
32
+ def test_add_series
33
+ s = @chart.add_series :data=>[0,1,2,3], :labels => ["one", 1, "anything"], :title=>"bob"
34
+ assert_equal(@chart.series.last, s, "series has been added to chart series collection")
35
+ assert_equal(s.title, "bob", "series title has been applied")
36
+ assert_equal(s.data, [0,1,2,3], "data option applied")
37
+ assert_equal(s.labels, ["one",1,"anything"], "labels option applied")
38
+ end
39
+
40
+ def test_create_range
41
+
42
+ end
43
+
44
+ def test_pn
45
+ assert_equal(@chart.pn, "charts/chart1.xml")
46
+ end
47
+
48
+ def test_to_xml
49
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
50
+ doc = Nokogiri::XML(@chart.to_xml)
51
+ errors = []
52
+ schema.validate(doc).each do |error|
53
+ errors.push error
54
+ puts error.message
55
+ end
56
+ assert(errors.empty?, "error free validation")
57
+ end
58
+
59
+ end
@@ -0,0 +1,58 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestChart < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @p = Axlsx::Package.new
8
+ ws = @p.workbook.add_worksheet
9
+ @row = ws.add_row :values=>["one", 1, Time.now]
10
+ @chart = ws.add_chart Axlsx::Bar3DChart, :title => "fishery"
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_initialization
17
+ assert_equal(@p.workbook.charts.last,@chart, "the chart is in the workbook")
18
+ assert_equal(@chart.title.text, "fishery", "the title option has been applied")
19
+ assert((@chart.series.is_a?(Axlsx::SimpleTypedList) && @chart.series.empty?), "The series is initialized and empty")
20
+ end
21
+
22
+ def test_title
23
+ @chart.title.text = 'wowzer'
24
+ assert_equal(@chart.title.text, "wowzer", "the title text via a string")
25
+ assert_equal(@chart.title.cell, nil, "the title cell is nil as we set the title with text.")
26
+ @chart.title.cell = @row.cells.first
27
+ assert_equal(@chart.title.text, "one", "the title text was set via cell reference")
28
+ assert_equal(@chart.title.cell, @row.cells.first)
29
+ end
30
+
31
+ def test_add_series
32
+ s = @chart.add_series :data=>[0,1,2,3], :labels => ["one", 1, "anything"], :title=>"bob"
33
+ assert_equal(@chart.series.last, s, "series has been added to chart series collection")
34
+ assert_equal(s.title, "bob", "series title has been applied")
35
+ assert_equal(s.data, [0,1,2,3], "data option applied")
36
+ assert_equal(s.labels, ["one",1,"anything"], "labels option applied")
37
+ end
38
+
39
+ def test_create_range
40
+
41
+ end
42
+
43
+ def test_pn
44
+ assert_equal(@chart.pn, "charts/chart1.xml")
45
+ end
46
+
47
+ def test_to_xml
48
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
49
+ doc = Nokogiri::XML(@chart.to_xml)
50
+ errors = []
51
+ schema.validate(doc).each do |error|
52
+ errors.push error
53
+ puts error.message
54
+ end
55
+ assert(errors.empty?, "error free validation")
56
+ end
57
+
58
+ end
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestDrawing < Test::Unit::TestCase
5
+ def setup
6
+ p = Axlsx::Package.new
7
+ @ws = p.workbook.add_worksheet
8
+
9
+ end
10
+
11
+ def test_initialization
12
+ assert(@ws.workbook.drawings.empty?)
13
+ assert_equal(@ws.drawing, @ws.workbook.drawings.last, "drawing is added to workbook")
14
+ assert(@ws.drawing.anchors.is_a?(Axlsx::SimpleTypedList) && @ws.drawing.anchors.empty?, "anchor list is created and empty")
15
+ end
16
+
17
+ def test_add_chart
18
+ chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
19
+ assert(chart.is_a?(Axlsx::Pie3DChart), "must create a chart")
20
+ assert_equal(@ws.workbook.charts.last, chart, "must be added to workbook charts collection")
21
+ assert_equal(@ws.drawing.anchors.last.graphic_frame.chart, chart, "an anchor has been created and holds a reference to this chart")
22
+ anchor = @ws.drawing.anchors.last
23
+ assert_equal([anchor.from.row, anchor.from.col], [0,0], "options for start at are applied")
24
+ assert_equal([anchor.to.row, anchor.to.col], [1,1], "options for start at are applied")
25
+ assert_equal(chart.title.text, "bob", "option for title is applied")
26
+ end
27
+
28
+ def test_charts
29
+ assert(@ws.drawing.charts.empty?)
30
+ chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
31
+ assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
32
+ chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
33
+ assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
34
+ end
35
+
36
+ def test_pn
37
+ assert_equal(@ws.drawing.pn, "drawings/drawing1.xml")
38
+ end
39
+
40
+ def test_rels_pn
41
+ assert_equal(@ws.drawing.rels_pn, "drawings/_rels/drawing1.xml.rels")
42
+ end
43
+
44
+ def test_rId
45
+ assert_equal(@ws.drawing.rId, "rId1")
46
+ end
47
+
48
+ def test_index
49
+ assert_equal(@ws.drawing.index, @ws.workbook.drawings.index(@ws.drawing))
50
+ end
51
+
52
+ def test_relationships
53
+ assert(@ws.drawing.relationships.empty?)
54
+ chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
55
+ assert_equal(@ws.drawing.relationships.size, 1, "adding a chart adds a relationship")
56
+ chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
57
+ assert_equal(@ws.drawing.relationships.size, 2, "adding a chart adds a relationship")
58
+ end
59
+
60
+ def test_to_xml
61
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
62
+ doc = Nokogiri::XML(@ws.drawing.to_xml)
63
+ errors = []
64
+ schema.validate(doc).each do |error|
65
+ errors.push error
66
+ puts error.message
67
+ end
68
+ assert(errors.empty?, "error free validation")
69
+ end
70
+
71
+ end