📄 26_twrite.t
字号:
#!/usr/bin/perl## Unit tests of _twrite function## _twrite($self, $data, $pos, $len)## 't' here is for 'tail'. This writes $data at absolute position $pos# in the file, overwriting exactly $len of the bytes at that position.# Everything else is moved down or up, dependong on whether# length($data) > $len or length($data) < $len.# $len == 0 is a pure insert; $len == length($data) is a simple overwrite.#my $file = "tf$$.txt";print "1..181\n";my $N = 1;use Tie::File;print "ok $N\n"; $N++;$: = Tie::File::_default_recsep();# (2) Peter Scott sent this one. It fails in 0.51 and works in 0.90# <4.3.2.7.2.20020331102819.00b913d0@shell2.webquarry.com>## The problem was premature termination in the inner loop# because you had $more_data scoped *inside* the block instead of outside.# 20020331open F, "> $file" or die "Couldn't open $file: $!";binmode F;for (1..100) { print F "$_ ", 'a'x150, $: ;}close F;# The file is now 15292 characters long on Unix, 15392 on Win32die -s $file unless -s $file == 15292 + 100 * length($:);tie my @lines, 'Tie::File', $file or die $!;push @lines, "1001 ".('a' x 100);splice @lines, 0, 1;untie @lines;my $s = -s $file;my $x = 15292 - 152 + 105 + 100*length($:);print $s == $x ? "ok $N\n" : "not ok $N # expected $x, got $s\n";$N++;my @subtests = qw(x <x x> x><x <x> <x><x x><x> <x><x> <x><x><x> 0);# (3-73) These were generated by 'gentests.pl' to cover all possible cases# (I hope)# Legend:# x: data is entirely contained within one block# x>: data runs from the middle to the end of the block# <x: data runs from the start to the middle of the block# <x>: data occupies precisely one block# x><x: data overlaps one block boundary# <x><x: data runs from the start of one block into the middle of the next# x><x>: data runs from the middle of one block to the end of the next# <x><x>: data occupies two blocks exactly# <x><x><x>: data occupies three blocks exactly# 0: data is null## For each possible alignment of the old and new data, we investigate# up to three situations: old data is shorter, old and new data are the# same length, and new data is shorter.## try($pos, $old, $new) means to run a test where the data starts at # position $pos, the old data has length $old,# and the new data has length $new.try( 9659, 6635, 6691); # old=x , new=x ; old < newtry( 8605, 2394, 2394); # old=x , new=x ; old = newtry( 9768, 1361, 664); # old=x , new=x ; old > newtry( 9955, 6429, 6429); # old=x> , new=x ; old = newtry(10550, 5834, 4123); # old=x> , new=x ; old > newtry(14580, 6158, 851); # old=x><x , new=x ; old > newtry(13442, 11134, 1572); # old=x><x> , new=x ; old > newtry( 8394, 0, 5742); # old=0 , new=x ; old < newtry( 8192, 2819, 6738); # old=<x , new=<x ; old < newtry( 8192, 514, 514); # old=<x , new=<x ; old = newtry( 8192, 2196, 858); # old=<x , new=<x ; old > newtry( 8192, 8192, 8192); # old=<x> , new=<x ; old = newtry( 8192, 8192, 1290); # old=<x> , new=<x ; old > newtry( 8192, 10575, 6644); # old=<x><x , new=<x ; old > newtry( 8192, 16384, 5616); # old=<x><x> , new=<x ; old > newtry( 8192, 24576, 6253); # old=<x><x><x>, new=<x ; old > newtry( 8192, 0, 6870); # old=0 , new=<x ; old < newtry( 8478, 6259, 7906); # old=x , new=x> ; old < newtry( 9965, 6419, 6419); # old=x> , new=x> ; old = newtry(16059, 6102, 325); # old=x><x , new=x> ; old > newtry( 9503, 15073, 6881); # old=x><x> , new=x> ; old > newtry( 9759, 0, 6625); # old=0 , new=x> ; old < newtry( 8525, 2081, 8534); # old=x , new=x><x ; old < newtry(15550, 834, 1428); # old=x> , new=x><x ; old < newtry(14966, 1668, 3479); # old=x><x , new=x><x ; old < newtry(16316, 1605, 1605); # old=x><x , new=x><x ; old = newtry(16093, 4074, 993); # old=x><x , new=x><x ; old > newtry(14739, 9837, 9837); # old=x><x> , new=x><x ; old = newtry(14071, 10505, 7344); # old=x><x> , new=x><x ; old > newtry(12602, 0, 8354); # old=0 , new=x><x ; old < newtry( 8192, 2767, 8192); # old=<x , new=<x> ; old < newtry( 8192, 8192, 8192); # old=<x> , new=<x> ; old = newtry( 8192, 14817, 8192); # old=<x><x , new=<x> ; old > newtry( 8192, 16384, 8192); # old=<x><x> , new=<x> ; old > newtry( 8192, 24576, 8192); # old=<x><x><x>, new=<x> ; old > newtry( 8192, 0, 8192); # old=0 , new=<x> ; old < newtry( 8192, 6532, 10882); # old=<x , new=<x><x ; old < newtry( 8192, 8192, 16044); # old=<x> , new=<x><x ; old < newtry( 8192, 9555, 11020); # old=<x><x , new=<x><x ; old < newtry( 8192, 9001, 9001); # old=<x><x , new=<x><x ; old = newtry( 8192, 11760, 10274); # old=<x><x , new=<x><x ; old > newtry( 8192, 16384, 10781); # old=<x><x> , new=<x><x ; old > newtry( 8192, 24576, 9284); # old=<x><x><x>, new=<x><x ; old > newtry( 8192, 0, 12488); # old=0 , new=<x><x ; old < newtry( 8222, 6385, 16354); # old=x , new=x><x> ; old < newtry(13500, 2884, 11076); # old=x> , new=x><x> ; old < newtry(14069, 4334, 10507); # old=x><x , new=x><x> ; old < newtry(14761, 9815, 9815); # old=x><x> , new=x><x> ; old = newtry(10469, 0, 14107); # old=0 , new=x><x> ; old < newtry( 8192, 4181, 16384); # old=<x , new=<x><x> ; old < newtry( 8192, 8192, 16384); # old=<x> , new=<x><x> ; old < newtry( 8192, 12087, 16384); # old=<x><x , new=<x><x> ; old < newtry( 8192, 16384, 16384); # old=<x><x> , new=<x><x> ; old = newtry( 8192, 24576, 16384); # old=<x><x><x>, new=<x><x> ; old > newtry( 8192, 0, 16384); # old=0 , new=<x><x> ; old < newtry( 8192, 4968, 24576); # old=<x , new=<x><x><x>; old < newtry( 8192, 8192, 24576); # old=<x> , new=<x><x><x>; old < newtry( 8192, 14163, 24576); # old=<x><x , new=<x><x><x>; old < newtry( 8192, 16384, 24576); # old=<x><x> , new=<x><x><x>; old < newtry( 8192, 24576, 24576); # old=<x><x><x>, new=<x><x><x>; old = newtry( 8192, 0, 24576); # old=0 , new=<x><x><x>; old < newtry( 8771, 776, 0); # old=x , new=0 ; old > newtry( 8192, 2813, 0); # old=<x , new=0 ; old > newtry(13945, 2439, 0); # old=x> , new=0 ; old > newtry(14493, 6090, 0); # old=x><x , new=0 ; old > newtry( 8192, 8192, 0); # old=<x> , new=0 ; old > newtry( 8192, 10030, 0); # old=<x><x , new=0 ; old > newtry(14983, 9593, 0); # old=x><x> , new=0 ; old > newtry( 8192, 16384, 0); # old=<x><x> , new=0 ; old > newtry( 8192, 24576, 0); # old=<x><x><x>, new=0 ; old > newtry(10489, 0, 0); # old=0 , new=0 ; old = new# (74-114)# These tests all take place at the start of the filetry( 0, 771, 1593); # old=<x , new=<x ; old < newtry( 0, 4868, 4868); # old=<x , new=<x ; old = newtry( 0, 147, 118); # old=<x , new=<x ; old > newtry( 0, 8192, 8192); # old=<x> , new=<x ; old = newtry( 0, 8192, 4574); # old=<x> , new=<x ; old > newtry( 0, 11891, 1917); # old=<x><x , new=<x ; old > newtry( 0, 16384, 5155); # old=<x><x> , new=<x ; old > newtry( 0, 24576, 2953); # old=<x><x><x>, new=<x ; old > newtry( 0, 0, 1317); # old=0 , new=<x ; old < newtry( 0, 5609, 8192); # old=<x , new=<x> ; old < newtry( 0, 8192, 8192); # old=<x> , new=<x> ; old = newtry( 0, 11083, 8192); # old=<x><x , new=<x> ; old > newtry( 0, 16384, 8192); # old=<x><x> , new=<x> ; old > newtry( 0, 24576, 8192); # old=<x><x><x>, new=<x> ; old > newtry( 0, 0, 8192); # old=0 , new=<x> ; old < newtry( 0, 6265, 9991); # old=<x , new=<x><x ; old < newtry( 0, 8192, 16119); # old=<x> , new=<x><x ; old < newtry( 0, 10218, 11888); # old=<x><x , new=<x><x ; old < newtry( 0, 14126, 14126); # old=<x><x , new=<x><x ; old = newtry( 0, 12002, 9034); # old=<x><x , new=<x><x ; old > newtry( 0, 16384, 13258); # old=<x><x> , new=<x><x ; old > newtry( 0, 24576, 14367); # old=<x><x><x>, new=<x><x ; old > newtry( 0, 0, 10881); # old=0 , new=<x><x ; old < newtry( 0, 6448, 16384); # old=<x , new=<x><x> ; old < newtry( 0, 8192, 16384); # old=<x> , new=<x><x> ; old < newtry( 0, 15082, 16384); # old=<x><x , new=<x><x> ; old < newtry( 0, 16384, 16384); # old=<x><x> , new=<x><x> ; old = newtry( 0, 24576, 16384); # old=<x><x><x>, new=<x><x> ; old > newtry( 0, 0, 16384); # old=0 , new=<x><x> ; old < newtry( 0, 2421, 24576); # old=<x , new=<x><x><x>; old < newtry( 0, 8192, 24576); # old=<x> , new=<x><x><x>; old < newtry( 0, 11655, 24576); # old=<x><x , new=<x><x><x>; old < newtry( 0, 16384, 24576); # old=<x><x> , new=<x><x><x>; old < newtry( 0, 24576, 24576); # old=<x><x><x>, new=<x><x><x>; old = new
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -