Subject: | is_missing(0) might be broken? |
Hi, I'm looking through Text::CSV's issues, and wondering why one of the following tests fails. Am I missing something? Or, this is a bug in XS/PP? (cf. https://github.com/makamaka/Text-CSV/issues/27 , though the test attached there seems broken in a few ways)
----------------
#!/usr/bin/perl
use strict;
use warnings;
#use Test::More "no_plan";
use Test::More tests => 13;
BEGIN {
use_ok "Text::CSV_XS";
plan skip_all => "Cannot load Text::CSV_XS" if $@;
require "t/util.pl";
}
my $tfn = "_92test.csv"; END { -f $tfn and unlink $tfn }
open FH, ">", $tfn or die "$tfn: $!";
print FH "\n"; # empty line
print FH "1,2\n";
print FH "3\n"; # empty column
close FH;
my $csv = Text::CSV_XS->new({
keep_meta_info => 1,
blank_is_undef => 1,
empty_is_undef => 1,
});
is $csv->is_missing(0), undef, "is_missing() is not defined yet";
open IN, "<", $tfn or die "$tfn: $!";
$csv->column_names(qw/first second/);
{
my $hr = $csv->getline_hr(*IN);
ok $csv->is_missing(0), "empty line: is_missing() should return true"; # <= FAILS
ok $csv->is_missing(1), "empty line: is_missing() should return true";
ok exists $hr->{first} && !defined $hr->{first};
ok exists $hr->{second} && !defined $hr->{second};
}
{
my $hr = $csv->getline_hr(*IN);
ok !$csv->is_missing(0), "not empty: is_missing() should not return true";
ok exists $hr->{first} && defined $hr->{first};
ok exists $hr->{second} && defined $hr->{second};
}
{
my $hr = $csv->getline_hr(*IN);
ok !$csv->is_missing(0), "not empty column: is_missing() should not return true";
ok $csv->is_missing(1), "empty column: is_missing() should return true";
ok exists $hr->{first} && defined $hr->{first};
ok exists $hr->{second} && !defined $hr->{second};
}