diff options
| author | Randy Morgan <[email protected]> | 2011-12-05 09:41:00 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-12-05 09:41:00 +0900 |
| commit | 73be92c5cd53ddbaaebf5768b481c3278736698b (patch) | |
| tree | c03e5c39db2e9dc453cbddcca823ad8c9b13be48 /test/workbook | |
| parent | b660d79bb3aa31d9f3e869d44b5851f02caa865b (diff) | |
| download | caxlsx-73be92c5cd53ddbaaebf5768b481c3278736698b.tar.gz caxlsx-73be92c5cd53ddbaaebf5768b481c3278736698b.zip | |
specs for new functionality
Diffstat (limited to 'test/workbook')
| -rw-r--r-- | test/workbook/tc_workbook.rb | 7 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 96 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 17 |
3 files changed, 120 insertions, 0 deletions
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb index 753e97e7..7f5139cb 100644 --- a/test/workbook/tc_workbook.rb +++ b/test/workbook/tc_workbook.rb @@ -42,6 +42,13 @@ class TestWorkbook < Test::Unit::TestCase end assert(errors.empty?, "error free validation") end + def test_range_requires__valid_sheet + ws = @wb.add_worksheet :name=>'fish' + ws.add_row [1,2,3] + ws.add_row [4,5,6] + assert_raise(ArgumentError, "no sheet name part") { @wb["A1:C2"]} + assert_equal @wb['fish!A1:C2'].size, 6 + end def test_to_xml_adds_worksheet_when_worksheets_is_empty assert(@wb.worksheets.empty?) diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 58c76bbc..d4b1d29e 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -27,6 +27,10 @@ class TestCell < Test::Unit::TestCase assert_equal(@c.index, @row.cells.index(@c)) end + def test_index + assert_equal(@c.pos, [@c.index, @c.row.index]) + end + def test_r assert_equal(@c.r, "A1", "calculate cell reference") end @@ -80,4 +84,96 @@ class TestCell < Test::Unit::TestCase assert_equal(@c.send(:cast_value, nil), "") end + + def test_color + assert_raise(ArgumentError) { @c.color = -1.1 } + assert_nothing_raised { @c.color = "FF00FF00" } + assert_equal(@c.color.rgb, "FF00FF00") + end + + def test_scheme + assert_raise(ArgumentError) { @c.scheme = -1.1 } + assert_nothing_raised { @c.scheme = :major } + assert_equal(@c.scheme, :major) + end + + def test_vertAlign + assert_raise(ArgumentError) { @c.vertAlign = -1.1 } + assert_nothing_raised { @c.vertAlign = :baseline } + assert_equal(@c.vertAlign, :baseline) + end + + def test_sz + assert_raise(ArgumentError) { @c.sz = -1.1 } + assert_nothing_raised { @c.sz = 12 } + assert_equal(@c.sz, 12) + end + + def test_extend + assert_raise(ArgumentError) { @c.extend = -1.1 } + assert_nothing_raised { @c.extend = false } + assert_equal(@c.extend, false) + end + + def test_condense + assert_raise(ArgumentError) { @c.condense = -1.1 } + assert_nothing_raised { @c.condense = false } + assert_equal(@c.condense, false) + end + + def test_shadow + assert_raise(ArgumentError) { @c.shadow = -1.1 } + assert_nothing_raised { @c.shadow = false } + assert_equal(@c.shadow, false) + end + + def test_outline + assert_raise(ArgumentError) { @c.outline = -1.1 } + assert_nothing_raised { @c.outline = false } + assert_equal(@c.outline, false) + end + + def test_strike + assert_raise(ArgumentError) { @c.strike = -1.1 } + assert_nothing_raised { @c.strike = false } + assert_equal(@c.strike, false) + end + + def test_u + assert_raise(ArgumentError) { @c.u = -1.1 } + assert_nothing_raised { @c.u = false } + assert_equal(@c.u, false) + end + + def test_i + assert_raise(ArgumentError) { @c.i = -1.1 } + assert_nothing_raised { @c.i = false } + assert_equal(@c.i, false) + end + + def test_rFont + assert_raise(ArgumentError) { @c.font_name = -1.1 } + assert_nothing_raised { @c.font_name = "Arial" } + assert_equal(@c.font_name, "Arial") + end + + def test_charset + assert_raise(ArgumentError) { @c.charset = -1.1 } + assert_nothing_raised { @c.charset = 1 } + assert_equal(@c.charset, 1) + end + + def test_family + assert_raise(ArgumentError) { @c.family = -1.1 } + assert_nothing_raised { @c.family = "Who knows!" } + assert_equal(@c.family, "Who knows!") + end + + def test_b + assert_raise(ArgumentError) { @c.b = -1.1 } + assert_nothing_raised { @c.b = false } + assert_equal(@c.b, false) + end + + end diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index a2c036a1..c86d410a 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -28,6 +28,15 @@ class TestWorksheet < Test::Unit::TestCase def test_index assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws)) end + + def test_referencing + @ws.add_row [1, 2, 3] + @ws.add_row [4, 5, 6] + range = @ws["A1:C2"] + assert_equal(range.size, 6) + assert_equal(range.first, @ws.rows.first.cells.first) + assert_equal(range.last, @ws.rows.last.cells.last) + end def test_add_row assert(@ws.rows.empty?, "sheet has no rows by default") @@ -103,12 +112,20 @@ class TestWorksheet < Test::Unit::TestCase end + def test_name_unique + assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> @ws) } + end + def test_update_auto_with_data small = @ws.workbook.styles.add_style(:sz=>2) big = @ws.workbook.styles.add_style(:sz=>10) + @ws.add_row ["chasing windmills", "penut"], :style=>small assert(@ws.auto_fit_data.size == 2, "a data item for each column") + assert_equal(@ws.auto_fit_data[0], {:sz=>2,:longest=>"chasing windmills"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") + + @ws.add_row ["mule"], :style=>big assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") end |
