aboutsummaryrefslogtreecommitdiffstats
path: root/test/excelx/cell
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2019-01-14 01:41:26 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2019-01-14 01:41:26 -0500
commit6aa7e04e06423e7d92ede727489ea346e88f7108 (patch)
tree9bdec92fd17898b662235bc0a491de827990130c /test/excelx/cell
parentc59817e300dbe1aab3120cad603cdb14b14ed78b (diff)
parentdddfa903d2b856146f05ffb4415c31d6127bb5bf (diff)
Update upstream source from tag 'upstream/2.8.0'
Update to upstream version '2.8.0' with Debian dir 569f5866fbcf4e449c6c48dc5d20a3ab54f95252
Diffstat (limited to 'test/excelx/cell')
-rw-r--r--test/excelx/cell/test_attr_reader_default.rb72
-rw-r--r--test/excelx/cell/test_base.rb5
-rw-r--r--test/excelx/cell/test_datetime.rb12
-rw-r--r--test/excelx/cell/test_empty.rb11
-rw-r--r--test/excelx/cell/test_number.rb9
-rw-r--r--test/excelx/cell/test_string.rb20
-rw-r--r--test/excelx/cell/test_time.rb8
7 files changed, 127 insertions, 10 deletions
diff --git a/test/excelx/cell/test_attr_reader_default.rb b/test/excelx/cell/test_attr_reader_default.rb
new file mode 100644
index 0000000..c1ae277
--- /dev/null
+++ b/test/excelx/cell/test_attr_reader_default.rb
@@ -0,0 +1,72 @@
+require "test_helper"
+
+class TestAttrReaderDefault < Minitest::Test
+ def base
+ Roo::Excelx::Cell::Base
+ end
+
+ def boolean
+ Roo::Excelx::Cell::Boolean
+ end
+
+ def class_date
+ Roo::Excelx::Cell::Date
+ end
+
+ def datetime
+ Roo::Excelx::Cell::DateTime
+ end
+
+ def empty
+ Roo::Excelx::Cell::Empty
+ end
+
+ def number
+ Roo::Excelx::Cell::Number
+ end
+
+ def string
+ Roo::Excelx::Cell::String
+ end
+
+ def base_date
+ ::Date.new(1899, 12, 30)
+ end
+
+ def base_timestamp
+ ::Date.new(1899, 12, 30).to_datetime.to_time.to_i
+ end
+
+ def class_time
+ Roo::Excelx::Cell::Time
+ end
+
+ def test_cell_default_values
+ assert_values base.new(nil, nil, [], 1, nil, nil), default_type: :base, :@default_type => nil, style: 1, :@style => nil
+ assert_values boolean.new("1", nil, nil, nil, nil), default_type: :boolean, :@default_type => nil, cell_type: :boolean, :@cell_type => nil
+ assert_values class_date.new("41791", nil, [:numeric_or_formula, "mm-dd-yy"], 6, nil, base_date, nil), default_type: :date, :@default_type => nil
+ assert_values class_time.new("0.521", nil, [:numeric_or_formula, "hh:mm"], 6, nil, base_timestamp, nil), default_type: :time, :@default_type => nil
+ assert_values datetime.new("41791.521", nil, [:numeric_or_formula, "mm-dd-yy hh:mm"], 6, nil, base_timestamp, nil), default_type: :datetime, :@default_type => nil
+ assert_values empty.new(nil), default_type: nil, :@default_type => nil, style: nil, :@style => nil
+ assert_values number.new("42", nil, ["0"], nil, nil, nil), default_type: :float, :@default_type => nil
+ assert_values string.new("1", nil, nil, nil, nil), default_type: :string, :@default_type => nil, cell_type: :string, :@cell_type => nil
+
+ assert_values base.new(nil, nil, [], 2, nil, nil), style: 2, :@style => 2
+ end
+
+ def assert_values(object, value_hash)
+ value_hash.each do |attr_name, expected_value|
+ value = if attr_name.to_s.include?("@")
+ object.instance_variable_defined?(attr_name) ? object.instance_variable_get(attr_name) : nil
+ else
+ object.public_send(attr_name)
+ end
+
+ if expected_value
+ assert_equal expected_value, value
+ else
+ assert_nil value
+ end
+ end
+ end
+end
diff --git a/test/excelx/cell/test_base.rb b/test/excelx/cell/test_base.rb
index 17c83be..e3d0c7c 100644
--- a/test/excelx/cell/test_base.rb
+++ b/test/excelx/cell/test_base.rb
@@ -25,6 +25,11 @@ class TestRooExcelxCellBase < Minitest::Test
refute cell.empty?
end
+ def test_presence
+ cell = base.new(value, nil, [], nil, nil, nil)
+ assert_equal cell, cell.presence
+ end
+
def test_cell_type_is_formula
formula = true
cell = base.new(value, formula, [], nil, nil, nil)
diff --git a/test/excelx/cell/test_datetime.rb b/test/excelx/cell/test_datetime.rb
index 425830b..4ab1e18 100644
--- a/test/excelx/cell/test_datetime.rb
+++ b/test/excelx/cell/test_datetime.rb
@@ -2,12 +2,12 @@ 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)
+ cell = datetime.new('30000.323212', nil, ['mm-dd-yy'], nil, nil, base_timestamp, 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)
+ cell = datetime.new('30000.323212', nil, [], nil, nil, base_timestamp, nil)
assert_equal :datetime, cell.type
end
@@ -19,7 +19,7 @@ class TestRooExcelxCellDateTime < Minitest::Test
['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
+ cell = datetime.new '42029.34375', nil, [format], nil, nil, base_timestamp, nil
assert_equal formatted_value, cell.formatted_value
end
end
@@ -30,7 +30,7 @@ class TestRooExcelxCellDateTime < Minitest::Test
['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
+ cell = datetime.new '42029.34375', nil, [format], nil, nil, base_timestamp, nil
assert_equal formatted_value, cell.formatted_value
end
end
@@ -39,7 +39,7 @@ class TestRooExcelxCellDateTime < Minitest::Test
Roo::Excelx::Cell::DateTime
end
- def base_date
- Date.new(1899, 12, 30)
+ def base_timestamp
+ DateTime.new(1899, 12, 30).to_time.to_i
end
end
diff --git a/test/excelx/cell/test_empty.rb b/test/excelx/cell/test_empty.rb
index 8263714..e502a1d 100644
--- a/test/excelx/cell/test_empty.rb
+++ b/test/excelx/cell/test_empty.rb
@@ -4,4 +4,15 @@ class TestRooExcelxCellEmpty < Minitest::Test
def empty
Roo::Excelx::Cell::Empty
end
+
+ def test_empty?
+ cell = empty.new(nil)
+ assert_same true, cell.empty?
+ end
+
+ def test_nil_presence
+ cell = empty.new(nil)
+ assert_nil cell.presence
+ end
+
end
diff --git a/test/excelx/cell/test_number.rb b/test/excelx/cell/test_number.rb
index 45db819..5c8d726 100644
--- a/test/excelx/cell/test_number.rb
+++ b/test/excelx/cell/test_number.rb
@@ -25,6 +25,11 @@ class TestRooExcelxCellNumber < Minitest::Test
assert_kind_of(Float, cell.value)
end
+ def test_very_simple_scientific_notation
+ cell = Roo::Excelx::Cell::Number.new '1e6', 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)
@@ -53,8 +58,12 @@ class TestRooExcelxCellNumber < Minitest::Test
def test_formats
[
['General', '1042'],
+ ['GENERAL', '1042'],
['0', '1042'],
+ ['000000', '001042'],
['0.00', '1042.00'],
+ ['0.0000', '1042.0000'],
+ ['0.000000000', '1042.000000000'],
['#,##0', '1,042'],
['#,##0.00', '1,042.00'],
['0%', '104200%'],
diff --git a/test/excelx/cell/test_string.rb b/test/excelx/cell/test_string.rb
index f1c848f..b7ecaa7 100644
--- a/test/excelx/cell/test_string.rb
+++ b/test/excelx/cell/test_string.rb
@@ -25,4 +25,24 @@ class TestRooExcelxCellString < Minitest::Test
cell = string.new '0', nil, nil, nil, nil
assert_equal '0', cell.value
end
+
+ def test_not_empty?
+ cell = string.new '1', nil, nil, nil, nil
+ assert_equal false, cell.empty?
+ end
+
+ def test_empty?
+ cell = string.new '', nil, nil, nil, nil
+ assert_equal true, cell.empty?
+ end
+
+ def test_presence
+ cell = string.new '1', nil, nil, nil, nil
+ assert_equal cell, cell.presence
+ end
+
+ def test_nil_presence
+ cell = string.new '', nil, nil, nil, nil
+ assert_nil cell.presence
+ end
end
diff --git a/test/excelx/cell/test_time.rb b/test/excelx/cell/test_time.rb
index 7619b3a..25d15f9 100644
--- a/test/excelx/cell/test_time.rb
+++ b/test/excelx/cell/test_time.rb
@@ -5,8 +5,8 @@ class TestRooExcelxCellTime < Minitest::Test
Roo::Excelx::Cell::Time
end
- def base_date
- Date.new(1899, 12, 30)
+ def base_timestamp
+ DateTime.new(1899, 12, 30).to_time.to_i
end
def test_formatted_value
@@ -18,13 +18,13 @@ class TestRooExcelxCellTime < Minitest::Test
['[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)
+ cell = roo_time.new(value, nil, [:numeric_or_formula, style_format], 6, nil, base_timestamp, 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)
+ cell = roo_time.new('0.0751', nil, [:numeric_or_formula, 'h:mm'], 6, nil, base_timestamp, nil)
assert_kind_of Integer, cell.value
end
end