Skip to content

Commit

Permalink
tests for Issue #181 and the like
Browse files Browse the repository at this point in the history
  • Loading branch information
weshatheleopard committed Mar 8, 2016
1 parent d8b9756 commit 340c70c
Showing 1 changed file with 70 additions and 34 deletions.
104 changes: 70 additions & 34 deletions spec/lib/worksheet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

it 'should raise error if hex color code includes # character' do
expect {
@worksheet.change_row_fill(3,'#FFF000')
@worksheet.change_row_fill(3, '#FFF000')
}.to raise_error(RuntimeError)
end

Expand All @@ -37,7 +37,7 @@

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.change_row_fill(-1,'111111')
@worksheet.change_row_fill(-1, '111111')
}.to raise_error(RuntimeError)
end

Expand All @@ -58,7 +58,7 @@

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.change_row_font_name(-1,'Arial')
@worksheet.change_row_font_name(-1, 'Arial')
}.to raise_error(RuntimeError)
end

Expand Down Expand Up @@ -112,13 +112,13 @@

it 'should raise error if hex color code includes # character' do
expect {
@worksheet.change_row_font_color(3,'#FFF000')
@worksheet.change_row_font_color(3, '#FFF000')
}.to raise_error(RuntimeError)
end

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.change_row_font_color(-1,'0f0f0f')
@worksheet.change_row_font_color(-1, '0f0f0f')
}.to raise_error(RuntimeError)
end

Expand Down Expand Up @@ -241,14 +241,14 @@

describe '.change_row_horizontal_alignment' do
it 'should cause row and cells to horizontally align as specified by the passed in string' do
@worksheet.change_row_horizontal_alignment(0,'center')
@worksheet.change_row_horizontal_alignment(0, 'center')
expect(@worksheet.get_row_alignment(0, true)).to eq('center')
expect(@worksheet[0][5].horizontal_alignment).to eq('center')
end

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.change_row_horizontal_alignment(-1,'center')
@worksheet.change_row_horizontal_alignment(-1, 'center')
}.to raise_error(RuntimeError)
end

Expand All @@ -262,14 +262,14 @@

describe '.change_row_vertical_alignment' do
it 'should cause row and cells to vertically align as specified by the passed in string' do
@worksheet.change_row_vertical_alignment(0,'center')
@worksheet.change_row_vertical_alignment(0, 'center')
expect(@worksheet.get_row_alignment(0, false)).to eq('center')
expect(@worksheet[0][5].vertical_alignment).to eq('center')
end

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.change_row_vertical_alignment(-1,'center')
@worksheet.change_row_vertical_alignment(-1, 'center')
}.to raise_error(RuntimeError)
end

Expand Down Expand Up @@ -376,13 +376,13 @@

it 'should raise error if hex color code includes # character' do
expect {
@worksheet.change_column_font_color(0,'#FFF000')
@worksheet.change_column_font_color(0, '#FFF000')
}.to raise_error(RuntimeError)
end

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.change_column_font_color(-1,'0f0f0f')
@worksheet.change_column_font_color(-1, '0f0f0f')
}.to raise_error(RuntimeError)
end
end
Expand Down Expand Up @@ -465,7 +465,7 @@

it 'should raise error if hex color code includes # character' do
expect {
@worksheet.change_column_fill(3,'#FFF000')
@worksheet.change_column_fill(3, '#FFF000')
}.to raise_error(RuntimeError)
end

Expand All @@ -477,7 +477,7 @@

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.change_column_fill(-1,'111111')
@worksheet.change_column_fill(-1, '111111')
}.to raise_error(RuntimeError)
end
end
Expand All @@ -491,7 +491,7 @@

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.change_column_horizontal_alignment(-1,'center')
@worksheet.change_column_horizontal_alignment(-1, 'center')
}.to raise_error(RuntimeError)
end
end
Expand Down Expand Up @@ -568,40 +568,40 @@

describe '.add_cell' do
it 'should add new cell where specified, even if a cell is already there (default)' do
@worksheet.add_cell(0,0,'TEST')
@worksheet.add_cell(0,0, 'TEST')
expect(@worksheet[0][0].value).not_to eq(@old_cell_value)
expect(@worksheet[0][0].value).to eq('TEST')
end

