Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
79072805 | 3 | # $RCSfile: each.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:47 $ |
8d063cd8 | 4 | |
c6aa4a32 | 5 | print "1..16\n"; |
8d063cd8 LW |
6 | |
7 | $h{'abc'} = 'ABC'; | |
8 | $h{'def'} = 'DEF'; | |
a687059c LW |
9 | $h{'jkl','mno'} = "JKL\034MNO"; |
10 | $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5); | |
8d063cd8 LW |
11 | $h{'a'} = 'A'; |
12 | $h{'b'} = 'B'; | |
13 | $h{'c'} = 'C'; | |
14 | $h{'d'} = 'D'; | |
15 | $h{'e'} = 'E'; | |
16 | $h{'f'} = 'F'; | |
17 | $h{'g'} = 'G'; | |
18 | $h{'h'} = 'H'; | |
19 | $h{'i'} = 'I'; | |
20 | $h{'j'} = 'J'; | |
21 | $h{'k'} = 'K'; | |
22 | $h{'l'} = 'L'; | |
23 | $h{'m'} = 'M'; | |
24 | $h{'n'} = 'N'; | |
25 | $h{'o'} = 'O'; | |
26 | $h{'p'} = 'P'; | |
27 | $h{'q'} = 'Q'; | |
28 | $h{'r'} = 'R'; | |
29 | $h{'s'} = 'S'; | |
30 | $h{'t'} = 'T'; | |
31 | $h{'u'} = 'U'; | |
32 | $h{'v'} = 'V'; | |
33 | $h{'w'} = 'W'; | |
34 | $h{'x'} = 'X'; | |
35 | $h{'y'} = 'Y'; | |
36 | $h{'z'} = 'Z'; | |
37 | ||
a687059c LW |
38 | @keys = keys %h; |
39 | @values = values %h; | |
8d063cd8 LW |
40 | |
41 | if ($#keys == 29 && $#values == 29) {print "ok 1\n";} else {print "not ok 1\n";} | |
42 | ||
75039078 | 43 | $i = 0; # stop -w complaints |
44 | ||
45 | while (($key,$value) = each(%h)) { | |
9d116dd7 JH |
46 | if ($key eq $keys[$i] && $value eq $values[$i] |
47 | && (('a' lt 'A' && $key lt $value) || $key gt $value)) { | |
8d063cd8 LW |
48 | $key =~ y/a-z/A-Z/; |
49 | $i++ if $key eq $value; | |
50 | } | |
51 | } | |
52 | ||
53 | if ($i == 30) {print "ok 2\n";} else {print "not ok 2\n";} | |
378cc40b | 54 | |
a687059c | 55 | @keys = ('blurfl', keys(%h), 'dyick'); |
378cc40b | 56 | if ($#keys == 31) {print "ok 3\n";} else {print "not ok 3\n";} |
75039078 | 57 | |
58 | $size = ((split('/',scalar %h))[1]); | |
59 | keys %h = $size * 5; | |
60 | $newsize = ((split('/',scalar %h))[1]); | |
61 | if ($newsize == $size * 8) {print "ok 4\n";} else {print "not ok 4\n";} | |
62 | keys %h = 1; | |
63 | $size = ((split('/',scalar %h))[1]); | |
64 | if ($size == $newsize) {print "ok 5\n";} else {print "not ok 5\n";} | |
65 | %h = (1,1); | |
66 | $size = ((split('/',scalar %h))[1]); | |
67 | if ($size == $newsize) {print "ok 6\n";} else {print "not ok 6\n";} | |
68 | undef %h; | |
69 | %h = (1,1); | |
70 | $size = ((split('/',scalar %h))[1]); | |
71 | if ($size == 8) {print "ok 7\n";} else {print "not ok 7\n";} | |
3524d3b9 TP |
72 | |
73 | # test scalar each | |
74 | %hash = 1..20; | |
75 | $total = 0; | |
76 | $total += $key while $key = each %hash; | |
77 | print "# Scalar each is bad.\nnot " unless $total == 100; | |
78 | print "ok 8\n"; | |
79 | ||
80 | for (1..3) { @foo = each %hash } | |
81 | keys %hash; | |
82 | $total = 0; | |
83 | $total += $key while $key = each %hash; | |
84 | print "# Scalar keys isn't resetting the iterator.\nnot " if $total != 100; | |
85 | print "ok 9\n"; | |
86 | ||
87 | for (1..3) { @foo = each %hash } | |
88 | $total = 0; | |
89 | $total += $key while $key = each %hash; | |
90 | print "# Iterator of each isn't being maintained.\nnot " if $total == 100; | |
91 | print "ok 10\n"; | |
92 | ||
93 | for (1..3) { @foo = each %hash } | |
94 | values %hash; | |
95 | $total = 0; | |
96 | $total += $key while $key = each %hash; | |
97 | print "# Scalar values isn't resetting the iterator.\nnot " if $total != 100; | |
98 | print "ok 11\n"; | |
99 | ||
100 | $size = (split('/', scalar %hash))[1]; | |
101 | keys(%hash) = $size / 2; | |
102 | print "not " if $size != (split('/', scalar %hash))[1]; | |
103 | print "ok 12\n"; | |
104 | keys(%hash) = $size + 100; | |
105 | print "not " if $size == (split('/', scalar %hash))[1]; | |
106 | print "ok 13\n"; | |
107 | ||
108 | print "not " if keys(%hash) != 10; | |
109 | print "ok 14\n"; | |
110 | ||
c6aa4a32 SP |
111 | print keys(hash) != 10 ? "not ok 15\n" : "ok 15\n"; |
112 | ||
113 | $i = 0; | |
114 | %h = (a => A, b => B, c=> C, d => D, abc => ABC); | |
115 | @keys = keys(h); | |
116 | @values = values(h); | |
117 | while (($key, $value) = each(h)) { | |
118 | if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) { | |
119 | $i++; | |
120 | } | |
121 | } | |
122 | if ($i == 5) { print "ok 16\n" } else { print "not ok\n" } |