File: grammars.t

package info (click to toggle)
libinline-perl 0.44-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 440 kB
  • ctags: 121
  • sloc: perl: 3,768; makefile: 38
file content (292 lines) | stat: -rw-r--r-- 5,656 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# Test both parser implementations to ensure they work the same
use strict;
use Test;
use YAML;
use File::Spec;

use blib;
require Inline::C::ParseRecDescent;
require Inline::C::ParseRegExp;

# Do all the typemap foo that Inline::C does
require Inline::C;
use Config;
my $typemap = File::Spec->catfile($Config::Config{installprivlib},
                                  'ExtUtils', 'typemap');
my $o = bless {}, 'Inline::C';
push @{$o->{ILSM}{MAKEFILE}{TYPEMAPS}}, $typemap
  if -f $typemap;
$o->get_types;

# Create new instances of each parser
my $recdescent = Inline::C::ParseRecDescent->get_parser();
my $regexp = Inline::C::ParseRegExp->get_parser();

$recdescent->{data}{typeconv} = $o->{ILSM}{typeconv};
$regexp->{data}{typeconv} = $o->{ILSM}{typeconv};

my @test_objects = @{YAML::Load($Inline::cases)};
plan(tests => 2 * @test_objects);

for my $case (@test_objects) {
    my $input = $case->{input};
    my $expect = $case->{expect};

    my @outputs;
    for ($recdescent, $regexp) {
        # Without a fresh copy of these objects, the same stuff is parsed over
        # and over.  However, because Parse::RecDescent is sllloooww, we can't
        # just construct a new object over and over. Hence, new() 'em up top,
        # and then clone them here.
        my $parser = deep_clone($_);
        $parser->code($input);
        delete $parser->{data}{typeconv};
        my $output = YAML::Dump($parser->{data});
        $output =~ s/^---.*\n//;
        push @outputs, $output;
    }

    ok($outputs[0], $expect, "ParseRecDescent failed for:$input\n");
    ok($outputs[1], $expect, "ParseRegExp failed for:$input\n");
}

use Data::Dumper;
sub deep_clone {
    my $VAR1;
    eval Dumper($_[0]);
    $VAR1
}

BEGIN {
($Inline::cases, undef) = (<<END, <<END);
- input: long get_serial(SV* obj) {
  expect: |
    done:
      get_serial: 1
    function:
      get_serial:
        arg_names:
          - obj
        arg_types:
          - SV *
        return_type: long
    functions:
      - get_serial

- input: SV* new(char* class, char* name, char* rank, long serial) {
  expect: |
    done:
      new: 1
    function:
      new:
        arg_names:
          - class
          - name
          - rank
          - serial
        arg_types:
          - char *
          - char *
          - char *
          - long
        return_type: SV *
    functions:
      - new

- input: |
    unsigned foo (unsigned int a, 
                  unsigned short b,
                  unsigned char c, 
                  unsigned char * d) {
  expect: |
    done:
      foo: 1
    function:
      foo:
        arg_names:
          - a
          - b
          - c
          - d
        arg_types:
          - unsigned int
          - unsigned short
          - unsigned char
          - unsigned char *
        return_type: unsigned
    functions:
      - foo

- input: long Foo5(int i, int j, ...) { return 3; }
  expect: |
    done:
      Foo5: 1
    function:
      Foo5:
        arg_names:
          - i
          - j
          - '...'
        arg_types:
          - int
          - int
          - '...'
        return_type: long
    functions:
      - Foo5

- input: char *func(char *x, char* y, char  *  z) {
  expect: |
    done:
      func: 1
    function:
      func:
        arg_names:
          - x
          - y
          - z
        arg_types:
          - char *
          - char *
          - char *
        return_type: char *
    functions:
      - func

- input: unsigned func(unsigned arg) {
  expect: |
    done:
      func: 1
    function:
      func:
        arg_names:
          - arg
        arg_types:
          - unsigned
        return_type: unsigned
    functions:
      - func

- input: void simplest() { }
  expect: &simplest |
    done:
      simplest: 1
    function:
      simplest:
        arg_names: []
        arg_types: []
        return_type: void
    functions:
      - simplest

- input: void simplest() {
  expect: *simplest
- input: |
    void
    simplest
    (
    )
    {
  expect: *simplest

- input: |
    void simplest() {
        with_a_body__too();
    }
  expect: *simplest

- input: |
    /* C comment */
    void simplest() {
  expect: *simplest

- input: |
    void simplest() { }
    /* void bogus() { } */
  expect: *simplest

- input: |
    // C++/C99 comment...
    void simplest() {
  expect: *simplest

- input: |
    void simplest() { }
    // void bogus() { }
  expect: *simplest

- input: int with_return_value() {
  expect: |
    done:
      with_return_value: 1
    function:
      with_return_value:
        arg_names: []
        arg_types: []
        return_type: int
    functions:
      - with_return_value

- input: void takes_a_char_star(char* name) {
  expect: |
    done:
      takes_a_char_star: 1
    function:
      takes_a_char_star:
        arg_names:
          - name
        arg_types:
          - char *
        return_type: void
    functions:
      - takes_a_char_star

- input: |
    int addem(int x, int y) {
        return x + y;
    }
  expect: |
    done:
      addem: 1
    function:
      addem:
        arg_names:
          - x
          - y
        arg_types:
          - int
          - int
        return_type: int
    functions:
      - addem

- input: |
    void a() { }
    void b() { }
    void c() { }
  expect: |
    done:
      a: 1
      b: 1
      c: 1
    function:
      a:
        arg_names: []
        arg_types: []
        return_type: void
      b:
        arg_names: []
        arg_types: []
        return_type: void
      c:
        arg_names: []
        arg_types: []
        return_type: void
    functions:
      - a
      - b
      - c

END
END
}