1use strict; 2use warnings; 3use Test::More; 4 5use XS::APItest; 6 7my $sv = bless {}, 'Moo'; 8my $foo = 'affe'; 9my $bar = 'tiger'; 10 11ok !mg_find_foo($sv), 'no foo magic yet'; 12ok !mg_find_bar($sv), 'no bar magic yet'; 13 14sv_magic_foo($sv, $foo); 15is mg_find_foo($sv), $foo, 'foo magic attached'; 16ok !mg_find_bar($sv), '... but still no bar magic'; 17 18sv_magic_bar($sv, $bar); 19is mg_find_foo($sv), $foo, 'foo magic still attached'; 20is mg_find_bar($sv), $bar, '... and bar magic is there too'; 21 22sv_unmagic_foo($sv); 23ok !mg_find_foo($sv), 'foo magic removed'; 24is mg_find_bar($sv), $bar, '... but bar magic is still there'; 25 26sv_unmagic_bar($sv); 27ok !mg_find_foo($sv), 'foo magic still removed'; 28ok !mg_find_bar($sv), '... and bar magic is removed too'; 29 30is(test_get_vtbl(), 0, 'get_vtbl(-1) returns NULL'); 31 32use Scalar::Util 'weaken'; 33eval { sv_magic(\!0, $foo) }; 34is $@, "", 'PERL_MAGIC_ext is permitted on read-only things'; 35 36done_testing; 37