File: xs_subs.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 (123 lines) | stat: -rwxr-xr-x 3,893 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

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

use vars qw/$XTRA/;
use Test::More tests=>10+($XTRA=26);

BEGIN {
    use_ok( 'Data::Dump::Streamer', qw(
        Dump readonly hidden_keys legal_keys lock_keys lock_ref_keys
        lock_keys_plus lock_ref_keys_plus ));
}

# from Scalar::Util readonly.t

ok(readonly(1),'readonly(1)');

my $var = 2;
ok(!readonly($var),'$var = 2; readonly($var)');
ok($var == 2,'$var==2');


ok(readonly("fred"),'readonly("fred")');

$var = "fred";
ok(!readonly($var),'$var = fred; readonly($var)');
ok($var eq "fred",'$var eq "fred"');

$var = \2;
ok(!readonly($var),'$var=\2; readonly($var)');
ok(readonly($$var),'readonly($$var)');
ok(!readonly(*STDOUT),'readonly(*STDOUT)');

# new
SKIP:{
    skip "No locked key semantics before 5.8.0",
        $XTRA
        if $]<5.008;
{
    my %hash=map { $_ => 1 } qw( a b c d e f);
    delete $hash{c};
    lock_keys(%hash);
    ok(Internals::SvREADONLY(%hash),'lock_keys');
    
    # we do this skip here just to make sure lock_keys is correctly setup.
    skip "Cant tell if a key is locked in 5.8.0",
        $XTRA - 1
        if $]==5.008;        
    
    delete @hash{qw(b e)};
    my @hidden=sort(hidden_keys(%hash));
    my @legal=sort(legal_keys(%hash));
    my @keys=sort(keys(%hash));
    #warn "@legal\n@keys\n";
    is("@hidden","b e",'lock_keys @hidden');
    is("@legal","a b d e f",'lock_keys @legal');
    is("@keys","a d f",'lock_keys @keys');
}
{
    my %hash=(0..9);
    lock_keys(%hash);
    ok(Internals::SvREADONLY(%hash),'lock_keys');
    Hash::Util::unlock_keys(%hash);
    ok(!Internals::SvREADONLY(%hash),'unlock_keys');
}
{
    my %hash=(0..9);
    lock_keys(%hash,keys(%hash),'a'..'f');
    ok(Internals::SvREADONLY(%hash),'lock_keys args');
    my @hidden=sort(hidden_keys(%hash));
    my @legal=sort(legal_keys(%hash));
    my @keys=sort(keys(%hash));
    is("@hidden","a b c d e f",'lock_keys() @hidden');
    is("@legal","0 2 4 6 8 a b c d e f",'lock_keys() @legal');
    is("@keys","0 2 4 6 8",'lock_keys() @keys');
}
{
    my %hash=map { $_ => 1 } qw( a b c d e f);
    delete $hash{c};
    lock_ref_keys(\%hash);
    ok(Internals::SvREADONLY(%hash),'lock_ref_keys');
    delete @hash{qw(b e)};
    my @hidden=sort(hidden_keys(%hash));
    my @legal=sort(legal_keys(%hash));
    my @keys=sort(keys(%hash));
    #warn "@legal\n@keys\n";
    is("@hidden","b e",'lock_ref_keys @hidden');
    is("@legal","a b d e f",'lock_ref_keys @legal');
    is("@keys","a d f",'lock_ref_keys @keys');
}
{
    my %hash=(0..9);
    lock_ref_keys(\%hash,keys %hash,'a'..'f');
    ok(Internals::SvREADONLY(%hash),'lock_ref_keys args');
    my @hidden=sort(hidden_keys(%hash));
    my @legal=sort(legal_keys(%hash));
    my @keys=sort(keys(%hash));
    is("@hidden","a b c d e f",'lock_ref_keys() @hidden');
    is("@legal","0 2 4 6 8 a b c d e f",'lock_ref_keys() @legal');
    is("@keys","0 2 4 6 8",'lock_ref_keys() @keys');
}
{
    my %hash=(0..9);
    lock_ref_keys_plus(\%hash,'a'..'f');
    ok(Internals::SvREADONLY(%hash),'lock_ref_keys args');
    my @hidden=sort(hidden_keys(%hash));
    my @legal=sort(legal_keys(%hash));
    my @keys=sort(keys(%hash));
    is("@hidden","a b c d e f",'lock_ref_keys_plus() @hidden');
    is("@legal","0 2 4 6 8 a b c d e f",'lock_ref_keys_plus() @legal');
    is("@keys","0 2 4 6 8",'lock_ref_keys_plus() @keys');
}
{
    my %hash=(0..9);
    lock_keys_plus(%hash,'a'..'f');
    ok(Internals::SvREADONLY(%hash),'lock_keys args');
    my @hidden=sort(hidden_keys(%hash));
    my @legal=sort(legal_keys(%hash));
    my @keys=sort(keys(%hash));
    is("@hidden","a b c d e f",'lock_keys_plus() @hidden');
    is("@legal","0 2 4 6 8 a b c d e f",'lock_keys_plus() @legal');
    is("@keys","0 2 4 6 8",'lock_keys_plus() @keys');
}
}