| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use warnings; |
| 4 |
use strict; |
| 5 |
|
| 6 |
use Test::More tests => 25; |
| 7 |
use XS::APItest; |
| 8 |
|
| 9 |
my $ppaddr = xop_ppaddr; |
| 10 |
|
| 11 |
my $av = xop_build_optree; |
| 12 |
|
| 13 |
is $av->[2], "NAME:custom", "unregistered XOPs have default name"; |
| 14 |
is $av->[3], "DESC:unknown custom operator", |
| 15 |
"unregistered XOPs have default desc"; |
| 16 |
is $av->[4], "CLASS:0", "unregistered XOPs are BASEOPs"; |
| 17 |
is scalar @$av, 5, "unregistered XOPs don't call peep"; |
| 18 |
|
| 19 |
my $names = xop_custom_op_names; |
| 20 |
$names->{$ppaddr} = "foo"; |
| 21 |
$av = xop_build_optree; |
| 22 |
|
| 23 |
is $av->[2], "NAME:foo", "PL_custom_op_names honoured"; |
| 24 |
is $av->[3], "DESC:unknown custom operator", |
| 25 |
"PL_custom_op_descs can be empty"; |
| 26 |
is $av->[4], "CLASS:0", "class fallback still works"; |
| 27 |
|
| 28 |
# this will segfault if the HV isn't there |
| 29 |
my $ops = xop_custom_ops; |
| 30 |
pass "PL_custom_ops created OK"; |
| 31 |
|
| 32 |
my $descs = xop_custom_op_descs; |
| 33 |
$descs->{$ppaddr} = "bar"; |
| 34 |
# this is not generally a supported operation |
| 35 |
delete $ops->{$ppaddr}; |
| 36 |
$av = xop_build_optree; |
| 37 |
|
| 38 |
is $av->[3], "DESC:bar", "PL_custom_op_descs honoured"; |
| 39 |
|
| 40 |
my $xop = xop_my_xop; |
| 41 |
delete $ops->{$ppaddr}; |
| 42 |
delete $names->{$ppaddr}; |
| 43 |
delete $descs->{$ppaddr}; |
| 44 |
xop_register; |
| 45 |
|
| 46 |
is $ops->{$ppaddr}, $xop, "XOP registered OK"; |
| 47 |
|
| 48 |
is xop_from_custom_op, $xop, "XOP lookup from OP roundtrips"; |
| 49 |
|
| 50 |
$av = xop_build_optree; |
| 51 |
my $OA_UNOP = xop_OA_UNOP; |
| 52 |
my ($unop, $kid) = ("???" x 2); |
| 53 |
|
| 54 |
# we can't use 'like', since that runs the match in a different scope |
| 55 |
# and so doesn't set $1 |
| 56 |
ok $av->[0] =~ /unop:([0-9a-f]+)/, "got unop address" |
| 57 |
and $unop = $1; |
| 58 |
ok $av->[1] =~ /kid:([0-9a-f]+)/, "got kid address" |
| 59 |
and $kid = $1; |
| 60 |
|
| 61 |
is $av->[2], "NAME:my_xop", "OP_NAME returns registered name"; |
| 62 |
is $av->[3], "DESC:XOP for testing", "OP_DESC returns registered desc"; |
| 63 |
is $av->[4], "CLASS:$OA_UNOP", "OP_CLASS returns registered class"; |
| 64 |
is scalar @$av, 7, "registered peep called"; |
| 65 |
is $av->[5], "peep:$unop", "...with correct 'o' param"; |
| 66 |
is $av->[6], "oldop:$kid", "...and correct 'oldop' param"; |
| 67 |
|
| 68 |
xop_clear; |
| 69 |
|
| 70 |
is $ops->{$ppaddr}, $xop, "clearing XOP doesn't remove it"; |
| 71 |
|
| 72 |
$av = xop_build_optree; |
| 73 |
|
| 74 |
is $av->[2], "NAME:custom", "clearing XOP resets name"; |
| 75 |
is $av->[3], "DESC:unknown custom operator", |
| 76 |
"clearing XOP resets desc"; |
| 77 |
is $av->[4], "CLASS:0", "clearing XOP resets class"; |
| 78 |
is scalar @$av, 5, "clearing XOP removes peep"; |
| 79 |
|
| 80 |
ok test_newOP_CUSTOM(), |
| 81 |
'newOP et al. do not fail assertions with OP_CUSTOM'; |