summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Stone <talby@trap.mtview.ca.us>2015-08-08 11:32:55 -0700
committerRobert Stone <talby@trap.mtview.ca.us>2015-08-08 11:39:16 -0700
commit8ac4a8147b2dc2c47c89f9ea3ded933ceee9372f (patch)
tree2353ca427c9f465fed140c8778d8e0d00df1b8e9
parent19a20c794bea67fb7e3530da362473c05cf87cad (diff)
downloadswig-8ac4a8147b2dc2c47c89f9ea3ded933ceee9372f.tar.gz
capture the current behavior of perlprimtypes.swg is more detail
-rw-r--r--Examples/test-suite/perl5/overload_simple_runme.pl39
-rw-r--r--Examples/test-suite/perl5/wrapmacro_runme.pl43
2 files changed, 80 insertions, 2 deletions
diff --git a/Examples/test-suite/perl5/overload_simple_runme.pl b/Examples/test-suite/perl5/overload_simple_runme.pl
index 624d428c6..57a585a22 100644
--- a/Examples/test-suite/perl5/overload_simple_runme.pl
+++ b/Examples/test-suite/perl5/overload_simple_runme.pl
@@ -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 *');
diff --git a/Examples/test-suite/perl5/wrapmacro_runme.pl b/Examples/test-suite/perl5/wrapmacro_runme.pl
index 8e0154057..f2478b51b 100644
--- a/Examples/test-suite/perl5/wrapmacro_runme.pl
+++ b/Examples/test-suite/perl5/wrapmacro_runme.pl
@@ -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);
+}