finialized changes, added moose prereq because of immutable status
[DataExtract-FixedWidth.git] / t / 07-Heurisitic_ParseHash.t
blob8e66538f210ccfe017083c2e2497b4229f58bd16
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use feature ':5.10';
6 use Test::More tests => 13;
7 use File::Spec;
8 use DataExtract::FixedWidth;
10 my $file = File::Spec->catfile( 't', 'data', 'RusselAdams-Snap.txt' );
11 open ( my $fh, $file ) || die "Can not open $file";
13 my @lines = <$fh>;
14 my $fw = DataExtract::FixedWidth->new({ heuristic => \@lines });
16 ok ( $fw->unpack_string eq 'a10a8a14a20a11A*'
17 , 'Testing hard coded prerendered unpack string got '
18 . $fw->unpack_string
19 . ' expected "a10a8a14a20a11A*"'
22 foreach my $idx ( 0 .. $#lines ) {
23 my $line = $lines[$idx];
25 my $arrRef = $fw->parse( $line );
26 my $hashRef = $fw->parse_hash( $line );
28 given ( $idx + 1 ) {
29 when ( 2 ) {
30 ok ( $hashRef->{'PP RANGE'} eq '1-1', "Testing output (->parse_hash)" );
31 ok ( $hashRef->{'REGION'} eq 'outer edge', "Testing output (->parse_hash) got " . $hashRef->{'REGION'} );
32 ok ( $hashRef->{'MOUNT POINT'} eq 'N/A', "Testing output (->parse_hash) got " . $hashRef->{'MOUNT POINT'} );
34 ok ( $arrRef->[0] eq '1-1', "Testing output (->parse)" );
35 ok ( $arrRef->[2] eq 'outer edge', "Testing output (->parse)" );
36 ok ( $arrRef->[5] eq 'N/A', "Testing output (->parse)" );
38 when ( 8 ) {
39 ok ( $hashRef->{'PP RANGE'} eq '205-217', "Testing output (->parse_hash)" );
40 ok ( $hashRef->{'REGION'} eq 'outer middle', "Testing output (->parse_hash)" );
41 ok ( $hashRef->{'MOUNT POINT'} eq '', "Testing output (->parse_hash)" );
43 ok ( $arrRef->[0] eq '205-217', "Testing output (->parse)" );
44 ok ( $arrRef->[2] eq 'outer middle', "Testing output (->parse)" );
45 ok ( $arrRef->[5] eq '', "Testing output (->parse)" );