File: 07-parse.t

package info (click to toggle)
libtext-recordparser-perl 1.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 364 kB
  • ctags: 34
  • sloc: perl: 2,045; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!perl

#
# tests for alternate parsing
#

use strict;
use File::Spec::Functions;
use FindBin qw( $Bin );
use Readonly;
use Test::More tests => 4;
use Text::RecordParser;

Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' );

{
    my $file = catfile( $TEST_DATA_DIR, 'simpsons.tab' );
    my $p    = Text::RecordParser->new(
        filename        => $file,
        field_separator => "\t",
    );
    $p->bind_header;
    my $row = $p->fetchrow_hashref;
    is( $row->{'Wife'}, 'Marge', 'Wife is Marge' );
}

{
    my $file = catfile( $TEST_DATA_DIR, 'simpsons.alt' );
    my $p = Text::RecordParser->new(
        filename         => $file,
        field_separator  => "\n",
        record_separator => "\n//\n",
    );
    $p->bind_header;
    my $row = $p->fetchrow_hashref;
    is( $row->{'Wife'}, 'Marge', 'Wife is still Marge' );
}

{
    my $file = catfile( $TEST_DATA_DIR, 'pipe.dat' );
    my $p    = Text::RecordParser->new(
        filename         => $file,
        field_separator  => qr/\|/,
    );
    my $row = $p->fetchrow_array;
    is( $row->[0], 'MSH', 'First field is "MSH"' );
    is( $row->[-1], '2.2', 'Last field is "2.2"' );
}