diff options
author | Steffen Mueller <smueller@cpan.org> | 2011-04-17 17:13:43 +0200 |
---|---|---|
committer | Steffen Mueller <smueller@cpan.org> | 2011-07-12 20:54:51 +0200 |
commit | 48150f65fc4a017fa6e14355313b169601ce3baf (patch) | |
tree | e05c16e980b3b54ff490a63b8e00a4ca9fe6bcce /dist | |
parent | 21edc85ae2ee8226f5ee3f43e31dd1e402c8361d (diff) | |
download | perl-48150f65fc4a017fa6e14355313b169601ce3baf.tar.gz |
Add is_empty method to EU::Typemaps
Diffstat (limited to 'dist')
-rw-r--r-- | dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm | 13 | ||||
-rw-r--r-- | dist/ExtUtils-ParseXS/t/510-t-bare.t | 17 |
2 files changed, 27 insertions, 3 deletions
diff --git a/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm b/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm index 0bc08cd803..0f5d12c840 100644 --- a/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm +++ b/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm @@ -635,6 +635,19 @@ sub merge { return 1; } +=head2 is_empty + +Returns a bool indicating whether this typemap is entirely empty. + +=cut + +sub is_empty { + my $self = shift; + + return @{ $self->{typemap_section} } == 0 + && @{ $self->{input_section} } == 0 + && @{ $self->{output_section} } == 0; +} =head2 _get_typemap_hash diff --git a/dist/ExtUtils-ParseXS/t/510-t-bare.t b/dist/ExtUtils-ParseXS/t/510-t-bare.t index a2f359d80e..033c0aea5a 100644 --- a/dist/ExtUtils-ParseXS/t/510-t-bare.t +++ b/dist/ExtUtils-ParseXS/t/510-t-bare.t @@ -2,13 +2,20 @@ use strict; use warnings; -use Test::More tests => 38; +use Test::More tests => 43; use ExtUtils::Typemaps; +# empty typemap +SCOPE: { + ok(ExtUtils::Typemaps->new()->is_empty(), "This is an empty typemap"); +} + # typemap only SCOPE: { my $map = ExtUtils::Typemaps->new(); $map->add_typemap(ctype => 'unsigned int', xstype => 'T_IV'); + ok(!$map->is_empty(), "This is not an empty typemap"); + is($map->as_string(), <<'HERE', "Simple typemap matches expectations"); TYPEMAP unsigned int T_IV @@ -20,6 +27,7 @@ HERE is($type->xstype, 'T_IV'); is($type->tidy_ctype, 'unsigned int'); + # test failure ok(!$map->get_typemap(ctype => 'foo'), "Access to nonexistent typemap doesn't die"); ok(!$map->get_inputmap(ctype => 'foo'), "Access to nonexistent inputmap via ctype doesn't die"); @@ -34,8 +42,9 @@ HERE # typemap & input SCOPE: { my $map = ExtUtils::Typemaps->new(); - $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV'); $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);'); + ok(!$map->is_empty(), "This is not an empty typemap"); + $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV'); is($map->as_string(), <<'HERE', "Simple typemap (with input) matches expectations"); TYPEMAP unsigned int T_UV @@ -64,8 +73,9 @@ HERE # typemap & output SCOPE: { my $map = ExtUtils::Typemaps->new(); - $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV'); $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);'); + ok(!$map->is_empty(), "This is not an empty typemap"); + $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV'); is($map->as_string(), <<'HERE', "Simple typemap (with output) matches expectations"); TYPEMAP unsigned int T_UV @@ -92,6 +102,7 @@ SCOPE: { $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV'); $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);'); $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);'); + ok(!$map->is_empty(), "This is not an empty typemap"); is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations"); TYPEMAP unsigned int T_UV |