Text-FixedLengthMultiline

 view release on metacpan or  search on metacpan

t/02parse.t  view on Meta::CPAN

my %data;

# Build a new format
# 2 tests
sub new_fmt()
{
    # Set the global variables
    undef $fmt;
    undef %data;
    $fmt = Text::FixedLengthMultiline->new(@_);
    isa_ok($fmt, 'Text::FixedLengthMultiline', 'Line '.(caller)[2]);
    return $fmt;
}

# Parse a line and test the result
# 2 tests
sub test_parse()
{
    my ($line, $expected_data, $expected_result) = @_;
    my $test_name = 'Line ' . ((caller)[2]) . ' parsing result for: '.(defined $line ? "<$line>" : 'undef');
    is($fmt->parse_line($line, \%data), $expected_result, $test_name);
    is_deeply(\%data, $expected_data, $test_name);
}

&new_fmt(format => [ 'col1' => 6 ]);
&test_parse(undef, { }, 0);
&test_parse('', { }, 0);
&test_parse('     ', { }, 0);
&test_parse('abc   ', { col1 => 'abc' }, 0);
&test_parse('def', { col1 => 'abc' }, -1);



( run in 1.846 second using v1.01-cache-2.11-cpan-a3c8064c92c )