capture the current behavior of perlprimtypes.swg is more detail

This commit is contained in:
Robert Stone 2015-08-08 11:32:55 -07:00
commit 8ac4a8147b
2 changed files with 80 additions and 2 deletions

View file

@ -2,7 +2,7 @@
use overload_simple;
use vars qw/$DOWARN/;
use strict;
use Test::More tests => 75;
use Test::More tests => 97;
pass("loaded");
@ -196,3 +196,40 @@ is(overload_simple::int_object(1), 1, "int_object(1)");
is(overload_simple::int_object(0), 0, "int_object(0)");
is(overload_simple::int_object(undef), 999, "int_object(Spam*)");
is(overload_simple::int_object($s), 999, "int_object(Spam*)");
# some of this section is duplication of above tests, but I want to see
# parity with the coverage in wrapmacro_runme.pl.
sub check {
my($args, $want) = @_;
my($s, $rslt) = defined $want ? ($want, "bar:$want") : ('*boom*', undef);
is(eval("overload_simple::Spam::bar($args)"), $rslt, "bar($args) => $s");
}
# normal use patterns
check("11", 'int');
check("11.0", 'double');
check("'11'", 'char *');
check("'11.0'", 'char *');
check("-13", 'int');
check("-13.0", 'double');
check("'-13'", 'char *');
check("'-13.0'", 'char *');
check("' '", 'char *');
check("' 11 '", 'char *');
# TypeError explosions
check("\\*STDIN", undef);
check("[]", undef);
check("{}", undef);
check("sub {}", undef);
# regression cases
check("''", 'char *');
check("' 11'", 'char *');
check("' 11.0'", 'char *');
check("' -11.0'", 'char *');
check("\"11\x{0}\"", 'char *');
check("\"\x{0}\"", 'char *');
check("\"\x{9}11\x{0}this is not eleven.\"", 'char *');
check("\"\x{9}11.0\x{0}this is also not eleven.\"", 'char *');

View file

@ -1,7 +1,7 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 5;
use Test::More tests => 27;
BEGIN { use_ok('wrapmacro') }
require_ok('wrapmacro');
@ -12,3 +12,44 @@ my $b = -1;
is(wrapmacro::maximum($a,$b), 2);
is(wrapmacro::maximum($a/7.0, -$b*256), 256);
is(wrapmacro::GUINT16_SWAP_LE_BE_CONSTANT(1), 256);
# some of this section is duplication of above tests, but I want to see
# parity with the coverage in overload_simple_runme.pl.
sub check {
my($args, $rslt) = @_;
my $s = defined $rslt ? $rslt : '*boom*';
is(eval("wrapmacro::maximum($args)"), $rslt, "max($args) => $s");
}
# normal use patterns
check("0, 11", 11);
check("0, 11.0", 11);
check("0, '11'", 11);
check("0, '11.0'", 11);
check("11, -13", 11);
check("11, -13.0", 11);
{ local $TODO = 'strtoull() handles /^\s*-\d+$/ amusingly';
check("11, '-13'", 11);
}
check("11, '-13.0'", 11);
# TypeError explosions
check("0, ' '", undef);
check("0, ' 11 '", undef);
check("0, \\*STDIN", undef);
check("0, []", undef);
check("0, {}", undef);
check("0, sub {}", undef);
# regression cases
{ local $TODO = 'strtol() and friends have edge cases we should guard against';
check("-11, ''", undef);
check("0, ' 11'", undef);
check("0, ' 11.0'", undef);
check("-13, ' -11.0'", undef);
check("0, \"11\x{0}\"", undef);
check("0, \"\x{0}\"", undef);
check("0, \"\x{9}11\x{0}this is not eleven.\"", undef);
check("0, \"\x{9}11.0\x{0}this is also not eleven.\"", undef);
}