diff options
| author | Ian Clarkson <[email protected]> | 2019-12-16 09:17:41 -0800 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2019-12-17 01:51:55 +0100 |
| commit | 5d3f4a9b0f8c9474459e174cf22aeb8252f444ab (patch) | |
| tree | b911cee956d740a1ab3edb9bb9ce798b60b7acb3 /test | |
| parent | 75cec07c450378a597c8bbae1ca10229b6fb2bf1 (diff) | |
| download | caxlsx-5d3f4a9b0f8c9474459e174cf22aeb8252f444ab.tar.gz caxlsx-5d3f4a9b0f8c9474459e174cf22aeb8252f444ab.zip | |
Check size in bytes as opposed to string size
- `size` returns length in characters, but doesn't factor in multibyte Unicode characters.
By switching to `bytesize`, we check the relevant measure of how many bytes the worksheet name is.
- Fixes https://github.com/randym/axlsx/issues/588
- Copy of PR against original axlsx
(https://github.com/randym/axlsx/pull/589)
Diffstat (limited to 'test')
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index fa8832d8..781f5250 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -29,6 +29,17 @@ class TestWorksheet < Test::Unit::TestCase assert_raises(ArgumentError) { @ws.name = 'foo?bar' } end + def test_exception_if_name_too_long + assert_nothing_raised { @ws.name = 'x' * 31 } + assert_raises(ArgumentError) { @ws.name = 'x' * 32 } + end + + def test_exception_if_name_too_long_because_of_multibyte_characters + three_byte_character = "✔" + assert_nothing_raised { @ws.name = 'x' * 28 + three_byte_character} + assert_raises(ArgumentError) { @ws.name = 'x' * 29 + three_byte_character } + end + def test_page_margins assert(@ws.page_margins.is_a? Axlsx::PageMargins) end |
