File: 30_types.t

package info (click to toggle)
libtext-csv-perl 1.99-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 676 kB
  • sloc: perl: 7,510; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,681 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl

use strict;
$^W = 1;

use Test::More tests => 25;

BEGIN {
    $ENV{PERL_TEXT_CSV} = 0;
    use_ok "Text::CSV", ();
    plan skip_all => "Cannot load Text::CSV" if $@;
    }

$| = 1;

my $csv = Text::CSV->new ({
    types => [
	Text::CSV::IV (),
	Text::CSV::PV (),
	Text::CSV::NV (),
	],
    });

ok ($csv,					"CSV_XS->new ()");

is (@{$csv->{types}}, 3,			"->{types} as hash");
is ($csv->{types}[0], Text::CSV::IV (),	"type IV");
is ($csv->{types}[1], Text::CSV::PV (),	"type PV");
is ($csv->{types}[2], Text::CSV::NV (),	"type NV");

is (ref ($csv->types), "ARRAY",			"->types () as method");
is ($csv->types ()->[0], Text::CSV::IV (),	"type IV");
is ($csv->types ()->[1], Text::CSV::PV (),	"type PV");
is ($csv->types ()->[2], Text::CSV::NV (),	"type NV");

is (length $csv->{_types}, 3,			"->{_types}");
my $inp = join "", map { chr $_ }
    Text::CSV::IV (), Text::CSV::PV (), Text::CSV::NV ();
# should be "\001\000\002"
is ($csv->{_types}, $inp,			"IV PV NV");

ok ($csv->parse ("2.55,CSFDATVM01,3.75"),	"parse ()");
my @fields = $csv->fields ();
is ($fields[0], "2",				"Field 1");
is ($fields[1], "CSFDATVM01",			"Field 2");
is ($fields[2], "3.75",				"Field 3");

ok ($csv->combine ("", "", "1.00"),		"combine ()");
is ($csv->string, ',,1.00',			"string");

my $warning;
$SIG{__WARN__} = sub { $warning = shift };

ok ($csv->parse ($csv->string ()),		"parse (combine ())");
like ($warning, qr/numeric/,			"numeric warning");

@fields = $csv->fields ();
is ($fields[0], "0",				"Field 1");
is ($fields[1], "",				"Field 2");
is ($fields[2], "1",				"Field 3");

is ($csv->types (0), undef,			"delete types");
is ($csv->types,     undef,			"types gone");