diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-07-18 17:16:39 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-07-18 17:16:39 -0400 |
commit | 1b404926df08ac4bbe6cbd2c7ada14de6cebda63 (patch) | |
tree | 0781c32efbc33403aa7580b170057ad1a2719b0f /t/basic.t | |
parent | b73fe4b205e7a2b521ea3dd84024b21f0f10cd7f (diff) | |
download | spreadsheet-template-1b404926df08ac4bbe6cbd2c7ada14de6cebda63.tar.gz spreadsheet-template-1b404926df08ac4bbe6cbd2c7ada14de6cebda63.zip |
add some tests
Diffstat (limited to 't/basic.t')
-rw-r--r-- | t/basic.t | 375 |
1 files changed, 375 insertions, 0 deletions
diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..d85ff06 --- /dev/null +++ b/t/basic.t @@ -0,0 +1,375 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Spreadsheet::ParseXLSX; +use Spreadsheet::Template; +use Spreadsheet::Template::Generator; + +my $data; + +{ + my $generator = Spreadsheet::Template::Generator->new; + $data = $generator->generate('t/data/Test.xlsx'); + my $expected = do { local $/; local @ARGV = ('t/data/Test.json'); <> }; + is($data, $expected, "got the correct serialization"); +} + +{ + my $template = Spreadsheet::Template->new; + my $excel = $template->render($data, {}); + open my $fh, '<', \$excel; + + my $wb = Spreadsheet::ParseXLSX->new->parse($fh); + 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'); + { local $TODO = "default font heights don't work well"; + 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'); + { local $TODO = "default font heights don't work well"; + 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'); + { local $TODO = "default font heights don't work well"; + 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'); + { local $TODO = "default font heights don't work well"; + 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'); + { local $TODO = "default font heights don't work well"; + 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'); + { local $TODO = "default font heights don't work well"; + 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'); + { local $TODO = "default font heights don't work well"; + 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'); + { local $TODO = "default font heights don't work well"; + 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'); + { local $TODO = "default font heights don't work well"; + 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; |