File: 14-trim.t

package info (click to toggle)
libtext-recordparser-perl 1.6.5-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 440 kB
  • sloc: perl: 3,351; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 908 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
#!perl

#
# tests for "trim"
#

use strict;
use File::Spec::Functions;
use FindBin '$Bin';
use Readonly;
use Test::Exception;
use Test::More tests => 4;
use Text::RecordParser;
use Text::RecordParser::Tab;

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

{
    my $file = catfile( $TEST_DATA_DIR, 'trim.csv' );
    my $p    = Text::RecordParser->new( $file );
    my $r1   = $p->fetchrow_hashref;
    is( $r1->{'SerialNumber'}, '1656401  ', 'Serial number OK' ); 

    my $r2   = $p->fetchrow_hashref;
    is( $r2->{'SerialNumber'}, '    ', 'Blank serial number OK' ); 
}

{
    my $file = catfile( $TEST_DATA_DIR, 'trim.csv' );
    my $p    = Text::RecordParser->new( $file );
    $p->trim(1);
    my $r1   = $p->fetchrow_hashref;
    is( $r1->{'SerialNumber'}, '1656401', 'Serial number OK' ); 

    my $r2   = $p->fetchrow_hashref;
    is( $r2->{'SerialNumber'}, '', 'Blank serial number OK' ); 
}