-
Notifications
You must be signed in to change notification settings - Fork 3
/
45-inject.t
79 lines (56 loc) · 1.63 KB
/
45-inject.t
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
#!perl
use warnings;
use strict;
use Data::Dumper;
use Test::More tests => 10;
use_ok( 'Devel::Examine::Subs' ) || print "Bail out!\n";
use_ok( 'File::Edit::Portable' ) || print "Bail out!\n";
my $file = 't/sample.data';
my $copy = 't/inject.copy';
my @code = <DATA>;
my $des = Devel::Examine::Subs->new (
file => $file,
copy => $copy,
);
my $rw = File::Edit::Portable->new;
{
$des->inject(code => \@code, line_num => 0);
my @c = $rw->read($copy);
is ($c[0], 'one', "inject() inserts at the proper spot with line_num => 0");
eval { unlink $copy; };
is ($@, '', "unlinked copy file $copy ok");
}
{
$des->inject(code => \@code, line_num => 5);
my @c = $rw->read($copy);
is ($c[5], 'one', "inject() inserts at the proper spot with line_num => 5");
eval { unlink $copy; };
is ($@, '', "unlinked copy file $copy ok");
}
{
# inject use
my @code = ('use This::Test;');
$des->inject(inject_use => \@code);
my @c = $rw->read($copy);
is ($c[2], 'use This::Test;', "inject() inserts use statement properly");
eval { unlink $copy; };
is ($@, '', "unlinked copy file $copy ok");
}
{
# inject use
my $copy = 't/inject.debug';
my $des = Devel::Examine::Subs->new(
file => 't/orig/inject.data',
copy => $copy,
);
my @code = ('hello();', "\n", 'there();');
$des->inject(inject_after_sub_def => \@code);
my @c = $rw->read($copy);
is ($c[4], ' hello();', "inject() inserts use statement properly after multi-line sub def");
eval { unlink $copy; };
is ($@, '', "unlinked copy file $copy ok");
}
__DATA__
one
two
three