eval
{
boolean->
import
(
":all"
);
};
if
( $@ ){
eval
"use Test::More qw(skip_all) => 'boolean hasn\\'t installed'"
;
exit
;
}
my
$total
= 14;
eval
"use Test::More tests=>$total;"
;
warn
($@) &&
exit
if
$@;
my
$nop
= parse_option(
'prefer_number, json_boolean'
);
our
$var
;
ok( !is_amf_boolean ( 1 ),
'perl bool context not converted()'
);
ok( !is_amf_boolean ( 0 ),
'perl bool context not converted()'
);
ok( !is_amf_boolean (
''
),
'perl bool context not converted()'
);
ok( !is_amf_boolean ( ! !1 ),
'perl bool context not converted(t)'
);
ok( !is_amf_boolean ( ! !0 ),
'perl bool context not converted(f)'
);
ok( is_amf_boolean ( true() ),
'"boolean" true'
);
ok( is_amf_boolean ( false() ),
'"boolean" false'
);
ok( !is_amf_boolean (
$a
= 4 ),
'int var'
);
ok( !is_amf_boolean (
$a
= 4.0 ),
'double var'
);
ok( !is_amf_boolean (
$a
=
"4"
),
'str var'
);
ok( is_amf_boolean(
$a
= true() ),
'boolean var'
);
ok( is_amf_boolean(
$a
= false() ),
'boolean var'
);
ok( is_amf_boolean(
$a
= true(), 1),
"true"
);
ok( is_amf_boolean(
$a
= false(), 0),
"false"
);
sub
is_amf_boolean{
is_amf0_boolean(
@_
) && is_amf3_boolean(
@_
);
}
sub
is_amf0_boolean{
return
''
unless
ord
(
my
$s
= freeze0(
$_
[0], )) == 1;
return
1
unless
defined
$_
[1];
my
$byte1
=
ord
(
substr
(
$s
,1));
return
1
if
$_
[1] &&
$byte1
== 1;
return
1
if
!
$_
[1] &&
$byte1
== 0;
return
''
;
}
sub
is_amf3_boolean{
my
$header
=
ord
( freeze3(
$_
[0] ));
return
$header
== 2 ||
$header
== 3
unless
defined
$_
[1];
return
$header
== 2
if
!
$_
[1];
return
$header
== 3
if
$_
[1]
}