diff options
| author | 2017-06-12 03:37:11 -0400 | |
|---|---|---|
| committer | 2017-06-12 03:37:11 -0400 | |
| commit | 8280a21a23d44aa90177e2bc041d0b8dc8556f4b (patch) | |
| tree | dadef7ee085c0e990a5070bd41b6a5b98c97f4fd /test/excelx/cell | |
Import Upstream version 2.7.1upstream/2.7.1
Diffstat (limited to 'test/excelx/cell')
| -rw-r--r-- | test/excelx/cell/test_base.rb | 63 | ||||
| -rw-r--r-- | test/excelx/cell/test_boolean.rb | 36 | ||||
| -rw-r--r-- | test/excelx/cell/test_date.rb | 38 | ||||
| -rw-r--r-- | test/excelx/cell/test_datetime.rb | 45 | ||||
| -rw-r--r-- | test/excelx/cell/test_empty.rb | 7 | ||||
| -rw-r--r-- | test/excelx/cell/test_number.rb | 74 | ||||
| -rw-r--r-- | test/excelx/cell/test_string.rb | 28 | ||||
| -rw-r--r-- | test/excelx/cell/test_time.rb | 30 |
8 files changed, 321 insertions, 0 deletions
diff --git a/test/excelx/cell/test_base.rb b/test/excelx/cell/test_base.rb new file mode 100644 index 0000000..17c83be --- /dev/null +++ b/test/excelx/cell/test_base.rb @@ -0,0 +1,63 @@ +require 'test_helper' + +class TestRooExcelxCellBase < Minitest::Test + def base + Roo::Excelx::Cell::Base + end + + def value + 'Hello World' + end + + def test_cell_type_is_base + cell = base.new(value, nil, [], nil, nil, nil) + assert_equal :base, cell.type + end + + def test_cell_value + cell_value = value + cell = base.new(cell_value, nil, [], nil, nil, nil) + assert_equal cell_value, cell.cell_value + end + + def test_not_empty? + cell = base.new(value, nil, [], nil, nil, nil) + refute cell.empty? + end + + def test_cell_type_is_formula + formula = true + cell = base.new(value, formula, [], nil, nil, nil) + assert_equal :formula, cell.type + end + + def test_formula? + formula = true + cell = base.new(value, formula, [], nil, nil, nil) + assert cell.formula? + end + + def test_cell_type_is_link + link = 'http://example.com' + cell = base.new(value, nil, [], nil, link, nil) + assert_equal :link, cell.type + end + + def test_link? + link = 'http://example.com' + cell = base.new(value, nil, [], nil, link, nil) + assert cell.link? + end + + def test_link_value + link = 'http://example.com' + cell = base.new(value, nil, [], nil, link, nil) + assert_equal value, cell.value + end + + def test_link_value_href + link = 'http://example.com' + cell = base.new(value, nil, [], nil, link, nil) + assert_equal link, cell.value.href + end +end diff --git a/test/excelx/cell/test_boolean.rb b/test/excelx/cell/test_boolean.rb new file mode 100644 index 0000000..5087db2 --- /dev/null +++ b/test/excelx/cell/test_boolean.rb @@ -0,0 +1,36 @@ +require 'test_helper' + +class TestRooExcelxCellNumber < Minitest::Test + def boolean + Roo::Excelx::Cell::Boolean + end + + def test_formatted_value + cell = boolean.new '1', nil, nil, nil, nil + assert_equal 'TRUE', cell.formatted_value + + cell = boolean.new '0', nil, nil, nil, nil + assert_equal 'FALSE', cell.formatted_value + end + + def test_to_s + cell = boolean.new '1', nil, nil, nil, nil + assert_equal 'TRUE', cell.to_s + + cell = boolean.new '0', nil, nil, nil, nil + assert_equal 'FALSE', cell.to_s + end + + def test_cell_value + cell = boolean.new '1', nil, nil, nil, nil + assert_equal '1', cell.cell_value + end + + def test_value + cell = boolean.new '1', nil, nil, nil, nil + assert_equal true, cell.value + + cell = boolean.new '0', nil, nil, nil, nil + assert_equal false, cell.value + end +end diff --git a/test/excelx/cell/test_date.rb b/test/excelx/cell/test_date.rb new file mode 100644 index 0000000..7bd046b --- /dev/null +++ b/test/excelx/cell/test_date.rb @@ -0,0 +1,38 @@ +require 'test_helper' + +class TestRooExcelxCellDate < Minitest::Test + def date_cell + Roo::Excelx::Cell::Date + end + + def base_date + ::Date.new(1899, 12, 30) + end + + def base_date_1904 + ::Date.new(1904, 01, 01) + end + + def test_handles_1904_base_date + cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date_1904, nil) + assert_equal ::Date.new(2018, 06, 02), cell.value + end + + def test_formatted_value + cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil) + assert_equal '06-01-14', cell.formatted_value + + cell = date_cell.new('41791', nil, [:numeric_or_formula, 'yyyy-mm-dd'], 6, nil, base_date, nil) + assert_equal '2014-06-01', cell.formatted_value + end + + def test_value_is_date + cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil) + assert_kind_of ::Date, cell.value + end + + def test_value + cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil) + assert_equal ::Date.new(2014, 06, 01), cell.value + end +end diff --git a/test/excelx/cell/test_datetime.rb b/test/excelx/cell/test_datetime.rb new file mode 100644 index 0000000..425830b --- /dev/null +++ b/test/excelx/cell/test_datetime.rb @@ -0,0 +1,45 @@ +require 'test_helper' + +class TestRooExcelxCellDateTime < Minitest::Test + def test_cell_value_is_datetime + cell = datetime.new('30000.323212', nil, ['mm-dd-yy'], nil, nil, base_date, nil) + assert_kind_of ::DateTime, cell.value + end + + def test_cell_type_is_datetime + cell = datetime.new('30000.323212', nil, [], nil, nil, base_date, nil) + assert_equal :datetime, cell.type + end + + def test_standard_formatted_value + [ + ['mm-dd-yy', '01-25-15'], + ['d-mmm-yy', '25-JAN-15'], + ['d-mmm ', '25-JAN'], + ['mmm-yy', 'JAN-15'], + ['m/d/yy h:mm', '1/25/15 8:15'] + ].each do |format, formatted_value| + cell = datetime.new '42029.34375', nil, [format], nil, nil, base_date, nil + assert_equal formatted_value, cell.formatted_value + end + end + + def test_custom_formatted_value + [ + ['yyyy/mm/dd hh:mm:ss', '2015/01/25 08:15:00'], + ['h:mm:ss000 mm/yy', '8:15:00000 01/15'], + ['mmm yyy', '2015-01-25 08:15:00'] + ].each do |format, formatted_value| + cell = datetime.new '42029.34375', nil, [format], nil, nil, base_date, nil + assert_equal formatted_value, cell.formatted_value + end + end + + def datetime + Roo::Excelx::Cell::DateTime + end + + def base_date + Date.new(1899, 12, 30) + end +end diff --git a/test/excelx/cell/test_empty.rb b/test/excelx/cell/test_empty.rb new file mode 100644 index 0000000..8263714 --- /dev/null +++ b/test/excelx/cell/test_empty.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TestRooExcelxCellEmpty < Minitest::Test + def empty + Roo::Excelx::Cell::Empty + end +end diff --git a/test/excelx/cell/test_number.rb b/test/excelx/cell/test_number.rb new file mode 100644 index 0000000..45db819 --- /dev/null +++ b/test/excelx/cell/test_number.rb @@ -0,0 +1,74 @@ +require 'test_helper' + +class TestRooExcelxCellNumber < Minitest::Test + def number + Roo::Excelx::Cell::Number + end + + def test_float + cell = Roo::Excelx::Cell::Number.new '42.1', nil, ['General'], nil, nil, nil + assert_kind_of(Float, cell.value) + end + + def test_integer + cell = Roo::Excelx::Cell::Number.new '42', nil, ['0'], nil, nil, nil + assert_kind_of(Integer, cell.value) + end + + def test_scientific_notation + cell = Roo::Excelx::Cell::Number.new '1.2E-3', nil, ['0'], nil, nil, nil + assert_kind_of(Float, cell.value) + end + + def test_simple_scientific_notation + cell = Roo::Excelx::Cell::Number.new '1E-3', nil, ['0'], nil, nil, nil + assert_kind_of(Float, cell.value) + end + + def test_percent + cell = Roo::Excelx::Cell::Number.new '42.1', nil, ['0.00%'], nil, nil, nil + assert_kind_of(Float, cell.value) + end + + def test_formats_with_negative_numbers + [ + ['#,##0 ;(#,##0)', '(1,042)'], + ['#,##0 ;[Red](#,##0)', '[Red](1,042)'], + ['#,##0.00;(#,##0.00)', '(1,042.00)'], + ['#,##0.00;[Red](#,##0.00)', '[Red](1,042.00)'] + ].each do |style_format, result| + cell = Roo::Excelx::Cell::Number.new '-1042', nil, [style_format], nil, nil, nil + assert_equal result, cell.formatted_value, "Style=#{style_format}" + end + end + + def test_numbers_with_cell_errors + Roo::Excelx::ERROR_VALUES.each do |error| + cell = Roo::Excelx::Cell::Number.new error, nil, ['General'], nil, nil, nil + assert_equal error, cell.value + assert_equal error, cell.formatted_value + end + end + + def test_formats + [ + ['General', '1042'], + ['0', '1042'], + ['0.00', '1042.00'], + ['#,##0', '1,042'], + ['#,##0.00', '1,042.00'], + ['0%', '104200%'], + ['0.00%', '104200.00%'], + ['0.00E+00', '1.04E+03'], + ['#,##0 ;(#,##0)', '1,042'], + ['#,##0 ;[Red](#,##0)', '1,042'], + ['#,##0.00;(#,##0.00)', '1,042.00'], + ['#,##0.00;[Red](#,##0.00)', '1,042.00'], + ['##0.0E+0', '1.0E+03'], + ['@', '1042'] + ].each do |style_format, result| + cell = Roo::Excelx::Cell::Number.new '1042', nil, [style_format], nil, nil, nil + assert_equal result, cell.formatted_value, "Style=#{style_format}" + end + end +end diff --git a/test/excelx/cell/test_string.rb b/test/excelx/cell/test_string.rb new file mode 100644 index 0000000..f1c848f --- /dev/null +++ b/test/excelx/cell/test_string.rb @@ -0,0 +1,28 @@ +require 'test_helper' + +class TestRooExcelxCellString < Minitest::Test + def string + Roo::Excelx::Cell::String + end + + + def test_formatted_value + cell = string.new '1', nil, nil, nil, nil + assert_equal '1', cell.formatted_value + end + + def test_to_s + cell = string.new '0', nil, nil, nil, nil + assert_equal '0', cell.to_s + end + + def test_cell_value + cell = string.new '1', nil, nil, nil, nil + assert_equal '1', cell.cell_value + end + + def test_value + cell = string.new '0', nil, nil, nil, nil + assert_equal '0', cell.value + end +end diff --git a/test/excelx/cell/test_time.rb b/test/excelx/cell/test_time.rb new file mode 100644 index 0000000..7619b3a --- /dev/null +++ b/test/excelx/cell/test_time.rb @@ -0,0 +1,30 @@ +require 'test_helper' + +class TestRooExcelxCellTime < Minitest::Test + def roo_time + Roo::Excelx::Cell::Time + end + + def base_date + Date.new(1899, 12, 30) + end + + def test_formatted_value + value = '0.0751' # 6488.64 seconds, or 1:48:08.64 + [ + ['h:mm', '1:48'], + ['h:mm:ss', '1:48:09'], + ['mm:ss', '48:09'], + ['[h]:mm:ss', '[1]:48:09'], + ['mmss.0', '4809.0'] # Cell::Time always get rounded to the nearest second. + ].each do |style_format, result| + cell = roo_time.new(value, nil, [:numeric_or_formula, style_format], 6, nil, base_date, nil) + assert_equal result, cell.formatted_value, "Style=#{style_format} is not properly formatted" + end + end + + def test_value + cell = roo_time.new('0.0751', nil, [:numeric_or_formula, 'h:mm'], 6, nil, base_date, nil) + assert_kind_of Integer, cell.value + end +end |
