Upgrade to Tie::File 0.16.
[p5sagit/p5-mst-13.2.git] / lib / Tie / File / t / 17_misc_meth.t
CommitLineData
fa408a35 1#!/usr/bin/perl
2#
3# Check miscellaneous tied-array interface methods
4# EXTEND, CLEAR, DELETE, EXISTS
5#
6
7use lib '/home/mjd/src/perl/Tie-File2/lib';
8my $file = "tf$$.txt";
91 while unlink $file;
10
11print "1..24\n";
12
13my $N = 1;
14use Tie::File;
15print "ok $N\n"; $N++;
16
17my $o = tie @a, 'Tie::File', $file;
18print $o ? "ok $N\n" : "not ok $N\n";
19$N++;
20
21# (3-8) EXTEND
22$o->EXTEND(3);
23check_contents("$/$/$/");
24$o->EXTEND(4);
25check_contents("$/$/$/$/");
26$o->EXTEND(3);
27check_contents("$/$/$/$/");
28
29# (9-10) CLEAR
30@a = ();
31check_contents("");
32
33# (11-16) EXISTS
34print !exists $a[0] ? "ok $N\n" : "not ok $N\n";
35$N++;
36$a[0] = "I like pie.";
37print exists $a[0] ? "ok $N\n" : "not ok $N\n";
38$N++;
39print !exists $a[1] ? "ok $N\n" : "not ok $N\n";
40$N++;
41$a[2] = "GIVE ME PIE";
42print exists $a[0] ? "ok $N\n" : "not ok $N\n";
43$N++;
44# exists $a[1] is not defined by this module under these circumstances
45print exists $a[1] ? "ok $N\n" : "ok $N\n";
46$N++;
47print exists $a[2] ? "ok $N\n" : "not ok $N\n";
48$N++;
49
50# (17-24) DELETE
51delete $a[0];
52check_contents("$/$/GIVE ME PIE$/");
53delete $a[2];
54check_contents("$/$/");
55delete $a[0];
56check_contents("$/$/");
57delete $a[1];
58check_contents("$/");
59
60
61use POSIX 'SEEK_SET';
62sub check_contents {
63 my $x = shift;
64 local *FH = $o->{fh};
65 seek FH, 0, SEEK_SET;
66 my $a;
67 { local $/; $a = <FH> }
68 $a = "" unless defined $a;
69 if ($a eq $x) {
70 print "ok $N\n";
71 } else {
72 s{$/}{\\n}g for $a, $x;
73 print "not ok $N\n# expected <$x>, got <$a>\n";
74 }
75 $N++;
76 print $o->_check_integrity($file, $ENV{INTEGRITY}) ? "ok $N\n" : "not ok $N\n";
77 $N++;
78}
79
80END {
81 undef $o;
82 untie @a;
83 1 while unlink $file;
84}
85
86