summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorjohnnyshields <[email protected]>2023-03-31 04:40:41 +0900
committerjohnnyshields <[email protected]>2023-03-31 04:40:41 +0900
commit0746815b75296bcf65d49a66f0dca1427ac65f3e (patch)
treedb99ace871993f5fa1bd80821527ab252a277d53 /test
parentc5ddbe7cd9bb15e8b247e6b5a5e359d02dd5b9fe (diff)
downloadcaxlsx-0746815b75296bcf65d49a66f0dca1427ac65f3e.tar.gz
caxlsx-0746815b75296bcf65d49a66f0dca1427ac65f3e.zip
Add settings for escape_formulas at global, workbook, worksheet, row and cell levels.
Diffstat (limited to 'test')
-rw-r--r--test/workbook/tc_workbook.rb36
-rw-r--r--test/workbook/worksheet/tc_row.rb26
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb58
3 files changed, 107 insertions, 13 deletions
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb
index f8d0b1f7..a9bd339c 100644
--- a/test/workbook/tc_workbook.rb
+++ b/test/workbook/tc_workbook.rb
@@ -162,4 +162,40 @@ class TestWorkbook < Test::Unit::TestCase
wb_xml = Nokogiri::XML(@wb.to_xml_string)
assert_equal sheet.name, wb_xml.xpath('//xmlns:workbook/xmlns:sheets/*[1]/@name').to_s
end
+
+ def test_escape_formulas
+ old = Axlsx::escape_formulas
+
+ Axlsx::escape_formulas = false
+ p = Axlsx::Package.new
+ @wb = p.workbook
+ assert_false @wb.escape_formulas
+ assert_false @wb.add_worksheet.escape_formulas
+ assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
+ assert @wb.add_worksheet(escape_formulas: true).escape_formulas
+
+ Axlsx::escape_formulas = true
+ p = Axlsx::Package.new
+ @wb = p.workbook
+ assert @wb.escape_formulas
+ assert @wb.add_worksheet.escape_formulas
+ assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
+ assert @wb.add_worksheet(escape_formulas: true).escape_formulas
+
+ @wb.escape_formulas = false
+ assert_false @wb.escape_formulas
+ assert_false @wb.add_worksheet.escape_formulas
+ assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
+ assert @wb.add_worksheet(escape_formulas: true).escape_formulas
+
+ @wb.escape_formulas = true
+ p = Axlsx::Package.new
+ @wb = p.workbook
+ assert @wb.escape_formulas
+ assert @wb.add_worksheet.escape_formulas
+ assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
+ assert @wb.add_worksheet(escape_formulas: true).escape_formulas
+
+ Axlsx::escape_formulas = old
+ end
end
diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb
index 38b13806..e29895e2 100644
--- a/test/workbook/worksheet/tc_row.rb
+++ b/test/workbook/worksheet/tc_row.rb
@@ -157,4 +157,30 @@ class TestRow < Test::Unit::TestCase
end
end
+ def test_escape_formulas
+ @ws.escape_formulas = false
+ @row = @ws.add_row
+ assert_false @row.add_cell('').escape_formulas
+ assert_false @row.add_cell('', escape_formulas: false).escape_formulas
+ assert @row.add_cell('', escape_formulas: true).escape_formulas
+
+ @row = Axlsx::Row.new(@ws)
+ assert_false @row.add_cell('').escape_formulas
+
+ @ws.escape_formulas = true
+ @row = @ws.add_row
+
+ assert @row.add_cell('').escape_formulas
+ assert_false @row.add_cell('', escape_formulas: false).escape_formulas
+ assert @row.add_cell('', escape_formulas: true).escape_formulas
+
+ @row.escape_formulas = false
+ assert_equal [false, false, false], @row.cells.map(&:escape_formulas)
+
+ @row.escape_formulas = true
+ assert_equal [true, true, true], @row.cells.map(&:escape_formulas)
+
+ @row.escape_formulas = [false, true, false]
+ assert_equal [false, true, false], @row.cells.map(&:escape_formulas)
+ end
end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 8e0c5696..d535e4f7 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -7,7 +7,6 @@ class TestWorksheet < Test::Unit::TestCase
@ws = @wb.add_worksheet
end
-
def test_pn
assert_equal(@ws.pn, "worksheets/sheet1.xml")
ws = @ws.workbook.add_worksheet
@@ -131,10 +130,8 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(header_footer[key], optioned.header_footer.send(key))
end
assert_equal(optioned.name, 'bob')
-
end
-
# def test_use_gridlines
# assert_raise(ArgumentError) { @ws.show_gridlines = -1.1 }
# assert_nothing_raised { @ws.show_gridlines = false }
@@ -210,7 +207,6 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_row [1, 2, 3, 4]
@ws.add_row [1, 2, 3, 4]
-
assert(@ws.row_breaks.empty?)
assert(@ws.col_breaks.empty?)
@ws.add_page_break(@ws.rows.last.cells[1])
@@ -218,7 +214,6 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(1, @ws.col_breaks.size)
end
-
def test_drawing
assert @ws.drawing == nil
@ws.add_chart(Axlsx::Pie3DChart)
@@ -442,6 +437,7 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal("foo\n\r\nbar", @ws.rows.last.cells.last.value)
assert_not_nil(@ws.to_xml_string.index("foo\n\r\nbar"))
end
+
# Make sure the XML for all optional elements (like pageMargins, autoFilter, ...)
# is generated in correct order.
def test_valid_with_optional_elements
@@ -589,7 +585,6 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(other_ws.index, filter_database[1].local_sheet_id)
end
-
def test_sheet_pr_for_auto_filter
@ws.auto_filter.range = 'A1:D9'
@ws.auto_filter.add_column 0, :filters, :filter_items => [1]
@@ -838,7 +833,7 @@ class TestWorksheet < Test::Unit::TestCase
sheet.add_border 'B2:D4', style: :medium
sheet.add_style 'D2:D4', border: { style: :thin, color: '000000' }
end
-
+
wb.apply_styles
assert_equal 8, wb.styled_cells.count
@@ -884,17 +879,54 @@ class TestWorksheet < Test::Unit::TestCase
wb.apply_styles
assert_equal 1, wb.styles.style_index.size
-
+
assert_equal(
{
- type: :xf,
- name: "Times New Roman",
- sz: 12,
- family: 1,
+ type: :xf,
+ name: "Times New Roman",
+ sz: 12,
+ family: 1,
color: "FFFFFF",
- },
+ },
wb.styles.style_index.values.first
)
end
+ def test_escape_formulas
+ @wb.escape_formulas = false
+ @ws = @wb.add_worksheet
+ assert_false @ws.escape_formulas
+ assert_false @ws.add_row(['']).cells.first.escape_formulas
+ assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas
+ assert @ws.add_row([''], escape_formulas: true).cells.first.escape_formulas
+ assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas)
+
+ @ws = Axlsx::Worksheet.new(@wb)
+ assert_false @ws.escape_formulas
+
+ @wb.escape_formulas = true
+ @ws = @wb.add_worksheet
+ assert @ws.escape_formulas
+ assert @ws.add_row(['']).cells.first.escape_formulas
+ assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas
+ assert @ws.add_row([''], escape_formulas: true).cells.first.escape_formulas
+ assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas)
+
+ @ws = Axlsx::Worksheet.new(@wb)
+ assert @ws.escape_formulas
+
+ @ws.escape_formulas = false
+ assert_false @ws.escape_formulas
+ assert_false @ws.add_row(['']).cells.first.escape_formulas
+ assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas
+ assert @ws.add_row([''], escape_formulas: true).cells.first.escape_formulas
+ assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas)
+
+ @ws.escape_formulas = true
+ assert @ws.escape_formulas
+ assert @ws.add_row(['']).cells.first.escape_formulas
+ assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas
+ assert @ws.add_row([''], escape_formulas: true).cells.first.escape_formulas
+ assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas)
+ end
end