File: 03-compilation-output.t

package info (click to toggle)
libfilter-signatures-perl 0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 236 kB
  • sloc: perl: 1,321; makefile: 2
file content (398 lines) | stat: -rw-r--r-- 9,108 bytes parent folder | download
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!perl -w
use strict;
use Test::More tests => 30;
use Data::Dumper;

require Filter::signatures;

# Mimic parts of the setup of Filter::Simple
my $extractor =
$Filter::Simple::placeholder = $Filter::Simple::placeholder
    = qr/\Q$;\E(.{4})\Q$;\E/s;

# Anonymous
$_ = <<'SUB';
sub ($name, $value) {
        return "'$name' is '$value'"
    };
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Anonymous subroutines get converted";
sub  { my ($name,$value)=@_;();
        return "'$name' is '$value'"
    };
RESULT

$_ = <<'SUB';
sub foo5 () {
        return "We can call a sub without parameters"
};
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Parameterless subroutines don't get converted";
sub foo5 { @_==0 or warn "Subroutine foo5 called with parameters.";();
        return "We can call a sub without parameters"
};
RESULT

# Function default parameters
$_ = <<'SUB';
sub mylog($msg, $when=time) {
    print "[$when] $msg\n";
};
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Function default parameters get converted";
sub mylog { my ($msg,$when)=@_;$when = time if @_ <= 1;();
    print "[$when] $msg\n";
};
RESULT

# Empty parameter list
$_ = <<'SUB';
sub mysub() {
    print "Yey\n";
};
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Functions without parameters get converted properly";
sub mysub { @_==0 or warn "Subroutine mysub called with parameters.";();
    print "Yey\n";
};
RESULT

# Discarding parameters
$_ = <<'SUB';
sub mysub($) {
    print "Yey\n";
};
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Functions with unnamed parameters get converted properly";
sub mysub { my (undef)=@_;();
    print "Yey\n";
};
RESULT

# Discarding parameters
$_ = <<'SUB';
sub mysub($foo, $, $bar) {
    print "Yey, $foo => $bar\n";
};
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Functions without parameters get converted properly";
sub mysub { my ($foo,undef,$bar)=@_;();
    print "Yey, $foo => $bar\n";
};
RESULT

# Signature-less functions remain unchanged
$_ = <<'SUB';
sub mysub {
    print "Yey\n";
};
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Named functions without signature remain unchanged";
sub mysub {
    print "Yey\n";
};
RESULT

$_ = <<'SUB';
sub {
    print "Yey\n";
};
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Named functions without signature remain unchanged";
sub {
    print "Yey\n";
};
RESULT

$_ = <<'SUB';
sub foo($bar,$baz) { print "Yey\n"; }
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "RT #xxxxxx Single-line functions work";
sub foo { my ($bar,$baz)=@_;(); print "Yey\n"; }
RESULT

{ local $TODO = "Recursive parentheses don't work on $]"
  if( $] < 5.010 );

