6 BEGIN {use_ok('XS::APItest')};
17 my %types = map {$_, eval "&to_${_}_amg()"} values %sigils;
25 use overload 'eq' => sub {no overloading; $_[0] == $_[1]},
26 '""' => sub {no overloading; "$_[0]"},
27 '~' => sub {return "Perl rules"};
32 use overload 'eq' => sub {no overloading; $_[0] == $_[1]},
33 '""' => sub {no overloading; "$_[0]"},
34 map {$_ . '{}', sub {return $_[0]}} keys %sigils;
39 use overload 'eq' => sub {no overloading; $_[0] == $_[1]},
40 '""' => sub {no overloading; "$_[0]"},
41 map {$_ . '{}', sub {no overloading; return $_[0][0]}} keys %sigils;
44 my @non_ref = (['undef', undef],
49 my @ref = (['unblessed SV', do {\my $whap}],
52 ['unblessed CV', sub {}],
53 ['unblessed GV', \*STDOUT],
54 ['no overloading', bless {}, 'None'],
55 ['other overloading', bless {}, 'Other'],
56 ['same overloading', bless {}, 'Same'],
59 while (my ($type, $enum) = each %types) {
60 foreach ([amagic_deref_call => \&amagic_deref_call],
61 [tryAMAGICunDEREF_var => \&tryAMAGICunDEREF_var],
63 my ($name, $func) = @$_;
64 foreach (@non_ref, @ref,
66 my ($desc, $input) = @$_;
67 my $got = &$func($input, $enum);
68 is($got, $input, "$name: expect no change for to_$type $desc");
71 my ($desc, $sucker) = @$_;
72 my $input = bless [$sucker], 'Chain';
73 is(eval {&$func($input, $enum)}, undef,
74 "$name: chain to $desc for to_$type");
75 like($@, qr/Overloaded dereference did not return a reference/,
80 my ($desc, $sucker) = @$_;
81 my $input = bless [$sucker], 'Chain';
82 my $got = &$func($input, $enum);
83 is($got, $sucker, "$name: chain to $desc for to_$type");
84 $input = bless [bless [$sucker], 'Chain'], 'Chain';
85 $got = &$func($input, $enum);
86 is($got, $sucker, "$name: chain to chain to $desc for to_$type");