Commit | Line | Data |
---|---|---|
6b85e4fe | 1 | use strict; |
13c1b207 | 2 | use warnings; |
5f64702c | 3 | use Config; |
38506751 NIS |
4 | BEGIN { |
5 | require Test::More; | |
6 | if ($Config{'useithreads'}) { | |
7 | Test::More->import( tests => 53 ); | |
8 | } | |
9 | else { | |
10 | Test::More->import(skip_all => "no useithreads"); | |
11 | } | |
5f64702c NIS |
12 | } |
13 | ||
6b85e4fe NIS |
14 | |
15 | my @array; | |
16 | my %hash; | |
17 | ||
18 | sub hash | |
19 | { | |
20 | my @val = @_; | |
21 | is(keys %hash, 0, "hash empty"); | |
22 | $hash{0} = $val[0]; | |
23 | is(keys %hash,1, "Assign grows hash"); | |
24 | is($hash{0},$val[0],"Value correct"); | |
25 | $hash{2} = $val[2]; | |
26 | is(keys %hash,2, "Assign grows hash"); | |
27 | is($hash{0},$val[0],"Value correct"); | |
28 | is($hash{2},$val[2],"Value correct"); | |
29 | $hash{1} = $val[1]; | |
30 | is(keys %hash,3,"Size correct"); | |
31 | my @keys = keys %hash; | |
32 | is(join(',',sort @keys),'0,1,2',"Keys correct"); | |
33 | my @hval = @hash{0,1,2}; | |
34 | is(join(',',@hval),join(',',@val),"Values correct"); | |
35 | my $val = delete $hash{1}; | |
36 | is($val,$val[1],"Delete value correct"); | |
37 | is(keys %hash,2,"Size correct"); | |
38 | while (my ($k,$v) = each %hash) | |
39 | { | |
40 | is($v,$val[$k],"each works"); | |
41 | } | |
42 | %hash = (); | |
43 | is(keys %hash,0,"Clear hash"); | |
44 | } | |
45 | ||
46 | sub array | |
47 | { | |
48 | my @val = @_; | |
49 | is(@array, 0, "array empty"); | |
50 | $array[0] = $val[0]; | |
51 | is(@array,1, "Assign grows array"); | |
52 | is($array[0],$val[0],"Value correct"); | |
53 | unshift(@array,$val[2]); | |
54 | is($array[0],$val[2],"Unshift worked"); | |
55 | is($array[-1],$val[0],"-ve index"); | |
56 | push(@array,$val[1]); | |
57 | is($array[-1],$val[1],"Push worked"); | |
58 | is(@array,3,"Size correct"); | |
59 | is(shift(@array),$val[2],"Shift worked"); | |
60 | is(@array,2,"Size correct"); | |
61 | is(pop(@array),$val[1],"Pop worked"); | |
62 | is(@array,1,"Size correct"); | |
63 | @array = (); | |
64 | is(@array,0,"Clear array"); | |
65 | } | |
66 | ||
67 | ok((require threads::shared),"Require module"); | |
68 | ||
69 | array(24,[],'Thing'); | |
70 | hash(24,[],'Thing'); | |
71 | ||
5f64702c | 72 | |
6b85e4fe NIS |
73 | import threads::shared; |
74 | share(\@array); | |
75 | ||
76 | #SKIP: | |
77 | # { | |
78 | # skip("Wibble",1); | |
79 | # ok(0,"No it isn't"); | |
80 | # } | |
81 | ||
82 | array(24,42,'Thing'); | |
83 | ||
84 | share(\%hash); | |
85 | hash(24,42,'Thing'); | |
86 |