3 # Tests for various caching errors
8 $: = Tie::File::_default_recsep();
9 my $data = join $:, "rec0" .. "rec9", "";
10 my $V = $ENV{INTEGRITY}; # Verbose integrity checking?
16 print "ok $N\n"; $N++;
18 open F, "> $file" or die $!;
23 my $o = tie @a, 'Tie::File', $file;
24 print $o ? "ok $N\n" : "not ok $N\n";
27 # (3) Through 0.18, this 'splice' call would corrupt the cache.
28 my @z = @a; # force cache to contain all ten records
30 print $o->_check_integrity($file, $V) ? "ok $N\n" : "not ok $N\n";
33 # Here we redo *all* the splice tests, with populate()
34 # calls before each one, to make sure that splice() does not botch the cache.
36 # (4-14) splicing at the beginning
38 splice(@a, 0, 0, "rec4");
40 splice(@a, 0, 1, "rec5"); # same length
42 splice(@a, 0, 1, "record5"); # longer
44 splice(@a, 0, 1, "r5"); # shorter
46 splice(@a, 0, 1); # removal
48 splice(@a, 0, 0); # no-op
51 splice(@a, 0, 0, 'r7', 'rec8'); # insert more than one
53 splice(@a, 0, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
55 splice(@a, 0, 3, 'record9', 'rec10'); # delete more than insert
57 splice(@a, 0, 2); # delete more than one
61 # (15-24) splicing in the middle
62 splice(@a, 1, 0, "rec4");
64 splice(@a, 1, 1, "rec5"); # same length
66 splice(@a, 1, 1, "record5"); # longer
68 splice(@a, 1, 1, "r5"); # shorter
70 splice(@a, 1, 1); # removal
72 splice(@a, 1, 0); # no-op
75 splice(@a, 1, 0, 'r7', 'rec8'); # insert more than one
77 splice(@a, 1, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
79 splice(@a, 1, 3, 'record9', 'rec10'); # delete more than insert
81 splice(@a, 1, 2); # delete more than one
84 # (25-34) splicing at the end
85 splice(@a, 3, 0, "rec4");
87 splice(@a, 3, 1, "rec5"); # same length
89 splice(@a, 3, 1, "record5"); # longer
91 splice(@a, 3, 1, "r5"); # shorter
93 splice(@a, 3, 1); # removal
95 splice(@a, 3, 0); # no-op
98 splice(@a, 3, 0, 'r7', 'rec8'); # insert more than one
100 splice(@a, 3, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
102 splice(@a, 3, 3, 'record9', 'rec10'); # delete more than insert
104 splice(@a, 3, 2); # delete more than one
107 # (35-44) splicing with negative subscript
108 splice(@a, -1, 0, "rec4");
110 splice(@a, -1, 1, "rec5"); # same length
112 splice(@a, -1, 1, "record5"); # longer
114 splice(@a, -1, 1, "r5"); # shorter
116 splice(@a, -1, 1); # removal
118 splice(@a, -1, 0); # no-op
121 splice(@a, -1, 0, 'r7', 'rec8'); # insert more than one
123 splice(@a, -1, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
125 splice(@a, -3, 3, 'record9', 'rec10'); # delete more than insert
127 splice(@a, -4, 3); # delete more than one
130 # (45) scrub it all out
134 # (46) put some back in
135 splice(@a, 0, 0, "rec0", "rec1");
138 # (47) what if we remove too many records?
142 # (48-49) In the past, splicing past the end was not correctly detected
149 # (50-51) Also we did not emulate splice's freaky behavior when inserting
150 # past the end of the array (1.14)
151 splice(@a, 89, 0, "I", "like", "pie");
153 splice(@a, 89, 0, "pie pie pie");
156 # (52-54) Test default arguments
157 splice @a, 0, 0, (0..11);
164 # (55) This was broken on 20030507 when you moved the cache management
165 # stuff out of _oadjust back into _splice without also putting it back
172 open F, "> $file" or die $!;
179 my $integrity = $o->_check_integrity($file, $ENV{INTEGRITY});
180 print $integrity ? "ok $N\n" : "not ok $N\n";
195 my @z = @a; # refill the cache with correct data
201 1 while unlink $file;