diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-07-16 18:24:59 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-07-16 18:24:59 -0400 |
commit | 2e265625a09640e6e7cd719ec27dc6dc63d7facc (patch) | |
tree | 758401b76220399c7757462893952392e416c011 | |
parent | 5e4cba47bafba988183e6b1b21cd69202e39dfe2 (diff) | |
download | spreadsheet-parsexlsx-2e265625a09640e6e7cd719ec27dc6dc63d7facc.tar.gz spreadsheet-parsexlsx-2e265625a09640e6e7cd719ec27dc6dc63d7facc.zip |
basic test
-rw-r--r-- | t/basic.t | 344 | ||||
-rw-r--r-- | t/data/Test.xlsx | bin | 0 -> 35554 bytes |
2 files changed, 344 insertions, 0 deletions
diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..f574996 --- /dev/null +++ b/t/basic.t @@ -0,0 +1,344 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Spreadsheet::ParseXLSX; + +my $filename = 't/data/Test.xlsx'; + +for my $file ($filename, do { open my $fh, '<', $filename or die; $fh }) { + my $wb = Spreadsheet::ParseXLSX->new->parse($file); + isa_ok($wb, 'Spreadsheet::ParseExcel::Workbook'); + + is($wb->worksheet_count, 1); + # is($workbook->get_filename, $filename); # XXX + + my $ws = $wb->worksheet(0); + isa_ok($ws, 'Spreadsheet::ParseExcel::Worksheet'); + is($ws->get_name, 'Sheet1'); + is_deeply([$ws->row_range], [0, 5]); + is_deeply([$ws->col_range], [0, 4]); + + { + my $cell = $ws->get_cell(0, 0); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, "Colored Cell"); + is($cell->value, "Colored Cell"); + is($cell->type, 'Text'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [1, '#9BBB59', '#FFFFFF']); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#FFFF00'); + } + + { + my $cell = $ws->get_cell(0, 1); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, "Wide Cell (25.00)"); + is($cell->value, "Wide Cell (25.00)"); + is($cell->type, 'Text'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + { + my $cell = $ws->get_cell(0, 2); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, "Bordered Cell w/ Text Wrap"); + is($cell->value, "Bordered Cell w/ Text Wrap"); + is($cell->type, 'Text'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 2); + ok($format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(1) x 4]); + is_deeply($format->{BdrColor}, [('#000000') x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + { + my $cell = $ws->get_cell(0, 3); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, "Middle Valigned"); + is($cell->value, "Middle Valigned"); + is($cell->type, 'Text'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 1); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + { + my $cell = $ws->get_cell(0, 4); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, "Right Aligned and text wrapped"); + is($cell->value, "Right Aligned and text wrapped"); + is($cell->type, 'Text'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 3); + is($format->{AlignV}, 2); + ok($format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + for my $i (0..4) { + is($ws->get_cell(1, $i), undef); + } + + { + my $cell = $ws->get_cell(2, 0); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, 10); + is($cell->value, 10); + is($cell->type, 'Numeric'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + for my $i (1..4) { + is($ws->get_cell(2, $i), undef); + } + + { + my $cell = $ws->get_cell(3, 0); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, 20); + is($cell->value, 20); + is($cell->type, 'Numeric'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + for my $i (1..2) { + is($ws->get_cell(3, $i), undef); + } + + { + my $cell = $ws->get_cell(3, 3); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, 2.5); + is($cell->value, "\$2.50"); + is($cell->type, 'Numeric'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + { + my $cell = $ws->get_cell(3, 4); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, "<< currency cell"); + is($cell->value, "<< currency cell"); + is($cell->type, 'Text'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 2); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#4BACC6'); + } + + { + my $cell = $ws->get_cell(4, 0); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, 30); + is($cell->value, 30); + is($cell->type, 'Numeric'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + for my $i (1..4) { + is($ws->get_cell(4, $i), undef); + } + + { + my $cell = $ws->get_cell(5, 0); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, 60); + is($cell->value, 60); + is($cell->type, 'Numeric'); + is($cell->{Formula}, 'SUM(A3:A5)'); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 0); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [0, undef, undef]); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#000000'); + } + + { + my $cell = $ws->get_cell(5, 1); + isa_ok($cell, 'Spreadsheet::ParseExcel::Cell'); + is($cell->unformatted, "<< formula cell"); + is($cell->value, "<< formula cell"); + is($cell->type, 'Text'); + is($cell->{Formula}, undef); + + my $format = $cell->get_format; + isa_ok($format, 'Spreadsheet::ParseExcel::Format'); + is($format->{AlignH}, 3); + is($format->{AlignV}, 2); + ok(!$format->{Wrap}); + is_deeply($format->{Fill}, [1, '#EEECE1', '#FFFFFF']); + is_deeply($format->{BdrStyle}, [(0) x 4]); + is_deeply($format->{BdrColor}, [(undef) x 4]); + is_deeply($format->{BdrDiag}, [0, 0, undef]); + + my $font = $format->{Font}; + isa_ok($font, 'Spreadsheet::ParseExcel::Font'); + is($font->{Name}, 'Calibri'); + is($font->{Height}, 12); + is($font->{Color}, '#F79646'); + } + + for my $i (2..4) { + is($ws->get_cell(5, $i), undef); + } +} + +done_testing; diff --git a/t/data/Test.xlsx b/t/data/Test.xlsx Binary files differnew file mode 100644 index 0000000..7c1f8ad --- /dev/null +++ b/t/data/Test.xlsx |