Re: [ PATCH ] module test fest
[p5sagit/p5-mst-13.2.git] / ext / B / t / asmdata.t
1 #!./perl -Tw
2
3 BEGIN {
4     chdir 't';
5     @INC = '../lib';
6 }
7
8 use Test::More tests => 13;
9
10 use_ok('B::Asmdata', qw(%insn_data @insn_name @optype @specialsv_name));
11
12 # check we got something.
13 isnt( keys %insn_data,  0,  '%insn_data exported and populated' );
14 isnt( @insn_name,       0,  '   @insn_name' );
15 isnt( @optype,          0,  '   @optype' );
16 isnt( @specialsv_name,  0,  '   @specialsv_name' );
17
18 # pick an op that's not likely to go away in the future
19 my @data = values %insn_data;
20 is( (grep { ref eq 'ARRAY' } @data),  @data,   '%insn_data contains arrays' );
21
22 # pick one at random to test with.
23 my $opname = (keys %insn_data)[rand @data];
24 my $data = $insn_data{$opname};
25 like( $data->[0], qr/^\d+$/,    '   op number' );
26 is( ref $data->[1],  'CODE',    '   PUT code ref' );
27 ok( !ref $data->[2],            '   GET method' );
28
29 is( $insn_name[$data->[0]], $opname,    '@insn_name maps correctly' );
30
31
32 # I'm going to assume that op types will all be named /OP$/.
33 # If this changes in the future, change this test.
34 is( grep(/OP$/, @optype), @optype,  '@optype is all /OP$/' );
35
36
37 # comment in bytecode.pl says "Nullsv *must come first so that the 
38 # condition ($$sv == 0) can continue to be used to test (sv == Nullsv)."
39 is( $specialsv_name[0],  'Nullsv',  'Nullsv come first in @special_sv_name' );
40
41 # other than that, we can't really say much more about @specialsv_name
42 # than it has to contain strings (on the off chance &PL_sv_undef gets 
43 # flubbed)
44 is( grep(!ref, @specialsv_name), @specialsv_name,   '  contains all strings' );