thread::shared nearly working again - remaining issue
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / 0nothread.t
1 use Test::More tests => 53;
2 use strict;
3
4 my @array;
5 my %hash;
6
7 sub hash
8 {
9  my @val = @_;
10  is(keys %hash, 0, "hash empty");
11  $hash{0} = $val[0];
12  is(keys %hash,1, "Assign grows hash");
13  is($hash{0},$val[0],"Value correct");
14  $hash{2} = $val[2];
15  is(keys %hash,2, "Assign grows hash");
16  is($hash{0},$val[0],"Value correct");
17  is($hash{2},$val[2],"Value correct");
18  $hash{1} = $val[1];
19  is(keys %hash,3,"Size correct");
20  my @keys = keys %hash;
21  is(join(',',sort @keys),'0,1,2',"Keys correct");
22  my @hval = @hash{0,1,2};
23  is(join(',',@hval),join(',',@val),"Values correct");
24  my $val = delete $hash{1};
25  is($val,$val[1],"Delete value correct");
26  is(keys %hash,2,"Size correct");
27  while (my ($k,$v) = each %hash)
28   {
29    is($v,$val[$k],"each works");
30   }
31  %hash = ();
32  is(keys %hash,0,"Clear hash");
33 }
34
35 sub array
36 {
37  my @val = @_;
38  is(@array, 0, "array empty");
39  $array[0] = $val[0];
40  is(@array,1, "Assign grows array");
41  is($array[0],$val[0],"Value correct");
42  unshift(@array,$val[2]);
43  is($array[0],$val[2],"Unshift worked");
44  is($array[-1],$val[0],"-ve index");
45  push(@array,$val[1]);
46  is($array[-1],$val[1],"Push worked");
47  is(@array,3,"Size correct");
48  is(shift(@array),$val[2],"Shift worked");
49  is(@array,2,"Size correct");
50  is(pop(@array),$val[1],"Pop worked");
51  is(@array,1,"Size correct");
52  @array = ();
53  is(@array,0,"Clear array");
54 }
55
56 ok((require threads::shared),"Require module");
57
58 array(24,[],'Thing');
59 hash(24,[],'Thing');
60
61 import threads::shared;
62 share(\@array);
63
64 #SKIP:
65 # {
66 #  skip("Wibble",1);
67 #  ok(0,"No it isn't");
68 # }
69
70 array(24,42,'Thing');
71
72 share(\%hash);
73 hash(24,42,'Thing');
74