File: globtest.t

package info (click to toggle)
libdata-dump-streamer-perl 2.08-40-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 408 kB
  • ctags: 101
  • sloc: perl: 2,669; makefile: 51
file content (289 lines) | stat: -rwxr-xr-x 7,721 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
use Test::More tests=>19;

#$Id: globtest.t 26 2006-04-16 15:18:52Z demerphq $#

BEGIN { use_ok( 'Data::Dump::Streamer', qw(regex Dump alias_av alias_hv) ); }
use strict;
use warnings;
use Data::Dumper;

# imports same()
(my $helper=$0)=~s/\w+\.\w+$/test_helper.pl/;
require $helper;
# use this one for simple, non evalable tests. (GLOB)
#   same ( $got,$expected,$name,$obj )
#
# use this one for eval checks and dumper checks but NOT for GLOB's
# same ( $name,$obj,$expected,@args )


my $o = Data::Dump::Streamer->new();

isa_ok( $o, 'Data::Dump::Streamer' );

{
	no strict;
	# no. 3 - a glob
	{
		local *g;
		same( scalar $o->Data(*g)->Out, <<'EXPECT', "a glob", $o );
$VAR1 = *::g;
EXPECT
	}

	# no. 4 - scalar slot
	{
		local *g = \"a string";
		## XXX: the empty globs are an icky 5.8.0 bug
		$^V lt v5.8 ?
		same( scalar $o->Data(*g)->Out, <<'EXPECT', "scalar slot", $o )
$VAR1 = *::g;
*::g = \'a string';
EXPECT
		:
		same( scalar $o->Data(*g)->Out, <<'EXPECT', "scalar slot", $o )
$VAR1 = *::g;
*::g = \'a string';
*::g = {};
*::g = [];
EXPECT
		;
	}

	# no. 5 - data slots
	{
		local *g;
		$g = 'a string';
		@g = qw/a list/;
		%g = qw/a hash/;
		our ($off,$width,$bits,$val,$res);
		($off,$width,$bits,$val,$res)=($off,$width,$bits,$val,$res);
		eval'
		format g =
vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$off, $width, $bits, $val, $res
vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$off, $width, $bits, $val, $res
.
';
		same( scalar $o->Data(*g)->Out, <<'EXPECT', "data slots (glob/FORMAT)", $o );
$VAR1 = *::g;
*::g = \do { my $v = 'a string' };
*::g = { a => 'hash' };
*::g = [
         'a',
         'list'
       ];
format g =
vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$off, $width, $bits, $val, $res
vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$off, $width, $bits, $val, $res
.
EXPECT
                SKIP: {
                    skip "no FORMAT refs before ".vstr(5,7)." and this is ".vstr(),
                         my $NUM=3
                       unless  5.008 <= $];

		same( scalar $o->Data(*g{FORMAT})->Out, <<'EXPECT', "data slots (ref/FORMAT)", $o );
$FORMAT1 = do{ local *F; my $F=<<'_EOF_FORMAT_'; $F=~s/^\s+# //mg; eval $F; die $F.$@ if $@; *F{FORMAT};
           # format F =
           # vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
           # $off, $width, $bits, $val, $res
           # vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
           # $off, $width, $bits, $val, $res
           # .
_EOF_FORMAT_
           };
EXPECT
                my $y=bless *g{FORMAT},"Thank::YSTH";
                #same ( scalar $o->Data(*g{FORMAT})->Out, <<'EXPECT', "data slots (blessed FORMAT)", $o );
		test_dump( {name=>"data slots (blessed FORMAT)",
		            verbose=>1,
		            pre_eval=>'our ($off,$width,$bits,$val,$res);',
		            no_dumper=>1
		            },
		             $o, *g{FORMAT}, <<'EXPECT'  );
$Thank_YSTH1 = bless( do{ local *F; my $F=<<'_EOF_FORMAT_'; $F=~s/^\s+# //mg; eval $F; die $F.$@ if $@; *F{FORMAT};
               # format F =
               # vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
               # $off, $width, $bits, $val, $res
               # vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
               # $off, $width, $bits, $val, $res
               # .
_EOF_FORMAT_
               }, 'Thank::YSTH' );
EXPECT
    our $gg=1; #silence a warning;
		same( scalar $o->Data(*gg{FORMAT})->Out, <<'EXPECT', "data slots (empty FORMAT)", $o );
$VAR1 = undef;
EXPECT
                };
	}

	# no. 6 - self glob
	{
		local *g;
		$g = *g{SCALAR};
		same( scalar $o->Data(*g)->Out, <<'EXPECT', "self glob", $o );
$VAR1 = *::g;
*::g = \do { my $v = 'V: *::g{SCALAR}' };
${*::g} = *::g{SCALAR};
EXPECT
	}

	# no. 7 - icky readonly scalars
	{
		local(*g, $s);
		*g = \"cannae be modified";
		$s = "do as you please";

		same( scalar $o->Data($g,$s)->Out, <<'EXPECT', "icky SCALAR slot", $o );
$RO1 = 'cannae be modified';
make_ro($RO1);
$VAR1 = 'do as you please';
EXPECT
	}
}
{
    #local $Data::Dump::Streamer::DEBUG=1;
    our $foo = 5;
    our @foo = (-10,\*foo);
    our %foo = (a=>1,b=>\$foo,c=>\@foo);
    $foo{d} = \%foo;
    $foo[2] = \%foo;
    same( "Named Globs", $o->Declare(0)->Names('*foo', '*bar', '*baz'), <<'EXPECT', ( \\*foo, \\@foo, \\%foo ) );
$foo = \\*::foo;
*::foo = \do { my $v = 5 };
$bar = \[
         -10,
         $$foo,
         'V: $$baz'
       ];
*::foo = $$bar;
$baz = \{
         a => 1,
         b => *::foo{SCALAR},
         c => $$bar,
         d => 'V: $$baz'
       };
*::foo = $$baz;
${$bar}->[2] = $$baz;
${$baz}->{d} = $$baz;
EXPECT
    same( "Named Globs Two", $o->Names('foo', 'bar', 'baz'), <<'EXPECT', ( \\*foo, \\@foo, \\%foo ) );
$foo = \\*::foo;
*::foo = \do { my $v = 5 };
$bar = \[
         -10,
         $$foo,
         'V: $$baz'
       ];
*::foo = $$bar;
$baz = \{
         a => 1,
         b => *::foo{SCALAR},
         c => $$bar,
         d => 'V: $$baz'
       };
*::foo = $$baz;
${$bar}->[2] = $$baz;
${$baz}->{d} = $$baz;
EXPECT
    same( "Named Globs Declare", $o->Declare(1)->Names('*foo', '*bar', '*baz'), <<'EXPECT', ( \\*foo, \\@foo, \\%foo ) );
my $foo = \\*::foo;
*::foo = \do { my $v = 5 };
my $bar = \[
            -10,
            $$foo,
            'V: $$baz'
          ];
*::foo = $$bar;
my $baz = \{
            a => 1,
            b => *::foo{SCALAR},
            c => $$bar,
            d => 'V: $$baz'
          };
*::foo = $$baz;
${$bar}->[2] = $$baz;
${$baz}->{d} = $$baz;
EXPECT
    same( "Named Globs Two Declare", $o->Names('foo', 'bar', 'baz'), <<'EXPECT', ( \\*foo, \\@foo, \\%foo ) );
my $foo = \\*::foo;
*::foo = \do { my $v = 5 };
my $bar = \[
            -10,
            $$foo,
            'V: $$baz'
          ];
*::foo = $$bar;
my $baz = \{
            a => 1,
            b => *::foo{SCALAR},
            c => $$bar,
            d => 'V: $$baz'
          };
*::foo = $$baz;
${$bar}->[2] = $$baz;
${$baz}->{d} = $$baz;
EXPECT
}
# with eval testing
{

    use Symbol;
    my $x=gensym;
    my $names=$o->Names(); # scalar context
    same( scalar $o->Data($x)->Out(),<<'EXPECT', "Symbol 1", $o );
my $foo = do{ require Symbol; Symbol::gensym };
EXPECT
    my @names=$o->Names(); # scalar context
    same( scalar $o->Data($x)->Out(),<<'EXPECT', "Symbol 2", $o );
my $foo = do{ require Symbol; Symbol::gensym };
EXPECT
    $o->Names();
    same( scalar $o->Data($x)->Out(),<<'EXPECT', "Symbol 3", $o );
my $GLOB1 = do{ require Symbol; Symbol::gensym };
EXPECT

    #local $Data::Dump::Streamer::DEBUG=1;

    $x=\gensym; #
    *$$x = $x;
    *$$x = $names;
    *$$x = { Thank => '[ysth]', Grr => bless \gensym,'Foo' };
    #Devel::Peek::Dump $x

    same( scalar $o->Data( $x )->Out(),<<'EXPECT', "Symbol 4", $o );
my $REF1 = \do{ require Symbol; Symbol::gensym };
*$$REF1 = {
            Grr   => bless( \Symbol::gensym, 'Foo' ),
            Thank => '[ysth]'
          };
*$$REF1 = [
            'foo',
            'bar',
            'baz'
          ];
*$$REF1 = $REF1;
EXPECT

}
{
    same( my $dump=$o->Data(*{gensym()})->Out, <<'EXPECT', "Symbol 5", $o );
my $VAR1 = *{ do{ require Symbol; Symbol::gensym } };
EXPECT
}
__END__
# with eval testing
{
    same( "", $o, <<'EXPECT', (  ) );
EXPECT
}
# without eval testing
{
    same( $dump = $o->Data()->Out, <<'EXPECT', "", $o );
EXPECT
}