#!perl -T
use
5.10.1;
$ProfileDict)
;
Readonly
our
%payloadKeys
=> (
'numberField'
=> {
type
=>
$ProfileNumber
,
description
=>
'A field containing a number.'
,
},
'numberArrayField'
=> {
type
=>
$ProfileArray
,
subtype
=>
$ProfileNumber
,
description
=>
'An array of numbers.'
,
},
'numberDictField'
=> {
type
=>
$ProfileDict
,
subtype
=>
$ProfileNumber
,
description
=>
'A dictionary of numbers.'
,
}
);
diag(
'This Perl uses '
, (
defined
$Config
{d_quad}) ? 64 : 32,
'-bit numbers.'
,
);
Readonly
my
@numbers
=> (
0,
10,
1561584,
-1,
-145688405,
-12,
(
defined
$Config
{d_quad}) ? 18446744073709551615 : 4294967295,
(
defined
$Config
{d_quad}) ? -9223372036854775808 : -2147483648,
'+1'
,
'+15'
,
'+1500351783'
,
);
Readonly
my
@baddies
=> (
undef
,
''
,
'Hello'
,
'Booga blargh!'
,
[
qw(1 2 3)
],
{
qw(1 hello 2 goodbye)
},
new File::Temp,
1.314159265,
1.5663,
0.2992,
);
plan
tests
=> 10
*scalar
(
@numbers
) + 3
*scalar
(
@baddies
);
my
$i
= 0;
foreach
my
$number
(
@numbers
) {
my
$object
= new Local::Number;
my
$payload
=
$object
->payload;
lives_ok {
$payload
->{numberField} =
$number
}
"Write number $number (#$i)"
;
my
$read_number
=
$payload
->{numberField};
ok(
defined
(
$read_number
),
'Read number back'
);
cmp_ok(
$read_number
,
'=='
,
$number
,
'Compare numbers'
);
lives_ok {
push
@{
$payload
->{numberArrayField}},
$number
; }
'Push number onto array'
;
lives_ok {
$payload
->{numberDictField}->{
"test$i"
} =
$number
; }
'Insert number into dictionary'
;
my
$plist
;
lives_ok {
$plist
=
$object
->plist}
'Convert to plist'
;
cmp_ok(
$plist
->value->{numberField}->value,
'=='
,
$number
,
'plist number matches'
);
cmp_ok(
$plist
->value->{numberArrayField}->value->[-1]->value,
'eq'
,
$payload
->{numberField},
'test number at the end of array'
);
ok(
exists
$plist
->value->{numberDictField}->value->{
"test$i"
},
'Test number is in dictionary'
);
cmp_ok(
$plist
->value->{numberDictField}->value->{
"test$i"
}->value,
'=='
,
$payload
->{numberField},
'Number in dictionary matches'
);
$i
++;
}
$i
= 0;
foreach
my
$not_number
(
@baddies
) {
my
$object
= new Local::Number;
my
$payload
=
$object
->payload;
dies_ok {
$payload
->{numberField} =
$not_number
; }
"A non-number (#$i)"
;
dies_ok {
push
@{
$payload
->{numberArrayField}},
$not_number
; }
'... pushing also fails'
;
dies_ok {
$payload
->{numberDictField}->{
"test$i"
} =
$not_number
; }
'... dict also fails'
;
$i
++;
}
done_testing();