File: wrapmacro_runme.pl

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (55 lines) | stat: -rw-r--r-- 1,446 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 27;
BEGIN { use_ok('wrapmacro') }
require_ok('wrapmacro');

# adapted from ../python/wrapmacro_runme.py

my $a = 2;
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);
}