File: 12-decoder-idiot-csv.t

package info (click to toggle)
libdata-tablereader-perl 0.021-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: perl: 2,340; makefile: 2; sh: 1
file content (28 lines) | stat: -rw-r--r-- 926 bytes parent folder | download
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
#! /usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Try::Tiny;
use Data::TableReader::Decoder::IdiotCSV;

plan skip_all => 'Need a CSV parser for this test'
	unless try { Data::TableReader::Decoder::IdiotCSV->default_csv_module };

my $input= <<'END';
"First Name","Last Name","Email"
"Joseph "Joe","Smith",""Smith, Joe" <jsmith@example.com>"
END
open my $input_fh, '<', \$input or die;
my $d= new_ok( 'Data::TableReader::Decoder::IdiotCSV',
	[ file_name => '', file_handle => $input_fh, _log => sub {} ],
	'IdiotCSV decoder' );

ok( my $iter= $d->iterator, 'got iterator' );

is( $iter->dataset_idx, 0, 'dataset_idx=0' );
is_deeply( $iter->(), [ 'First Name', 'Last Name', 'Email' ], 'first row' );
is_deeply( $iter->(), [ 'Joseph "Joe', 'Smith', '"Smith, Joe" <jsmith@example.com>' ], 'second row' );
is_deeply( $iter->(), undef, 'no third row' );
is( $iter->dataset_idx, 0, 'dataset_idx=0' );

done_testing;