fixed manifest with tests
[DataExtract-FixedWidth.git] / t / 03-Nulls.t
blob1de89b6728b7ac43a830b7e174f468b57a5dfac0
1 #!/usr/bin/env perl
2 ## Quick test for null_as_undef
3 use strict;
4 use warnings;
5 use feature ':5.10';
7 use Test::More tests => 12;
8 use File::Spec;
9 use DataExtract::FixedWidth;
11 my $file = File::Spec->catfile( 't', 'data', 'Nulls.txt' );
12 open ( my $fh, $file ) || die "Can not open $file";
14 while ( my $line = <$fh> ) {
15 state $fw;
17 if ( $. == 1 ) {
18 $fw = DataExtract::FixedWidth->new({
19 header_row => $line
20 , null_as_undef => 1
21 });
23 else {
24 my $arrRef = $fw->parse( $line );
25 my $hashRef = $fw->parse_hash( $line );
27 given ( $. ) {
28 when ( 2 ) {
29 ok ( $hashRef->{id} eq 1, "Testing output (->parse_hash)" );
30 ok ( $hashRef->{name} eq 'Amy', "Testing output (->parse_hash)" );
31 ok ( !defined $hashRef->{team}, "Testing output (->parse_hash)" );
33 ok ( $arrRef->[0] eq '1', "Testing output (->parse)" );
34 ok ( $arrRef->[1] eq 'Amy', "Testing output (->parse)" );
35 ok ( !defined $arrRef->[2], "Testing output (->parse)" );
37 when ( 3 ) {
38 ok ( !defined $hashRef->{id}, "Testing output (->parse_hash)" );
39 ok ( $hashRef->{name} eq 'Amy', "Testing output (->parse_hash)" );
40 ok ( $hashRef->{team} eq 'Reds', "Testing output (->parse_hash)" );
42 ok ( !defined $arrRef->[0], "Testing output (->parse)" );
43 ok ( $arrRef->[1] eq 'Amy', "Testing output (->parse)" );
44 ok ( $arrRef->[2] eq 'Reds', "Testing output (->parse)" );