axlsx 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -3
- data/Rakefile +7 -1
- data/examples/chart_colors.rb +1 -1
- data/examples/chart_colors.xlsx +0 -0
- data/examples/doc/_index.html +84 -0
- data/examples/doc/class_list.html +47 -0
- data/examples/doc/css/common.css +1 -0
- data/examples/doc/css/full_list.css +55 -0
- data/examples/doc/css/style.css +322 -0
- data/examples/doc/file_list.html +46 -0
- data/examples/doc/frames.html +13 -0
- data/examples/doc/index.html +84 -0
- data/examples/doc/js/app.js +205 -0
- data/examples/doc/js/full_list.js +173 -0
- data/examples/doc/js/jquery.js +16 -0
- data/examples/doc/method_list.html +46 -0
- data/examples/doc/top-level-namespace.html +95 -0
- data/examples/example.rb +12 -5
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.rb +3 -0
- data/lib/axlsx.rb +4 -4
- data/lib/axlsx/drawing/drawing.rb +7 -2
- data/lib/axlsx/drawing/graphic_frame.rb +2 -1
- data/lib/axlsx/drawing/num_data_source.rb +3 -0
- data/lib/axlsx/drawing/vml_drawing.rb +42 -0
- data/lib/axlsx/drawing/vml_drawing.rb~ +6 -0
- data/lib/axlsx/drawing/vml_shape.rb +128 -0
- data/lib/axlsx/drawing/vml_shape.rb~ +61 -0
- data/lib/axlsx/package.rb +24 -0
- data/lib/axlsx/rels/relationships.rb +0 -10
- data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
- data/lib/axlsx/util/constants.rb +24 -0
- data/lib/axlsx/util/validators.rb +32 -4
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +21 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +4 -2
- data/lib/axlsx/workbook/worksheet/comment.rb +107 -0
- data/lib/axlsx/workbook/worksheet/comment.rb~ +91 -0
- data/lib/axlsx/workbook/worksheet/comments.rb +77 -0
- data/lib/axlsx/workbook/worksheet/comments.rb~ +86 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +90 -0
- data/lib/axlsx/workbook/worksheet/print_options.rb +63 -0
- data/lib/axlsx/workbook/worksheet/row.rb +2 -2
- data/lib/axlsx/workbook/worksheet/worksheet.rb +72 -9
- data/test/doc_props/tc_core.rb +3 -1
- data/test/drawing/tc_hyperlink.rb +4 -0
- data/test/drawing/tc_line_series.rb +6 -2
- data/test/drawing/tc_pie_series.rb +6 -1
- data/test/drawing/tc_vml_drawing.rb +25 -0
- data/{examples/#extractive.csv# → test/drawing/tc_vml_drawing.rb~} +0 -0
- data/test/drawing/tc_vml_shape.rb +100 -0
- data/test/rels/tc_relationship.rb +1 -0
- data/test/stylesheet/tc_gradient_fill.rb +8 -0
- data/test/stylesheet/tc_pattern_fill.rb +7 -1
- data/test/tc_helper.rb +1 -0
- data/test/tc_package.rb +16 -5
- data/test/util/tc_validators.rb +29 -0
- data/test/workbook/worksheet/tc_cell.rb +17 -0
- data/test/workbook/worksheet/tc_comment.rb +56 -0
- data/test/workbook/worksheet/tc_comments.rb +50 -0
- data/test/workbook/worksheet/tc_page_setup.rb +103 -0
- data/test/workbook/worksheet/tc_print_options.rb +72 -0
- data/test/workbook/worksheet/tc_row.rb +19 -13
- data/test/workbook/worksheet/tc_worksheet.rb +60 -7
- metadata +56 -24
- data/examples/#extractive.rb# +0 -45
- data/examples/chart_colors.rb~ +0 -0
- data/examples/colored_series_data.xlsx +0 -0
- data/examples/example.csv +0 -1000
- data/examples/extractive.csv +0 -1
- data/examples/extractive.csv~ +0 -1
- data/examples/extractive.rb~ +0 -3
- data/examples/extractive.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/stack.rb +0 -21
- data/examples/stack.rb~ +0 -27
- data/examples/stack.xlsx +0 -0
- data/examples/~$chart_colors.xlsx +0 -0
- data/examples/~$extractive.xlsx +0 -0
data/test/doc_props/tc_core.rb
CHANGED
@@ -4,6 +4,8 @@ class TestCore < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
@core = Axlsx::Core.new
|
7
|
+
# could still see some false positives if the second changes between the next two calls
|
8
|
+
@time = Time.now.strftime('%Y-%m-%dT%H:%M:%S')
|
7
9
|
@doc = Nokogiri::XML(@core.to_xml_string)
|
8
10
|
end
|
9
11
|
|
@@ -18,7 +20,7 @@ class TestCore < Test::Unit::TestCase
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def test_populates_created
|
21
|
-
assert_equal(@doc.xpath('//dcterms:created').text,
|
23
|
+
assert_equal(@doc.xpath('//dcterms:created').text, @time, "dcterms:created incorrect")
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_populates_default_name
|
@@ -6,7 +6,7 @@ class TestLineSeries < Test::Unit::TestCase
|
|
6
6
|
p = Axlsx::Package.new
|
7
7
|
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
8
8
|
chart = @ws.drawing.add_chart Axlsx::Line3DChart, :title => "fishery"
|
9
|
-
@series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob"
|
9
|
+
@series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob", :color => "#FF0000"
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_initialize
|
@@ -15,6 +15,10 @@ class TestLineSeries < Test::Unit::TestCase
|
|
15
15
|
assert_equal(@series.data.class, Axlsx::NumDataSource)
|
16
16
|
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
|
+
def test_to_xml_string
|
20
|
+
doc = Nokogiri::XML(@series.to_xml_string)
|
21
|
+
assert(doc.xpath("//srgbClr[@val='#{@series.color}']"))
|
22
|
+
end
|
19
23
|
#TODO serialization testing
|
20
24
|
end
|
@@ -6,7 +6,7 @@ class TestPieSeries < Test::Unit::TestCase
|
|
6
6
|
p = Axlsx::Package.new
|
7
7
|
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
8
8
|
chart = @ws.drawing.add_chart Axlsx::Pie3DChart, :title => "fishery"
|
9
|
-
@series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob"
|
9
|
+
@series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob", :colors => ["FF0000", "00FF00", "0000FF"]
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_initialize
|
@@ -22,6 +22,11 @@ class TestPieSeries < Test::Unit::TestCase
|
|
22
22
|
assert(@series.explosion == 20)
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_to_xml_string
|
26
|
+
doc = Nokogiri::XML(@series.to_xml_string)
|
27
|
+
assert(doc.xpath("//srgbClr[@val='#{@series.colors[0]}']"))
|
28
|
+
|
29
|
+
end
|
25
30
|
#TODO test unique serialization parts
|
26
31
|
|
27
32
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestVmlDrawing < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
wb = p.workbook
|
8
|
+
@ws = wb.add_worksheet
|
9
|
+
@ws.add_comment :ref => 'A1', :text => 'penut machine', :author => 'crank'
|
10
|
+
@ws.add_comment :ref => 'C3', :text => 'rust bucket', :author => 'PO'
|
11
|
+
@vml_drawing = @ws.comments.vml_drawing
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_initialize
|
15
|
+
assert_raise(ArgumentError) { Axlsx::VmlDrawing.new }
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_to_xml_string
|
19
|
+
str = @vml_drawing.to_xml_string()
|
20
|
+
doc = Nokogiri::XML(str)
|
21
|
+
assert_equal(doc.xpath("//v:shape").size, 2)
|
22
|
+
assert(doc.xpath("//o:idmap[@o:data='#{@ws.index+1}']"))
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestVmlShape < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
wb = p.workbook
|
8
|
+
@ws = wb.add_worksheet
|
9
|
+
@ws.add_comment :ref => 'A1', :text => 'penut machine', :author => 'crank'
|
10
|
+
@ws.add_comment :ref => 'C3', :text => 'rust bucket', :author => 'PO'
|
11
|
+
@comments = @ws.comments
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_initialize
|
15
|
+
assert_raise(ArgumentError) { Axlsx::VmlDrawing.new }
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_row
|
19
|
+
shape = @comments.first.vml_shape
|
20
|
+
assert_equal(shape.row, 0)
|
21
|
+
shape = @comments.last.vml_shape
|
22
|
+
assert_equal(shape.row, 2)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_column
|
26
|
+
shape = @comments.first.vml_shape
|
27
|
+
assert_equal(shape.column, 0)
|
28
|
+
shape = @comments.last.vml_shape
|
29
|
+
assert_equal(shape.column, 2)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_left_column
|
33
|
+
shape = @comments.first.vml_shape
|
34
|
+
shape.left_column = 3
|
35
|
+
assert(shape.left_column == 3)
|
36
|
+
assert_raise(ArgumentError) { shape.left_column = [] }
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_left_offset
|
40
|
+
shape = @comments.first.vml_shape
|
41
|
+
shape.left_offset = 3
|
42
|
+
assert(shape.left_offset == 3)
|
43
|
+
assert_raise(ArgumentError) { shape.left_offset = [] }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_right_column
|
47
|
+
shape = @comments.first.vml_shape
|
48
|
+
shape.right_column = 3
|
49
|
+
assert(shape.right_column == 3)
|
50
|
+
assert_raise(ArgumentError) { shape.right_column = [] }
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_right_offset
|
54
|
+
shape = @comments.first.vml_shape
|
55
|
+
shape.right_offset = 3
|
56
|
+
assert(shape.right_offset == 3)
|
57
|
+
assert_raise(ArgumentError) { shape.right_offset = [] }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_top_offset
|
61
|
+
shape = @comments.first.vml_shape
|
62
|
+
shape.top_offset = 3
|
63
|
+
assert(shape.top_offset == 3)
|
64
|
+
assert_raise(ArgumentError) { shape.top_offset = [] }
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_bottom_offset
|
68
|
+
shape = @comments.first.vml_shape
|
69
|
+
shape.bottom_offset = 3
|
70
|
+
assert(shape.bottom_offset == 3)
|
71
|
+
assert_raise(ArgumentError) { shape.bottom_offset = [] }
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_bottom_row
|
75
|
+
shape = @comments.first.vml_shape
|
76
|
+
shape.bottom_row = 3
|
77
|
+
assert(shape.bottom_row == 3)
|
78
|
+
assert_raise(ArgumentError) { shape.bottom_row = [] }
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_top_row
|
82
|
+
shape = @comments.first.vml_shape
|
83
|
+
shape.top_row = 3
|
84
|
+
assert(shape.top_row == 3)
|
85
|
+
assert_raise(ArgumentError) { shape.top_row = [] }
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_to_xml_string
|
89
|
+
str = @comments.vml_drawing.to_xml_string()
|
90
|
+
doc = Nokogiri::XML(str)
|
91
|
+
assert_equal(doc.xpath("//v:shape").size, 2)
|
92
|
+
@comments.each do |comment|
|
93
|
+
shape = comment.vml_shape
|
94
|
+
assert(doc.xpath("//v:shape/x:ClientData/x:Row[text()='#{shape.row}']").size == 1)
|
95
|
+
assert(doc.xpath("//v:shape/x:ClientData/x:Column[text()='#{shape.column}']").size == 1)
|
96
|
+
assert(doc.xpath("//v:shape/x:ClientData/x:Anchor[text()='#{shape.left_column}, #{shape.left_offset}, #{shape.top_row}, #{shape.top_offset}, #{shape.right_column}, #{shape.right_offset}, #{shape.bottom_row}, #{shape.bottom_offset}']").size == 1)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -10,6 +10,7 @@ class TestRelationships < Test::Unit::TestCase
|
|
10
10
|
def test_type
|
11
11
|
assert_raise(ArgumentError) { Axlsx::Relationship.new 'type', 'target' }
|
12
12
|
assert_nothing_raised { Axlsx::Relationship.new Axlsx::WORKSHEET_R, 'target' }
|
13
|
+
assert_nothing_raised { Axlsx::Relationship.new Axlsx::COMMENT_R, 'target' }
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_target_mode
|
@@ -61,4 +61,12 @@ class TestGradientFill < Test::Unit::TestCase
|
|
61
61
|
assert(@item.stop.size == 1)
|
62
62
|
assert(@item.stop.last.is_a?(Axlsx::GradientStop))
|
63
63
|
end
|
64
|
+
|
65
|
+
def test_to_xml_string
|
66
|
+
@item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(:rgb => "000000"), 0.5)
|
67
|
+
@item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(:rgb => "FFFFFF"), 0.5)
|
68
|
+
@item.type = :path
|
69
|
+
doc = Nokogiri::XML(@item.to_xml_string)
|
70
|
+
assert(doc.xpath("//color[@rgb='FF000000']"))
|
71
|
+
end
|
64
72
|
end
|
@@ -33,5 +33,11 @@ class TestPatternFill < Test::Unit::TestCase
|
|
33
33
|
assert_nothing_raised { @item.patternType = :lightUp }
|
34
34
|
assert_equal(@item.patternType, :lightUp)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
|
+
def test_to_xml_string
|
38
|
+
@item = Axlsx::PatternFill.new :bgColor => Axlsx::Color.new(:rgb => "FF0000"), :fgColor => Axlsx::Color.new(:rgb=>"00FF00")
|
39
|
+
doc = Nokogiri::XML(@item.to_xml_string)
|
40
|
+
assert(doc.xpath('//color[@rgb="FFFF0000"]'))
|
41
|
+
assert(doc.xpath('//color[@rgb="FF00FF00"]'))
|
42
|
+
end
|
37
43
|
end
|
data/test/tc_helper.rb
CHANGED
data/test/tc_package.rb
CHANGED
@@ -4,10 +4,23 @@ class TestPackage < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
@package = Axlsx::Package.new
|
6
6
|
ws = @package.workbook.add_worksheet
|
7
|
+
ws.add_row ['yes', 'we', 'can']
|
8
|
+
ws.add_comment :author => 'bob', :text => 'penny!', :ref => 'A1'
|
7
9
|
chart = ws.add_chart Axlsx::Pie3DChart
|
8
10
|
chart.add_series :data=>[1,2,3], :labels=>["a", "b", "c"]
|
9
11
|
@fname = 'axlsx_test_serialization.xlsx'
|
12
|
+
img = File.expand_path('../../examples/image1.jpeg', __FILE__)
|
13
|
+
ws.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
|
14
|
+
image.width=720
|
15
|
+
image.height=666
|
16
|
+
image.hyperlink.tooltip = "Labeled Link"
|
17
|
+
image.start_at 2, 2
|
18
|
+
end
|
19
|
+
end
|
10
20
|
|
21
|
+
def test_use_autowidth
|
22
|
+
@package.use_autowidth = false
|
23
|
+
assert(@package.workbook.use_autowidth == false)
|
11
24
|
end
|
12
25
|
|
13
26
|
def test_core_accessor
|
@@ -55,10 +68,6 @@ class TestPackage < Test::Unit::TestCase
|
|
55
68
|
|
56
69
|
def test_parts
|
57
70
|
p = @package.send(:parts)
|
58
|
-
p.each do |part|
|
59
|
-
#all parts must have :doc, :entry, :schema
|
60
|
-
assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?)
|
61
|
-
end
|
62
71
|
#all parts have an entry
|
63
72
|
assert_equal(p.select{ |part| part[:entry] =~ /_rels\/\.rels/ }.size, 1, "rels missing")
|
64
73
|
assert_equal(p.select{ |part| part[:entry] =~ /docProps\/core\.xml/ }.size, 1, "core missing")
|
@@ -72,9 +81,11 @@ class TestPackage < Test::Unit::TestCase
|
|
72
81
|
assert_equal(p.select{ |part| part[:entry] =~ /xl\/charts\/chart\d\.xml/ }.size, @package.workbook.charts.size, "one or more charts missing")
|
73
82
|
assert_equal(p.select{ |part| part[:entry] =~ /xl\/worksheets\/sheet\d\.xml/ }.size, @package.workbook.worksheets.size, "one or more sheet missing")
|
74
83
|
assert_equal(p.select{ |part| part[:entry] =~ /xl\/worksheets\/_rels\/sheet\d\.xml\.rels/ }.size, @package.workbook.worksheets.size, "one or more sheet rels missing")
|
84
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/comments\d\.xml/ }.size, @package.workbook.worksheets.size, "one or more sheet rels missing")
|
85
|
+
|
75
86
|
|
76
87
|
#no mystery parts
|
77
|
-
assert_equal(p.size,
|
88
|
+
assert_equal(p.size, 15)
|
78
89
|
|
79
90
|
end
|
80
91
|
|
data/test/util/tc_validators.rb
CHANGED
@@ -70,6 +70,35 @@ class TestValidators < Test::Unit::TestCase
|
|
70
70
|
assert_raise(ArgumentError) { Axlsx.validate_relationship_type "http://some.url" }
|
71
71
|
assert_raise(ArgumentError) { Axlsx.validate_relationship_type false }
|
72
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
|
+
#page_scale
|
87
|
+
assert_nothing_raised { Axlsx.validate_page_scale 10 }
|
88
|
+
assert_nothing_raised { Axlsx.validate_page_scale 100 }
|
89
|
+
assert_nothing_raised { Axlsx.validate_page_scale 400 }
|
90
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_scale 9 }
|
91
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_scale 10.0 }
|
92
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_scale 400.1 }
|
93
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_scale "99" }
|
94
|
+
|
95
|
+
#page_orientation
|
96
|
+
assert_nothing_raised { Axlsx.validate_page_orientation :default }
|
97
|
+
assert_nothing_raised { Axlsx.validate_page_orientation :landscape }
|
98
|
+
assert_nothing_raised { Axlsx.validate_page_orientation :portrait }
|
99
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_orientation nil }
|
100
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_orientation 1 }
|
101
|
+
assert_raise(ArgumentError) { Axlsx.validate_page_orientation "landscape" }
|
73
102
|
end
|
74
103
|
end
|
75
104
|
|
@@ -244,6 +244,23 @@ class TestCell < Test::Unit::TestCase
|
|
244
244
|
c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
|
245
245
|
assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
|
246
246
|
end
|
247
|
+
|
248
|
+
def test_to_xml_string_nil
|
249
|
+
@c.value = nil
|
250
|
+
c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
|
251
|
+
assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_to_xml_string_formula
|
255
|
+
p = Axlsx::Package.new
|
256
|
+
ws = p.workbook.add_worksheet do |ws|
|
257
|
+
ws.add_row ["=IF(2+2=4,4,5)"]
|
258
|
+
end
|
259
|
+
doc = Nokogiri::XML(ws.to_xml_string)
|
260
|
+
assert("//f[text()=['IF(2+2=4,4,5)']")
|
261
|
+
|
262
|
+
end
|
263
|
+
|
247
264
|
def test_to_xml
|
248
265
|
# TODO This could use some much more stringent testing related to the xml content generated!
|
249
266
|
row = @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)"]
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestComment < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
p = Axlsx::Package.new
|
6
|
+
wb = p.workbook
|
7
|
+
@ws = wb.add_worksheet
|
8
|
+
@c1 = @ws.add_comment :ref => 'A1', :text => 'penut machine', :author => 'crank'
|
9
|
+
@c2 = @ws.add_comment :ref => 'C3', :text => 'rust bucket', :author => 'PO'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_initailize
|
13
|
+
assert_raise(ArgumentError) { Axlsx::Comment.new }
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_author
|
17
|
+
assert(@c1.author == 'crank')
|
18
|
+
assert(@c2.author == 'PO')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_text
|
22
|
+
assert(@c1.text == 'penut machine')
|
23
|
+
assert(@c2.text == 'rust bucket')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_author_index
|
27
|
+
assert_equal(@c1.author_index, 1)
|
28
|
+
assert_equal(@c2.author_index, 0)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_ref
|
32
|
+
assert(@c1.ref == 'A1')
|
33
|
+
assert(@c2.ref == 'C3')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_vml_shape
|
37
|
+
assert(@c1.vml_shape.is_a?(Axlsx::VmlShape))
|
38
|
+
assert(@c1.vml_shape.column == Axlsx::name_to_indices(@c1.ref)[0])
|
39
|
+
assert(@c1.vml_shape.row == Axlsx::name_to_indices(@c1.ref)[1])
|
40
|
+
assert(@c1.vml_shape.row == Axlsx::name_to_indices(@c1.ref)[1])
|
41
|
+
assert(@c1.vml_shape.left_column == Axlsx::name_to_indices(@c1.ref)[1]+1)
|
42
|
+
assert(@c1.vml_shape.top_row == Axlsx::name_to_indices(@c1.ref)[1])
|
43
|
+
assert(@c1.vml_shape.right_column == Axlsx::name_to_indices(@c1.ref)[0]+4)
|
44
|
+
assert(@c1.vml_shape.bottom_row == Axlsx::name_to_indices(@c1.ref)[1]+4)
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_xml_string
|
48
|
+
doc = Nokogiri::XML(@c1.to_xml_string)
|
49
|
+
assert_equal(doc.xpath("//comment[@ref='#{@c1.ref}']").size, 1)
|
50
|
+
assert_equal(doc.xpath("//comment[@authorId='#{@c1.author_index.to}']").size, 1)
|
51
|
+
assert_equal(doc.xpath("//t[text()='#{@c1.author}']").size, 1)
|
52
|
+
assert_equal(doc.xpath("//t[text()='#{@c1.text}']").size, 1)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestComments < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
p = Axlsx::Package.new
|
6
|
+
wb = p.workbook
|
7
|
+
@ws = wb.add_worksheet
|
8
|
+
@c1 = @ws.add_comment :ref => 'A1', :text => 'penut machine', :author => 'crank'
|
9
|
+
@c2 = @ws.add_comment :ref => 'C3', :text => 'rust bucket', :author => 'PO'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_initialize
|
13
|
+
assert_raise(ArgumentError) { Axlsx::Comments.new }
|
14
|
+
assert(@ws.comments.vml_drawing.is_a?(Axlsx::VmlDrawing))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_add_comment
|
18
|
+
assert_equal(@ws.comments.size, 2)
|
19
|
+
assert_raise(ArgumentError) { @ws.comments.add_comment() }
|
20
|
+
assert_raise(ArgumentError) { @ws.comments.add_comment(:text => 'Yes We Can', :ref => 'A1') }
|
21
|
+
assert_raise(ArgumentError) { @ws.comments.add_comment(:author => 'bob', :ref => 'A1') }
|
22
|
+
assert_raise(ArgumentError) { @ws.comments.add_comment(:author => 'bob', :text => 'Yes We Can')}
|
23
|
+
assert_nothing_raised { @ws.comments.add_comment(:author => 'bob', :text => 'Yes We Can', :ref => 'A1') }
|
24
|
+
assert_equal(@ws.comments.size, 3)
|
25
|
+
end
|
26
|
+
def test_authors
|
27
|
+
assert_equal(@ws.comments.authors.size, @ws.comments.size)
|
28
|
+
@ws.add_comment(:text => 'Yes We Can!', :author => :bob, :ref => 'F1')
|
29
|
+
assert_equal(@ws.comments.authors.size, 3)
|
30
|
+
@ws.add_comment(:text => 'Yes We Can!', :author => :bob, :ref => 'F1')
|
31
|
+
assert_equal(@ws.comments.authors.size, 3, 'only unique authors are returned')
|
32
|
+
end
|
33
|
+
def test_pn
|
34
|
+
assert_equal(@ws.comments.pn, Axlsx::COMMENT_PN % (@ws.index+1).to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_index
|
38
|
+
assert_equal(@ws.index, @ws.comments.index)
|
39
|
+
end
|
40
|
+
def test_to_xml_string
|
41
|
+
doc = Nokogiri::XML(@ws.comments.to_xml_string)
|
42
|
+
# puts doc.xpath("comments").to_xml
|
43
|
+
# TODO figure out why these xpath expressions dont work!
|
44
|
+
# assert(doc.xpath("//comments"))
|
45
|
+
# assert_equal(doc.xpath("//xmlns:author").size, @ws.comments.authors.size)
|
46
|
+
# assert_equal(doc.xpath("//comment").size, @ws.comments.size)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|