summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/worksheet
diff options
context:
space:
mode:
authorWeston Ganger <[email protected]>2022-10-22 22:39:10 -0700
committerWeston Ganger <[email protected]>2022-11-02 19:20:58 -0700
commit168baec8c309960c2598b1dd82f2f6f16b462961 (patch)
treeb030001aa35f0f31bb2516428a481d78769fdf30 /test/workbook/worksheet
parent56fae454a3a4f01c2401321579726d7331407f0d (diff)
downloadcaxlsx-168baec8c309960c2598b1dd82f2f6f16b462961.tar.gz
caxlsx-168baec8c309960c2598b1dd82f2f6f16b462961.zip
Improve BorderCreator args
Diffstat (limited to 'test/workbook/worksheet')
-rw-r--r--test/workbook/worksheet/tc_border_creator.rb54
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb24
2 files changed, 50 insertions, 28 deletions
diff --git a/test/workbook/worksheet/tc_border_creator.rb b/test/workbook/worksheet/tc_border_creator.rb
index c84b1f46..0a72cc84 100644
--- a/test/workbook/worksheet/tc_border_creator.rb
+++ b/test/workbook/worksheet/tc_border_creator.rb
@@ -7,45 +7,43 @@ class TestBorderCreator < Test::Unit::TestCase
@ws = @wb.add_worksheet
end
- def test_defaults
- 3.times do
- @ws.add_row [1,2,3]
- end
+ def test_initialize
+ @ws.add_row [1,2,3]
- bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], {})
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"])
assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
- assert_equal bc.instance_variable_get(:@width), :thin
+ assert_equal bc.instance_variable_get(:@style), :thin
assert_equal bc.instance_variable_get(:@color), "000000"
- bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], ["top"])
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [:top], style: :thick, color: "ffffff")
assert_equal bc.instance_variable_get(:@edges), [:top]
- assert_equal bc.instance_variable_get(:@width), :thin
- assert_equal bc.instance_variable_get(:@color), "000000"
+ assert_equal bc.instance_variable_get(:@style), :thick
+ assert_equal bc.instance_variable_get(:@color), "ffffff"
+ end
+
+ def test_initialize_edges
+ @ws.add_row [1,2,3]
- bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], :all)
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: nil)
+ assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
+
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: :all)
assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
- assert_equal bc.instance_variable_get(:@width), :thin
- assert_equal bc.instance_variable_get(:@color), "000000"
- bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], [:foo])
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [])
assert_equal bc.instance_variable_get(:@edges), []
- assert_equal bc.instance_variable_get(:@width), :thin
- assert_equal bc.instance_variable_get(:@color), "000000"
- bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], {edges: ["top"], style: :thick, color: "ffffff"})
- assert_equal bc.instance_variable_get(:@edges), [:top]
- assert_equal bc.instance_variable_get(:@width), :thick
- assert_equal bc.instance_variable_get(:@color), "ffffff"
+ assert_raises(ArgumentError) do
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [:foo])
+ end
- bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], nil)
- assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
- assert_equal bc.instance_variable_get(:@width), :thin
- assert_equal bc.instance_variable_get(:@color), "000000"
+ assert_raises(ArgumentError) do
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: :foo)
+ end
- bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"])
- assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
- assert_equal bc.instance_variable_get(:@width), :thin
- assert_equal bc.instance_variable_get(:@color), "000000"
+ assert_raises(ArgumentError) do
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [nil])
+ end
end
def test_draw
@@ -53,7 +51,7 @@ class TestBorderCreator < Test::Unit::TestCase
@ws.add_row [1,2,3,4,5]
end
- bc = Axlsx::BorderCreator.new(@ws, @ws["A1:C3"], {edges: ["top", :left], style: :thick, color: "ffffff"})
+ bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:C3"], edges: ["top", :left], style: :thick, color: "ffffff")
bc.draw
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 6dbea530..8e0c5696 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -716,6 +716,30 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal 12 + 2, wb.styles.style_index.keys.max
end
+ def test_add_border_arguments
+ p = Axlsx::Package.new
+ wb = p.workbook
+
+ wb.add_worksheet do |sheet|
+ 20.times.each do
+ sheet.add_row [1,2,3,4,5]
+ end
+
+ sheet.add_border "B2:D5"
+ sheet.add_border ["C3:C4", "D3:D4", "A2"], {color: "FF00000"}
+ sheet.add_border "B10:E10", [:top, :bottom, :left, :right]
+ sheet.add_border "B12:E12", :all
+ sheet.add_border "B14:E14", Axlsx::Border::EDGES
+ sheet.add_border "B16:E16", {edges: :all, style: :thick}
+ sheet.add_border "B18:E18", {edges: [:top], style: :thick, color: "FFFFF00"}
+ end
+
+ wb.apply_styles
+
+ assert_equal true, wb.styles_applied
+ assert_equal 17, wb.styles.style_index.count
+ end
+
def test_duplicate_borders
p = Axlsx::Package.new
wb = p.workbook