Hand-applied patch from David Cantrell to add file_offset to allow use of DATA filehandle
[dbsrgits/DBM-Deep.git] / t / 27_filehandle.t
diff --git a/t/27_filehandle.t b/t/27_filehandle.t
new file mode 100644 (file)
index 0000000..6fa65c0
--- /dev/null
@@ -0,0 +1,33 @@
+##
+# DBM::Deep Test
+##
+use strict;
+use Test::More tests => 4;
+
+use DBM::Deep;
+
+open(FILE, "t/27_filehandle.t.db") || die("Can't open t/27_filehandle.t.db\n");
+
+my $db;
+
+# test if we can open and read a db using its filehandle
+
+ok(($db = DBM::Deep->new(fh => *FILE)), "open db in filehandle");
+ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database");
+
+undef $db;
+close(FILE);
+
+# now the same, but with an offset into the file.  Use the database that's
+# embedded in the test for the DATA filehandle.  First, find the database ...
+open(FILE, "t/28_DATA.t") || die("Can't open t/28_DATA.t\n");
+while(my $line = <FILE>) {
+    last if($line =~ /^__DATA__/);
+}
+my $offset = tell(FILE);
+close(FILE);
+
+open(FILE, "t/28_DATA.t");
+ok(($db = DBM::Deep->new(fh => *FILE, file_offset => $offset)), "open db in filehandle with offset");
+ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database");
+