finialized changes, added moose prereq because of immutable status
[DataExtract-FixedWidth.git] / t / 01-Wikipedia.t
blobc8fc7b131cdecb33cc427bc27c1786f3ebafd5a5
1 #!/usr/bin/env perl
2 ## Example from http://en.wikipedia.org/w/index.php?title=Flat_file_database&oldid=209112999
3 ## Default options with column header name deduction
4 use strict;
5 use warnings;
6 use feature ':5.10';
9 use Test::More tests => 18;
10 use DataExtract::FixedWidth;
11 use File::Spec;
13 my $file = File::Spec->catfile( 't', 'data', 'Wikipedia.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 });
24 else {
25 my $arrRef = $fw->parse( $line );
26 my $hashRef = $fw->parse_hash( $line );
28 given ( $. ) {
29 when ( 2 ) {
30 ok ( $hashRef->{name} eq 'Amy', "Testing output (->parse_hash)" );
31 ok ( $hashRef->{team} eq 'Blues', "Testing output (->parse_hash)" );
32 ok ( $hashRef->{id} eq '1', "Testing output (->parse_hash)" );
34 ok ( $arrRef->[0] eq '1', "Testing output (->parse)" );
35 ok ( $arrRef->[1] eq 'Amy', "Testing output (->parse)" );
36 ok ( $arrRef->[2] eq 'Blues', "Testing output (->parse)" );
38 when ( 6 ) {
39 ok ( $hashRef->{id} eq '5', "Testing output (->parse_hash)" );
40 ok ( $hashRef->{name} eq 'Ethel', "Testing output (->parse_hash)" );
41 ok ( $hashRef->{team} eq 'Reds', "Testing output (->parse_hash)" );
43 ok ( $arrRef->[0] eq '5', "Testing output (->parse)" );
44 ok ( $arrRef->[1] eq 'Ethel', "Testing output (->parse)" );
45 ok ( $arrRef->[2] eq 'Reds', "Testing output (->parse)" );
47 when ( 9 ) {
48 ok ( $hashRef->{id} eq '8', "Testing output (->parse_hash)" );
49 ok ( $hashRef->{name} eq 'Hank', "Testing output (->parse_hash)" );
50 ok ( $hashRef->{team} eq 'Reds', "Testing output (->parse_hash)" );
52 ok ( $arrRef->[0] eq '8', "Testing output (->parse)" );
53 ok ( $arrRef->[1] eq 'Hank', "Testing output (->parse)" );
54 ok ( $arrRef->[2] eq 'Reds', "Testing output (->parse)" );