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
|
use Test::More tests => 22;
use PGObject::Util::PseudoCSV;
# plain forms
my $simpletuple = '(a,b,",")';
my $simplearray = '{a,b,","}';
# nulls
my $nulltuple = '(a,b,",",NULL)';
my $nullarray = '{a,b,",",NULL}';
# nested tests
my $nestedtuple = '(a,b,",","(1,a)")';
my $nestedarray = '{{a,b},{1,a}}';
my $tuplewitharray = '(a,b,",","{1,a}")';
my $arrayoftuples = '{"(a,b)","(1,a)"}';
# Newline tests
my $newlinetuple = qq|(a,b,",\n")|;
my $newlinearray = qq|{a,b,",\n"}|;
my $valarray;
my $hashref;
# Simple tuple tests to array
ok ($valarray = pseudocsv_parse($simpletuple, 'test'),
'Parse success, simple tuple, legacy format');
is_deeply($valarray, ['a', 'b', ','], 'Parse correct, simple tuple');
ok ($valarray = pseudocsv_parse($simpletuple),
'parse success, current format');
is_deeply($valarray, ['a', 'b', ','], 'Parse correct, simple tuple');
# Simple array parse
ok ($valarray = pseudocsv_parse($simplearray, 'test'),
'Parse success, simple array');
is_deeply($valarray, ['a', 'b', ','], 'Parse correct, simple array');
# Null tuple
ok ($valarray = pseudocsv_parse($nulltuple, 'test'),
'Parse success, simple tuple');
is_deeply($valarray, ['a', 'b', ',', undef], 'Parse correct, simple tuple');
ok($hashref = pcsv2hash($nulltuple, 'a', 'b', 'c', 'd'), 'parsed null tuple to hashref');
is_deeply($hashref, {a => 'a', b => 'b', c => ',', d => undef },
'hashref correct from null tuple');
# Null array
ok ($valarray = pseudocsv_parse($nullarray, 'test'),
'Parse success, simple array');
is_deeply($valarray, ['a', 'b', ',', undef], 'Parse correct, simple array');
# Nested tuple
ok ($valarray = pseudocsv_parse($nestedtuple, 'test'),
'Parse success, nested tuple');
is_deeply($valarray, ['a', 'b', ',', '(1,a)'], 'Parse correct, simple array');
# Tuple with array
ok ($valarray = pseudocsv_parse($tuplewitharray, 'test'),
'Parse success, tuple with array member');
is_deeply($valarray, ['a', 'b', ',', [1, 'a']], 'Parse correct, tuple with array');
# Array of tuples
ok ($valarray = pseudocsv_parse($arrayoftuples, 'test'),
'Parse success, tuple with array of tuples');
is_deeply($valarray, ['(a,b)','(1,a)'], 'Parse correct, array of tuples');
# New line tuple
ok ($valarray = pseudocsv_parse($newlinetuple, 'test'),
'Parse success, tuple with array of tuples');
is_deeply($valarray, ['a', 'b', ",\n"], 'Parse correct, array of tuples');
# New line array
ok ($valarray = pseudocsv_parse($newlinearray, 'test'),
'Parse success, tuple with array of tuples');
is_deeply($valarray, ['a', 'b', ",\n"], 'Parse correct, array of tuples');
|