1#!/usr/bin/perl 2use strict; 3use warnings; 4use Test::More tests => 27; 5BEGIN { use_ok('wrapmacro') } 6require_ok('wrapmacro'); 7 8# adapted from ../python/wrapmacro_runme.py 9 10my $a = 2; 11my $b = -1; 12is(wrapmacro::maximum($a,$b), 2); 13is(wrapmacro::maximum($a/7.0, -$b*256), 256); 14is(wrapmacro::GUINT16_SWAP_LE_BE_CONSTANT(1), 256); 15 16# some of this section is duplication of above tests, but I want to see 17# parity with the coverage in overload_simple_runme.pl. 18 19sub check { 20 my($args, $rslt) = @_; 21 my $s = defined $rslt ? $rslt : '*boom*'; 22 is(eval("wrapmacro::maximum($args)"), $rslt, "max($args) => $s"); 23} 24 25# normal use patterns 26check("0, 11", 11); 27check("0, 11.0", 11); 28check("0, '11'", 11); 29check("0, '11.0'", 11); 30check("11, -13", 11); 31check("11, -13.0", 11); 32{ local $TODO = 'strtoull() handles /^\s*-\d+$/ amusingly'; 33check("11, '-13'", 11); 34} 35check("11, '-13.0'", 11); 36 37# TypeError explosions 38check("0, ' '", undef); 39check("0, ' 11 '", undef); 40check("0, \\*STDIN", undef); 41check("0, []", undef); 42check("0, {}", undef); 43check("0, sub {}", undef); 44 45# regression cases 46{ local $TODO = 'strtol() and friends have edge cases we should guard against'; 47check("-11, ''", undef); 48check("0, ' 11'", undef); 49check("0, ' 11.0'", undef); 50check("-13, ' -11.0'", undef); 51check("0, \"11\x{0}\"", undef); 52check("0, \"\x{0}\"", undef); 53check("0, \"\x{9}11\x{0}this is not eleven.\"", undef); 54check("0, \"\x{9}11.0\x{0}this is also not eleven.\"", undef); 55} 56