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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
use strict;
use warnings;
my $loaded;
BEGIN { $| = 1; print "1..20\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::CSV;
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
#
# Test non-existent package Text::CSV::Base
#
@Text::CSV::Base::ISA = qw(Text::CSV);
#
# empty subclass test
#
my $empty = Text::CSV::Base->new();
if ($empty->version() and $empty->parse('') and $empty->combine('')) {
print "ok 2\n";
} else {
print "not ok 2\n";
}
my $csv = Text::CSV::Base->new( { always_quote => 1 } );
if (! $csv->combine()) { # fail - missing argument
print "ok 3\n";
} else {
print "not ok 3\n";
}
if (! $csv->combine('abc', "def\n", 'ghi')) { # fail - bad character
print "ok 4\n";
} else {
print "not ok 4\n";
}
if ($csv->combine('') && ($csv->string eq q(""))) { # succeed
print "ok 5\n";
} else {
print "not ok 5\n";
}
if ($csv->combine('', '') && ($csv->string eq q("",""))) { # succeed
print "ok 6\n";
} else {
print "not ok 6\n";
}
if ($csv->combine('', 'I said, "Hi!"', '') &&
($csv->string eq q("","I said, ""Hi!""",""))) { # succeed
print "ok 7\n";
} else {
print "not ok 7\n";
}
if ($csv->combine('"', 'abc') && ($csv->string eq q("""","abc"))) { # succeed
print "ok 8\n";
} else {
print "not ok 8\n";
}
if ($csv->combine('abc', '"') && ($csv->string eq q("abc",""""))) { # succeed
print "ok 9\n";
} else {
print "not ok 9\n";
}
if ($csv->combine('abc', 'def', 'ghi') &&
($csv->string eq q("abc","def","ghi"))) { # succeed
print "ok 10\n";
} else {
print "not ok 10\n";
}
if ($csv->combine("abc\tdef", 'ghi') &&
($csv->string eq qq("abc\tdef","ghi"))) { # succeed
print "ok 11\n";
} else {
print "not ok 11\n";
}
if (! $csv->parse()) { # fail - missing argument
print "ok 12\n";
} else {
print "not ok 12\n";
}
if (! $csv->parse('"abc')) { # fail - missing closing double-quote
print "ok 13\n";
} else {
print "not ok 13\n";
}
if (! $csv->parse('ab"c')) { # fail - double-quote outside of double-quotes
print "ok 14\n";
} else {
print "not ok 14\n";
}
if (! $csv->parse('"ab"c"')) { # fail - bad character sequence
print "ok 15\n";
} else {
print "not ok 15\n";
}
if (! $csv->parse(qq("abc\nc"))) { # fail - bad character
print "ok 16\n";
} else {
print "not ok 16\n";
}
if (! $csv->status()) { # fail - test #16 should have failed
print "ok 17\n";
} else {
print "not ok 17\n";
}
if ($csv->parse(q(",")) and ($csv->fields())[0] eq ',') { # success
print "ok 18\n";
} else {
print "not ok 18\n";
}
if ($csv->parse(qq("","I said,\t""Hi!""","")) and
($csv->fields())[0] eq '' and
($csv->fields())[1] eq qq(I said,\t"Hi!") and
($csv->fields())[2] eq '') { # success
print "ok 19\n";
} else {
print "not ok 19\n";
}
if ($csv->status()) { # success - test #19 should have succeeded
print "ok 20\n";
} else {
print "not ok 20\n";
}
|