added new test
[DataExtract-FixedWidth.git] / t / 02-RusselAdams-Snap.t
bloba9c1319fc76952af6b0bdb9e6597e75dbaffb9e1
1 #!/usr/bin/env perl
2 ## AIX Example provided by Russel Adams
3 ## ..... lspv -p hdisk0
4 ## Column headers explicitly provided
5 use strict;
6 use warnings;
7 use feature ':5.10';
9 use Test::More tests => 13;
10 use File::Spec;
11 use DataExtract::FixedWidth;
13 my $file = File::Spec->catfile( 't', 'data', 'RusselAdams-Snap.txt' );
14 open ( my $fh, $file ) || die "Can not open $file";
16 my $fw;
17 while ( my $line = <$fh> ) {
19 if ( $. == 1 ) {
20 $fw = DataExtract::FixedWidth->new({
21 header_row => $line
22 , cols => [
23 qw/STATE REGION TYPE/
24 , 'PP RANGE'
25 , 'MOUNT POINT'
26 , 'LV NAME'
28 });
29 ok ( $fw->unpack_string eq 'a10a8a14a20a11A*'
30 , 'Testing hard coded prerendered unpack string'
31 . ' Expected a10a8a14a20a11A'
32 . ' got ' . $fw->unpack_string
35 else {
36 my $arrRef = $fw->parse( $line );
37 my $hashRef = $fw->parse_hash( $line );
39 given ( $. ) {
40 when ( 2 ) {
41 ok ( $hashRef->{'PP RANGE'} eq '1-1', "Testing output (->parse_hash)" );
42 ok ( $hashRef->{'REGION'} eq 'outer edge', "Testing output (->parse_hash)" );
43 ok ( $hashRef->{'MOUNT POINT'} eq 'N/A', "Testing output (->parse_hash)" );
45 ok ( $arrRef->[0] eq '1-1', "Testing output (->parse)" );
46 ok ( $arrRef->[2] eq 'outer edge', "Testing output (->parse)" );
47 ok ( $arrRef->[5] eq 'N/A', "Testing output (->parse)" );
49 when ( 8 ) {
50 ok ( $hashRef->{'PP RANGE'} eq '205-217', "Testing output (->parse_hash)" );
51 ok ( $hashRef->{'REGION'} eq 'outer middle', "Testing output (->parse_hash)" );
52 ok ( $hashRef->{'MOUNT POINT'} eq '', "Testing output (->parse_hash)" );
54 ok ( $arrRef->[0] eq '205-217', "Testing output (->parse)" );
55 ok ( $arrRef->[2] eq 'outer middle', "Testing output (->parse)" );
56 ok ( $arrRef->[5] eq '', "Testing output (->parse)" );