From bff4c5ecfa730c6f5af35577a5cb83562512866e Mon Sep 17 00:00:00 2001 From: Joe Kain Date: Sat, 31 Mar 2012 19:00:18 -0700 Subject: Test 3+ letter column references and indices. --- test/workbook/worksheet/tc_cell.rb | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 4db0c7be..c35e62bc 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -13,6 +13,30 @@ class TestCell < Test::Unit::TestCase @cAA = @ws["AA2"] end + def setup_wide + # The wide row makes the test take a long time. Add it only + # in test_large as adding it in setup make all the tests take + # longer. + # + # For even more, but slower, testing use the 20000 cell row and + # uncomment the ABCD3 element below. + data = (0..1000).map { |index| index } + #data = (0..20000).map { |index| index } + @ws.add_row data + + @wide_test_points = { "A3" => 0, + "Z3" => 25, + "B3" => 1, + "AA3" => 1 * 26 + 0, + "AAA3" => 1 * 26**2 + 1 * 26 + 0, + "AAZ3" => 1 * 26**2 + 1 * 26 + 25, + "ABA3" => 1 * 26**2 + 2 * 26 + 0, + + # For additional testing, uncomment this line and uncomment the 20000 cell row above + #"ABCD3" => 1 * 26**3 + 2 * 26**2 + 3 * 26 + 3 + } + end + def test_initialize assert_equal(@row.cells.last, @c, "the cell was added to the row") assert_equal(@c.type, :float, "type option is applied") @@ -41,6 +65,22 @@ class TestCell < Test::Unit::TestCase assert_equal(@c.r, "A1", "calculate cell reference") end + def test_wide_index + setup_wide + @wide_test_points.each_pair do |ref, index| + c = @ws[ref] + assert_equal(c.index, index, "calculate cell index for cell #{ref}") + end + end + + def test_wide_r + setup_wide + @wide_test_points.each_pair do |ref, index| + c = @ws[ref] + assert_equal(c.r, ref, "calculate cell reference for cell at index #{index}") + end + end + def test_r_abs assert_equal(@c.r_abs,"$A$1", "calculate absolute cell reference") assert_equal(@cAA.r_abs,"$AA$2", "needs to accept multi-digit columns") -- cgit v1.2.3