it 'should add a new cell below nil rows that might exist' do
@worksheet.sheet_data.rows << nil << nil
@worksheet.add_cell(15,0,'TEST')
@worksheet.add_cell(15,0, 'TEST')
expect(@worksheet[15][0].value).to eq('TEST')
end

it 'should add new cell where specified with formula, even if a cell is already there (default)' do
@worksheet.add_cell(0,0,'','SUM(A2:A10)')
@worksheet.add_cell(0,0, '', 'SUM(A2:A10)')
expect(@worksheet[0][0].value).not_to eq(@old_cell_value)
expect(@worksheet[0][0].formula).not_to eq(@old_cell_formula)
expect(@worksheet[0][0].value).to eq('')
expect(@worksheet[0][0].formula.expression).to eq('SUM(A2:A10)')
end

it 'should not overwrite when a cell is present when overwrite is specified to be false' do
@worksheet.add_cell(0,0,'TEST','B2',false)
@worksheet.add_cell(0,0, 'TEST', 'B2',false)
expect(@worksheet[0][0].value).to eq(@old_cell_value)
expect(@worksheet[0][0].formula.expression.to_s).to eq(@old_cell_formula)
end

it 'should still add a new cell when there is no cell to be overwritten' do
@worksheet.add_cell(11,11,'TEST','B2',false)
@worksheet.add_cell(11,11, 'TEST', 'B2',false)
expect(@worksheet[11][11].value).to eq('TEST')
expect(@worksheet[11][11].formula.expression).to eq('B2')
end

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.add_cell(-1,-1,'')
@worksheet.add_cell(-1,-1, '')
}.to raise_error(RuntimeError)
end
end
Expand Down Expand Up @@ -632,6 +632,15 @@
@worksheet.delete_row(-1)
}.to raise_error(RuntimeError)
end

it 'should properly reindex the cells' do
@worksheet.sheet_data.rows.each_with_index { |row, r|
row.cells.each_with_index { |cell, c|
expect(cell.row).to eq(r)
expect(cell.column).to eq(c)
}
}
end
end

describe '.insert_row' do
Expand All @@ -653,13 +662,13 @@
end

it 'should insert a row at index specified, copying styles from row "above"' do
@worksheet.change_row_font_name(0,'Courier')
@worksheet.change_row_font_name(0, 'Courier')
@worksheet.insert_row(1)
expect(@worksheet.get_row_font_name(1)).to eq('Courier')
end

it 'should preserve (rather than fix) formulas that reference cells "pushed down" rows' do
@worksheet.add_cell(5,0,nil,'SUM(A1:A4)')
@worksheet.add_cell(5,0,nil, 'SUM(A1:A4)')
@worksheet.insert_row(0)
expect(@worksheet[6][0].formula.expression).to eq('SUM(A1:A4)')
end
Expand All @@ -675,6 +684,15 @@
@worksheet.insert_row(11)
expect(@worksheet.sheet_data.size).to eq(13)
end

it 'should properly reindex the cells' do
@worksheet.sheet_data.rows.each_with_index { |row, r|
row.cells.each_with_index { |cell, c|
expect(cell.row).to eq(r)
expect(cell.column).to eq(c)
}
}
end
end

describe '.delete_column' do
Expand All @@ -692,7 +710,7 @@
end

it 'should preserve (rather than fix) formulas that reference cells in "pushed left" columns' do
@worksheet.add_cell(0,4,nil,'SUM(A1:D1)')
@worksheet.add_cell(0,4,nil, 'SUM(A1:D1)')
@worksheet.delete_column(0)
expect(@worksheet[0][3].formula.expression).to eq('SUM(A1:D1)')
end
Expand All @@ -709,6 +727,15 @@
@worksheet.delete_column(-1)
}.to raise_error(RuntimeError)
end

it 'should properly reindex the cells' do
@worksheet.sheet_data.rows.each_with_index { |row, r|
row.cells.each_with_index { |cell, c|
expect(cell.row).to eq(r)
expect(cell.column).to eq(c)
}
}
end
end

