This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Implement 'skip' option for merging typemaps
[perl5.git] / dist / ExtUtils-ParseXS / t / 510-t-bare.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 29;
6 use ExtUtils::Typemaps;
7
8 # typemap only
9 SCOPE: {
10   my $map = ExtUtils::Typemaps->new();
11   $map->add_typemap(ctype => 'unsigned int', xstype => 'T_IV');
12   is($map->as_string(), <<'HERE', "Simple typemap matches expectations");
13 TYPEMAP
14 unsigned int    T_IV
15 HERE
16
17   my $type = $map->get_typemap(ctype => 'unsigned int');
18   isa_ok($type, 'ExtUtils::Typemaps::Type');
19   is($type->ctype, 'unsigned int');
20   is($type->xstype, 'T_IV');
21   is($type->tidy_ctype, 'unsigned int');
22 }
23
24 # typemap & input
25 SCOPE: {
26   my $map = ExtUtils::Typemaps->new();
27   $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
28   $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
29   is($map->as_string(), <<'HERE', "Simple typemap (with input) matches expectations");
30 TYPEMAP
31 unsigned int    T_UV
32
33 INPUT
34 T_UV
35         $var = ($type)SvUV($arg);
36 HERE
37
38   my $type = $map->get_typemap(ctype => 'unsigned int');
39   isa_ok($type, 'ExtUtils::Typemaps::Type');
40   is($type->ctype, 'unsigned int');
41   is($type->xstype, 'T_UV');
42   is($type->tidy_ctype, 'unsigned int');
43
44   my $in = $map->get_inputmap(xstype => 'T_UV');
45   isa_ok($in, 'ExtUtils::Typemaps::InputMap');
46   is($in->xstype, 'T_UV');
47 }
48
49
50 # typemap & output
51 SCOPE: {
52   my $map = ExtUtils::Typemaps->new();
53   $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
54   $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
55   is($map->as_string(), <<'HERE', "Simple typemap (with output) matches expectations");
56 TYPEMAP
57 unsigned int    T_UV
58
59 OUTPUT
60 T_UV
61         sv_setuv($arg, (UV)$var);
62 HERE
63
64   my $type = $map->get_typemap(ctype => 'unsigned int');
65   isa_ok($type, 'ExtUtils::Typemaps::Type');
66   is($type->ctype, 'unsigned int');
67   is($type->xstype, 'T_UV');
68   is($type->tidy_ctype, 'unsigned int');
69
70   my $in = $map->get_outputmap(xstype => 'T_UV');
71   isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
72   is($in->xstype, 'T_UV');
73 }
74
75 # typemap & input & output
76 SCOPE: {
77   my $map = ExtUtils::Typemaps->new();
78   $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
79   $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
80   $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
81   is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations");
82 TYPEMAP
83 unsigned int    T_UV
84
85 INPUT
86 T_UV
87         $var = ($type)SvUV($arg);
88
89 OUTPUT
90 T_UV
91         sv_setuv($arg, (UV)$var);
92 HERE
93 }
94
95 # two typemaps & input & output
96 SCOPE: {
97   my $map = ExtUtils::Typemaps->new();
98   $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
99   $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
100   $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
101
102   $map->add_typemap(ctype => 'int', xstype => 'T_IV');
103   $map->add_inputmap(xstype => 'T_IV', code => '$var = ($type)SvIV($arg);');
104   $map->add_outputmap(xstype => 'T_IV', code => 'sv_setiv($arg, (IV)$var);');
105   is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations");
106 TYPEMAP
107 unsigned int    T_UV
108 int     T_IV
109
110 INPUT
111 T_UV
112         $var = ($type)SvUV($arg);
113 T_IV
114         $var = ($type)SvIV($arg);
115
116 OUTPUT
117 T_UV
118         sv_setuv($arg, (UV)$var);
119 T_IV
120         sv_setiv($arg, (IV)$var);
121 HERE
122   my $type = $map->get_typemap(ctype => 'unsigned int');
123   isa_ok($type, 'ExtUtils::Typemaps::Type');
124   is($type->ctype, 'unsigned int');
125   is($type->xstype, 'T_UV');
126   is($type->tidy_ctype, 'unsigned int');
127
128   my $in = $map->get_outputmap(xstype => 'T_UV');
129   isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
130   is($in->xstype, 'T_UV');
131   $in = $map->get_outputmap(xstype => 'T_IV');
132   isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
133   is($in->xstype, 'T_IV');
134 }
135