File Coverage

t/file-csv.t
Criterion Covered Total %
statement 40 40 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 47 47 100.0


line stmt bran cond sub pod time code
1 1     1   27377 use strict;
  1         2  
  1         29  
2 1     1   4 use warnings;
  1         1  
  1         18  
3 1     1   9 use v5.12;
  1         3  
  1         26  
4              
5 1     1   304 use Test::More tests => 8;
  1         10679  
  1         5  
6              
7 1     1   642 use File::Temp qw(tempdir);
  1         11827  
  1         46  
8 1     1   170 use Sweet::Dir;
  1         2  
  1         31  
9 1     1   302 use Sweet::File::CSV;
  1         3  
  1         2248  
10              
11 1         120786 my $test_dir = Sweet::Dir->new(path => 't');
12              
13 1         3 my $temp_path = tempdir();
14 1         348 my $temp_dir = Sweet::Dir->new(path => $temp_path)->create;
15              
16 1         45 my $file1 = Sweet::File::CSV->new(
17                 name => 'file1.csv',
18                 dir => $test_dir,
19             );
20              
21 1         21 is $file1->separator, ',', 'separator';
22              
23 1         221 my @file1_rows = ('1,2', '3,4');
24 1         2 my @file1_fields = ('FIELDA', 'FIELDB');
25              
26 1         25 is $file1->header, 'FIELDA,FIELDB', 'header';
27              
28 1         190 my @got_rows = $file1->rows;
29 1         4 is_deeply \@got_rows, \@file1_rows, 'rows';
30              
31 1         375 my @got_fields = $file1->fields;
32 1         4 is_deeply \@got_fields, \@file1_fields, 'fields';
33              
34 1         351 is $file1->field(0), $file1_fields[0], 'field(0)';
35 1         186 is $file1->field(1), $file1_fields[1], 'field(1)';
36              
37 1         154 my @file2_fields = qw(Name Age);
38 1         28 my $file2 = Sweet::File::CSV->new(
39                 name => 'file_that_does_not_exists.csv',
40                 dir => $temp_dir,
41                 fields => \@file2_fields,
42             );
43              
44 1         27 my @got_fields2 = $file2->fields;
45 1         4 is_deeply \@got_fields2, \@file2_fields, 'fields from init_arg';
46 1         354 is $file2->header, join(',', @file2_fields), 'header from fields';
47              
48