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
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 24;
BEGIN {
require_ok "Text::CSV_XS";
plan skip_all => "Cannot load Text::CSV_XS" if $@;
require "./t/util.pl";
}
$| = 1;
my @binField = ("abc\0def\n\rghi", "ab\"ce,\031\"'", "\266");
my $csv = Text::CSV_XS->new ({ binary => 1 });
ok ($csv->combine (@binField), "combine ()");
my $string;
is_binary ($string = $csv->string,
qq("abc"0def\n\rghi","ab""ce,\031""'",\266), "string ()");
ok ($csv->parse ($string), "parse ()");
is ($csv->fields, scalar @binField, "field count");
my @field = $csv->fields ();
for (0 .. $#binField) {
is ($field[$_], $binField[$_], "Field $_");
}
ok (1, "eol \\r\\n");
$csv->eol ("\r\n");
ok ($csv->combine (@binField), "combine ()");
is_binary ($csv->string,
qq("abc"0def\n\rghi","ab""ce,\031""'",\266\r\n), "string ()");
ok (1, "eol \\n");
$csv->eol ("\n");
ok ($csv->combine (@binField), "combine ()");
is_binary ($csv->string,
qq("abc"0def\n\rghi","ab""ce,\031""'",\266\n), "string ()");
ok (1, "eol ,xxxxxxx\\n");
$csv->eol (",xxxxxxx\n");
ok ($csv->combine (@binField), "combine ()");
is_binary ($csv->string,
qq("abc"0def\n\rghi","ab""ce,\031""'",\266,xxxxxxx\n), "string ()");
$csv->eol ("\n");
ok (1, "quote_char undef");
$csv->quote_char (undef);
ok ($csv->combine ("abc","def","ghi"), "combine");
is ($csv->string, "abc,def,ghi\n", "string ()");
# Ken's test
ok (1, "always_quote");
my $csv2 = Text::CSV_XS->new ({ always_quote => 1 });
ok ($csv2, "new ()");
ok ($csv2->combine ("abc","def","ghi"), "combine ()");
is ($csv2->string, '"abc","def","ghi"', "string ()");
|