describe '.insert_column' do
Expand All @@ -720,7 +747,7 @@
end

it 'should insert a column at index specified, copying styles from column to "left"' do
@worksheet.change_column_font_name(0,'Courier')
@worksheet.change_column_font_name(0, 'Courier')
@worksheet.insert_column(1)
expect(@worksheet.get_column_font_name(1)).to eq('Courier')
end
Expand All @@ -732,7 +759,7 @@
end

it 'should preserve (rather than fix) formulas that reference cells in "pushed right" column' do
@worksheet.add_cell(0,5,nil,'SUM(A1:D1)')
@worksheet.add_cell(0,5,nil, 'SUM(A1:D1)')
@worksheet.insert_column(0)
expect(@worksheet[0][6].formula.expression).to eq('SUM(A1:D1)')
end
Expand All @@ -750,11 +777,20 @@
@worksheet.insert_column(-1)
}.to raise_error(RuntimeError)
end

it 'should properly reindex the cells' do
@worksheet.sheet_data.rows.each_with_index { |row, r|
row.cells.each_with_index { |cell, c|
expect(cell.row).to eq(r)
expect(cell.column).to eq(c)
}
}
end
end

describe '.insert_cell' do
it 'should simply add a cell if no shift argument is specified' do
@worksheet.insert_cell(0,0,'test')
@worksheet.insert_cell(0,0, 'test')
expect(@worksheet[0][0].value).to eq('test')
expect(@worksheet[0][1].value).to eq('0:1')
expect(@worksheet[1][0].value).to eq('1:0')
Expand All @@ -775,34 +811,34 @@
end

it 'should shift cells down if :down is specified' do
@worksheet.insert_cell(0,0,'test',nil,:down)
@worksheet.insert_cell(0, 0, 'test', nil, :down)
expect(@worksheet[0][0].value).to eq('test')
expect(@worksheet[0][1].value).to eq('0:1')
expect(@worksheet[1][0].value).to eq('0:0')
end

it 'should cause error if shift argument is specified whcih is not :right or :down' do
expect {
@worksheet.insert_cell(0,0,'test',nil,:up)
@worksheet.insert_cell(0, 0, 'test', nil, :up)
}.to raise_error(RuntimeError)
end

it 'should cause error if a negative argument is passed in' do
expect {
@worksheet.insert_cell(-1,-1)
@worksheet.insert_cell(-1, -1)
}.to raise_error(RuntimeError)
end
end

describe '.delete_cell' do
it 'should make a cell nil if no shift argument specified' do
deleted = @worksheet.delete_cell(0,0)
deleted = @worksheet.delete_cell(0, 0)
expect(@worksheet[0][0]).to be_nil
expect(@old_cell.inspect).to eq(deleted.inspect)
end

it 'should return nil if a cell which is out of range is specified' do
expect(@worksheet.delete_cell(12,12)).to be_nil
expect(@worksheet.delete_cell(12, 12)).to be_nil
end

it 'should cause error if a negative argument is passed in' do
Expand Down Expand Up @@ -852,7 +888,7 @@

describe '.get_row_font_name' do
it 'should correctly reflect font name for row' do
@worksheet.change_row_font_name(0,'Courier')
@worksheet.change_row_font_name(0, 'Courier')
expect(@worksheet.get_row_font_name(0)).to eq('Courier')
end

Expand All @@ -874,7 +910,7 @@

describe '.get_row_font_color' do
it 'should correctly reflect font color for row' do
@worksheet.change_row_font_color(0,'0f0f0f')
@worksheet.change_row_font_color(0, '0f0f0f')
expect(@worksheet.get_row_font_color(0)).to eq('0f0f0f')
end

Expand Down Expand Up @@ -1039,7 +1075,7 @@

describe '.get_column_font_color' do
it 'should correctly reflect font color for column' do
@worksheet.change_column_font_color(0,'0f0f0f')
@worksheet.change_column_font_color(0, '0f0f0f')
expect(@worksheet.get_column_font_color(0)).to eq('0f0f0f')
end

Expand Down

0 comments on commit 340c70c

Please sign in to comment.