Fixed a long lasting bug which caused empty rows to be added in the event of trailing...
[DataExtract-FixedWidth.git] / t / 12-Null.t
blob43f077a21a66fab3a5a4f0e1cd5dee8dca9cbb4f
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use feature ':5.10';
6 use DataExtract::FixedWidth;
7 use IO::File;
9 use Test::More tests => 2;
11 use File::Spec;
12 my $file = File::Spec->catfile( 't', 'data', 'NullFirstRow.txt' );
13 my $fh = IO::File->new( $file );
14 my @lines = grep /\w/, $fh->getlines;
16 my $defw = DataExtract::FixedWidth->new({
17 heuristic => \@lines
18 , skip_header_data => 0
19 , null_as_undef => 1
20 });
22 is (
23 $defw->unpack_string
24 , 'a12a12a5a7A*'
25 , 'trailing fields does not exist'
28 my @data;
29 for ( @lines ) {
30 push @data, \@{$defw->parse($_)};
33 my $test_against = [
35 'foobarbaz',
36 'foobarbaz',
37 undef,
38 undef,
39 undef
42 'foobarbaz',
43 'foobarbaz',
44 undef,
45 undef,
46 undef
49 'foobarbaz',
50 'foobarbaz',
51 undef,
52 undef,
53 undef
56 undef,
57 'WWWWWWWWW',
58 'TTTT',
59 'TTTT',
60 'FFFFFFFFF'
63 undef,
64 'TTTTTTTTT',
65 'TTTT',
66 'TTTT',
67 'FFFFFFFFF'
70 undef,
71 'FFFFFFFFF',
72 'TTTT',
73 'TTTT',
74 'FFFFFFFFF'
78 is_deeply ( \@data, $test_against, 'table yield good' );