$_ = <<'SUB';
sub staleUploads( $self, $timeout = 3600, $now = time() ) {
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Default arguments with parentheses work";
sub staleUploads { my ($self,$timeout,$now)=@_;$timeout = 3600 if @_ <= 1;$now = time() if @_ <= 2;();
}
RESULT

$_ = <<'SUB';
sub staleUploads( $self, $timeout = 3600, $now = time((()))) {
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Default arguments with multiple parentheses work";
sub staleUploads { my ($self,$timeout,$now)=@_;$timeout = 3600 if @_ <= 1;$now = time((())) if @_ <= 2;();
}
RESULT

$_ = <<'SUB';
sub ( $self, $now = localtime(1)) {
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Default arguments with parentheses and values work";
sub  { my ($self,$now)=@_;$now = localtime(1) if @_ <= 1;();
}
RESULT

}

$_ = <<'SUB';
sub ( $self, $cb = sub {
}) {
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Default arguments with parentheses and values work";
sub  { my ($self,$cb)=@_;$cb = sub { } if @_ <= 1;();

}
RESULT

$_ = <<'SUB';
sub f ($a,@) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Slurpy discard argument works";
sub f { my ($a,undef)=@_;();
...
}
RESULT

$_ = <<'SUB';
my @args;
sub ( $self, $foo = $#args) {
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Default arguments that look like comments";
my @args;
sub  { my ($self,$foo)=@_;$foo = $#args if @_ <= 1;();
}
RESULT

$_ = <<'SUB';
sub f ($a = /\w/ ) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Argument lists containing regular expressions work";
sub f { my ($a)=@_;$a = /\w/ if @_ <= 0;();
...
}
RESULT

$_ = <<'SUB';
sub f ($a = \$b, $c=\@d, $e=\%f, $g=\&h, $i=\*j ) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Argument lists containing scalar references";
sub f { my ($a,$c,$e,$g,$i)=@_;$a = \$b if @_ <= 0;$c = \@d if @_ <= 1;$e = \%f if @_ <= 2;$g = \&h if @_ <= 3;$i = \*j if @_ <= 4;();
...
}
RESULT

$_ = <<'SUB';
sub f ($a = /\(/ ) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Argument lists containing unmatched parentheses work";
sub f { my ($a)=@_;$a = /\(/ if @_ <= 0;();
...
}
RESULT

$_ = <<'SUB';
sub f ($a = /[\(]/ ) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Characterclasses with unmatched quoted parentheses work";
sub f { my ($a)=@_;$a = /[\(]/ if @_ <= 0;();
...
}
RESULT

{ local $TODO = "Recursive parentheses don't work on $]"
  if( $] < 5.010 );

$_ = <<'SUB';
sub f ($a = /[\)]/ ) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Characterclasses with unmatched quoted parentheses work";
sub f { my ($a)=@_;$a = /[\)]/ if @_ <= 0;();
...
}
RESULT
}

{ local $TODO = 'More robust regexp parsing needed';
$_ = <<'SUB';
sub f ($a = /[(]/ ) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Regular expressions containing characterclasses with unmatched parentheses work";
sub f { my ($a)=@_;$a = /\(/ if @_ <= 0;();
...
}
RESULT

$_ = <<'SUB';
sub f ($a = /[)]/ ) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Regular expressions containing characterclasses with unmatched parentheses work";
sub f { my ($a)=@_;$a = /[)]/ if @_ <= 0;();
...
}
RESULT

}

{ local $TODO = "Recursive parentheses don't work on $]"
  if( $] < 5.010 );

$_ = <<'SUB';
sub f ($a = qr(\() ) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Argument lists containing unmatched parentheses within qr-strings work";
sub f { my ($a)=@_;$a = qr(\() if @_ <= 0;();
...
}
RESULT
}

$_ = <<'SUB';
sub f ($a = do { }) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "do-blocks work";
sub f { my ($a)=@_;$a = do { } if @_ <= 0;();
...
}
RESULT

{ local $TODO = "Recursive parentheses don't work on $]"
  if( $] < 5.010 );

$_ = <<'SUB';
sub f ($a = substr("abc",0,1)) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Commas within subroutine calls don't split the argument lists";
sub f { my ($a)=@_;$a = substr("abc",0,1) if @_ <= 0;();
...
}
RESULT
}

$_ = <<'SUB';
sub f ($a = /\,/, $b=1) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Commas within regular expression matches don't split the argument lists";
sub f { my ($a,$b)=@_;$a = /\,/ if @_ <= 0;$b = 1 if @_ <= 1;();
...
}
RESULT

$_ = <<'SUB';
sub f ($a = /\,/, $b=1) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Commas within regular expression matches don't split the argument lists";
sub f { my ($a,$b)=@_;$a = /\,/ if @_ <= 0;$b = 1 if @_ <= 1;();
...
}
RESULT

$_ = <<'SUB';
sub f ($a = do { $x = "abc"; return substr $x,0,1}) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Commas within do-blocks don't split the argument lists";
sub f { my ($a)=@_;$a = do { $x = "abc"; return substr $x,0,1} if @_ <= 0;();
...
}
RESULT

{ local $TODO = "Recursive parentheses don't work on $]"
  if( $] < 5.010 );

$_ = <<'SUB';
sub f ($a = do { $x = "abc"; return substr($x,0,1)}) {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "do-blocks with parentheses work";
sub f { my ($a)=@_;$a = do { $x = "abc"; return substr($x,0,1)} if @_ <= 0;();
...
}
RESULT
}

# This is a test for the placeholders that Filter::Simple supplies - if you
# have enough of them, "interesting" characters pop up within these placeholders
# We have an interesting dependency on the format of these placeholders.
$_ = <<'SUB';
sub f ($a = "...(") {
...
}
SUB
Filter::signatures::transform_arguments();
is $_, <<'RESULT', "Parentheses in (replaced) string arguments work";
sub f { my ($a)=@_;$a = "...(" if @_ <= 0;();
...
}
RESULT

if( $Test::More::VERSION > 0.87 ) { # 5.8.x compatibility
    done_testing();
};