summaryrefslogtreecommitdiff
path: root/t/digest.t
diff options
context:
space:
mode:
Diffstat (limited to 't/digest.t')
-rw-r--r--t/digest.t51
1 files changed, 51 insertions, 0 deletions
diff --git a/t/digest.t b/t/digest.t
new file mode 100644
index 0000000..276add6
--- /dev/null
+++ b/t/digest.t
@@ -0,0 +1,51 @@
+use 5.008001;
+use strict;
+use warnings;
+use Test::More 0.96;
+
+use lib 't/lib';
+use TestUtils qw/exception/;
+
+use Path::Tiny;
+use Digest;
+
+my $dir = Path::Tiny->tempdir;
+my $file = $dir->child('foo.bin');
+
+my $chunk = pack( "Z*", "Hello Path::Tiny\nThis is packed binary string\n" );
+ok( $file->spew_raw($chunk), "created test file with packed binary string" );
+
+is(
+ $file->digest,
+ 'a98e605049836e8adb36d351abb95a09e9e5e200703576ecdaec0e697d17d626',
+ 'digest SHA-256 (hardcoded)',
+);
+
+my $sha = Digest->new('SHA-256');
+$sha->add($chunk);
+my $sha_hex = $sha->hexdigest;
+is( $file->digest, $sha_hex, 'digest SHA-256' );
+is( $file->digest( { chunk_size => 10 } ), $sha_hex, 'digest SHA-256 (chunked)' );
+
+is(
+ $file->digest('MD5'),
+ 'ce05aca61c0e58d7396073b668bcafd0',
+ 'digest MD5 (hardcoded)',
+);
+
+my $md5 = Digest->new('MD5');
+$md5->add($chunk);
+my $md5_hex = $md5->hexdigest;
+is( $file->digest('MD5'), $md5_hex, 'digest MD5', );
+is( $file->digest( { chunk_size => 10 }, 'MD5' ), $md5_hex, 'digest MD5 (chunked)' );
+
+done_testing;
+#
+# This file is part of Path-Tiny
+#
+# This software is Copyright (c) 2014 by David Golden.
+#
+# This is free software, licensed under:
+#
+# The Apache License, Version 2.0, January 2004
+#