Excel-Writer-XLSX
view release on metacpan or search on metacpan
t/lib/TestFunctions.pm view on Meta::CPAN
# Comparison of the XML elements in each file.
if ( !_arrays_equal( \@got_xml, \@exp_xml ) ) {
return ( \@got_xml, \@exp_xml,
" _compare_xlsx_files(): $filename" );
}
}
# Files were the same. Return values that will evaluate to a test pass.
return ( ['ok'], ['ok'], ' _compare_xlsx_files()' );
}
###############################################################################
#
# _arrays_equal()
#
# Compare two array refs for equality.
#
sub _arrays_equal {
my $exp = shift;
my $got = shift;
if ( @$exp != @$got ) {
return 0;
}
for my $i ( 0 .. @$exp - 1 ) {
if ( $exp->[$i] ne $got->[$i] ) {
return 0;
}
}
return 1;
}
###############################################################################
#
# _sort_rel_file_data()
#
# Re-order the relationship elements in an array of XLSX XML rel (relationship)
# data. This is necessary for comparison since Excel can produce the elements
# in a semi-random order.
#
sub _sort_rel_file_data {
my @xml_elements = @_;
my $header = shift @xml_elements;
my $tail = pop @xml_elements;
# Sort the relationship elements.
@xml_elements = sort @xml_elements;
return $header, @xml_elements, $tail;
}
###############################################################################
#
# Use Test::Differences::eq_or_diff() where available or else fall back to
# using Test::More::is_deeply().
#
sub _is_deep_diff {
my ( $got, $expected, $caption, ) = @_;
eval {
require Test::Differences;
Test::Differences->import();
};
if ( !$@ ) {
eq_or_diff( $got, $expected, $caption, { context => 1 } );
}
else {
is_deeply( $got, $expected, $caption );
}
}
###############################################################################
#
# Create a new XML writer sub-classed object based on a class name and bind
# the output to the supplied scalar ref for testing. Calls to the objects XML
# writing subs will add the output to the scalar.
#
sub _new_object {
my $got_ref = shift;
my $class = shift;
open my $got_fh, '>', $got_ref or die "Failed to open filehandle: $!";
my $object = $class->new( $got_fh );
return $object;
}
###############################################################################
#
# Create a new Worksheet object and bind the output to the supplied scalar ref.
#
sub _new_worksheet {
my $got_ref = shift;
return _new_object( $got_ref, 'Excel::Writer::XLSX::Worksheet' );
}
###############################################################################
#
# Create a new Style object and bind the output to the supplied scalar ref.
#
sub _new_style {
my $got_ref = shift;
return _new_object( $got_ref, 'Excel::Writer::XLSX::Package::Styles' );
}
###############################################################################
#
# Create a new Workbook object and bind the output to the supplied scalar ref.
# This is slightly different than the previous cases since the constructor
# requires a filename/filehandle.
( run in 4.003 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )