[svn:parrot] r42606 - trunk/t/library
mikehh at svn.parrot.org
mikehh at svn.parrot.org
Fri Nov 20 20:01:21 UTC 2009
Author: mikehh
Date: Fri Nov 20 20:01:21 2009
New Revision: 42606
URL: https://trac.parrot.org/parrot/changeset/42606
Log:
convert test to pir - patch from bubaflub++ (TT #1310)
Modified:
trunk/t/library/md5.t
Modified: trunk/t/library/md5.t
==============================================================================
--- trunk/t/library/md5.t Fri Nov 20 19:52:19 2009 (r42605)
+++ trunk/t/library/md5.t Fri Nov 20 20:01:21 2009 (r42606)
@@ -1,13 +1,7 @@
-#!perl
-# Copyright (C) 2001-2005, Parrot Foundation.
+#!parrot
+# Copyright (C) 2001-2009, Parrot Foundation.
# $Id$
-use strict;
-use warnings;
-use lib qw( t . lib ../lib ../../lib );
-use Test::More;
-use Parrot::Test tests => 6;
-
=head1 NAME
t/library/md5.t - test MD5 library
@@ -32,180 +26,51 @@
##############################
# Stress parrot using MD5 library
-pir_output_is( <<'CODE', <<'OUT', "Miscellaneous words" );
-.sub _main
+.sub main :main
+ .include 'test_more.pir'
+ plan(517)
+
+ test_miscellaneous_words()
+ test_funny_chars()
+ test_string_lengths()
+ test_really_long_string()
+ test_recursive_md5_1()
+ test_recursive_md5_2()
+.end
+
+.sub test_miscellaneous_words
+
load_bytecode "Digest/MD5.pbc"
$P0 = _md5sum ("Hello")
- _md5_print ($P0)
- print "\n"
+ $S0 = _md5_hex($P0)
+ is($S0, '8b1a9953c4611296a827abf8c47804d7', 'md5 Hello')
$P0 = _md5sum ("Goodbye")
- _md5_print ($P0)
- print "\n"
+ $S0 = _md5_hex($P0)
+ is($S0, '6fc422233a40a75a1f028e11c3cd1140', 'md5 Goodbye')
$P0 = _md5sum ("Parrot")
- _md5_print ($P0)
- print "\n"
+ $S0 = _md5_hex($P0)
+ is($S0, 'e7cb1e977e896954fec46d2ea7832072', 'md5 Parrot')
$P0 = _md5sum ("Hello World!")
- _md5_print ($P0)
- print "\n"
+ $S0 = _md5_hex($P0)
+ is($S0, 'ed076287532e86365e841e92bfc50d8c', 'md5 Hello World')
- end
.end
-CODE
-8b1a9953c4611296a827abf8c47804d7
-6fc422233a40a75a1f028e11c3cd1140
-e7cb1e977e896954fec46d2ea7832072
-ed076287532e86365e841e92bfc50d8c
-OUT
-pir_output_is( <<'CODE', <<'OUT', "Funny chars" );
-.sub _main
+.sub test_funny_chars
load_bytecode "Digest/MD5.pbc"
$P0 = _md5sum ("\n\n\n\n\t")
- _md5_print ($P0)
- print "\n"
- end
+ $S0 = _md5_hex($P0)
+ is($S0, 'b66434493525523b4393ce0d1f2425d7', 'funny chars')
.end
-CODE
-b66434493525523b4393ce0d1f2425d7
-OUT
-
-my $code = join(
- "\n\n",
- map {
- <<CODE
- \$P0 = _md5sum ("$_")
- _md5_print (\$P0)
- print "\\n"
-CODE
- ;
- } (
- "",
- "0",
- "01",
- "012",
- "0123",
- "01234",
- "012345",
- "0123456",
- "01234567",
- "012345678",
- "0123456789",
- "01234567890",
- "012345678901",
- "0123456789012",
- "01234567890123",
- "012345678901234",
- "0123456789012345",
- "01234567890123456",
- "012345678901234567",
- "0123456789012345678",
- "01234567890123456789",
- "012345678901234567890",
- "0123456789012345678901",
- "01234567890123456789012",
- "012345678901234567890123",
- "0123456789012345678901234",
- "01234567890123456789012345",
- "012345678901234567890123456",
- "0123456789012345678901234567",
- "01234567890123456789012345678",
- "012345678901234567890123456789",
- "0123456789012345678901234567890",
- "01234567890123456789012345678901",
- "012345678901234567890123456789012",
- "0123456789012345678901234567890123",
- "01234567890123456789012345678901234",
- "012345678901234567890123456789012345",
- "0123456789012345678901234567890123456",
- "01234567890123456789012345678901234567",
- "012345678901234567890123456789012345678",
- "0123456789012345678901234567890123456789",
- "01234567890123456789012345678901234567890",
- "012345678901234567890123456789012345678901",
- "0123456789012345678901234567890123456789012",
- "01234567890123456789012345678901234567890123",
- "012345678901234567890123456789012345678901234",
- "0123456789012345678901234567890123456789012345",
- "01234567890123456789012345678901234567890123456",
- "012345678901234567890123456789012345678901234567",
- "0123456789012345678901234567890123456789012345678",
- "01234567890123456789012345678901234567890123456789",
- "012345678901234567890123456789012345678901234567890",
- "0123456789012345678901234567890123456789012345678901",
- "01234567890123456789012345678901234567890123456789012",
- "012345678901234567890123456789012345678901234567890123",
- "0123456789012345678901234567890123456789012345678901234",
- "01234567890123456789012345678901234567890123456789012345",
- "012345678901234567890123456789012345678901234567890123456",
- "0123456789012345678901234567890123456789012345678901234567",
- "01234567890123456789012345678901234567890123456789012345678",
- "012345678901234567890123456789012345678901234567890123456789",
- "0123456789012345678901234567890123456789012345678901234567890",
- "01234567890123456789012345678901234567890123456789012345678901",
- "012345678901234567890123456789012345678901234567890123456789012",
- "0123456789012345678901234567890123456789012345678901234567890123",
- "01234567890123456789012345678901234567890123456789012345678901234",
- "012345678901234567890123456789012345678901234567890123456789012345",
- "0123456789012345678901234567890123456789012345678901234567890123456",
- "01234567890123456789012345678901234567890123456789012345678901234567",
- "012345678901234567890123456789012345678901234567890123456789012345678",
- "0123456789012345678901234567890123456789012345678901234567890123456789",
- "01234567890123456789012345678901234567890123456789012345678901234567890",
- "012345678901234567890123456789012345678901234567890123456789012345678901",
- "0123456789012345678901234567890123456789012345678901234567890123456789012",
- "01234567890123456789012345678901234567890123456789012345678901234567890123",
- "012345678901234567890123456789012345678901234567890123456789012345678901234",
- "0123456789012345678901234567890123456789012345678901234567890123456789012345",
- "01234567890123456789012345678901234567890123456789012345678901234567890123456",
- "012345678901234567890123456789012345678901234567890123456789012345678901234567",
- "0123456789012345678901234567890123456789012345678901234567890123456789012345678",
- "01234567890123456789012345678901234567890123456789012345678901234567890123456789",
- "012345678901234567890123456789012345678901234567890123456789012345678901234567890",
- "0123456789012345678901234567890123456789012345678901234567890123456789012345678901",
- "01234567890123456789012345678901234567890123456789012345678901234567890123456789012",
- "012345678901234567890123456789012345678901234567890123456789012345678901234567890123",
- "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234",
- "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345",
- "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456",
- "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567",
- "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678",
-"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
-"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
-"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
-"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012",
-"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123",
-"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234",
-"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345",
-"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456",
-"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567",
-"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678",
-"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
-"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
-"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
-"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012",
-"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123",
-"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234",
-"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345",
-"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456",
-"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567",
-"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678",
-"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
-"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
- )
-);
-
-pir_output_is( <<CODE, <<'OUT', "String lengths" );
-.sub _main
+.sub test_string_lengths
load_bytecode "Digest/MD5.pbc"
- $code
- end
-.end
-CODE
-d41d8cd98f00b204e9800998ecf8427e
+ $I0 = 0
+
+ $S10 = <<'OUTPUT'
cfcd208495d565ef66e7dff9f98764da
96a3be3cf272e017046d1b2674a52bd3
d2490f048dc3b77a457e3e450ab4eb38
@@ -317,21 +182,32 @@
2468a5c59cccb56bd51ed5ee766b2d2b
09e32555adc12a6f2c8fed9a459935af
6c27622d1d5365e4abfd02f2eccfd8f9
-OUT
-
-my $text = "Hello Parrot World! " x 50_000;
+OUTPUT
+ $P0 = split "\n", $S10
+ testing_loop:
+ $S1 = $I0
+ $S0 .= $S1
+ $S5 = shift $P0
+ $P1 = _md5sum ($S0)
+ $S6 = _md5_hex($P1)
+ inc $I0
+ mod $I0, $I0, 10
+ $I1 = length $S0
+ $S12 = $I1
+ $S11 = 'string length '
+ $S11 .= $S12
+ is($S6, $S5, $S11)
+ if $I1 <= 110 goto testing_loop
+.end
-pir_output_is( <<CODE, <<'OUT', "REALLY long string" );
-.sub _main
+.sub test_really_long_string
load_bytecode "Digest/MD5.pbc"
- \$P0 = _md5sum ("$text")
- _md5_print (\$P0)
- print "\\n"
- end
+ $S0 = "Hello Parrot World! "
+ repeat $S1, $S0, 50000
+ $P0 = _md5sum ($S1)
+ $S2 = _md5_hex($P0)
+ is($S2, '840e4dec51660b1f52473e0b0b9545f5', 'really long string')
.end
-CODE
-840e4dec51660b1f52473e0b0b9545f5
-OUT
=begin bash
@@ -349,26 +225,13 @@
=cut
-pir_output_is( <<'CODE', <<'OUT', "recursive md5sum (1)" );
-.sub _main
+.sub test_recursive_md5_1
load_bytecode "Digest/MD5.pbc"
-
+ .local string output
$S0 = "Hello World!"
$I0 = 0
-loop:
- print $S0
- print "\n"
- if $I0 >= 200 goto end
- $P0 = _md5sum($S0)
- $S0 = _md5_hex($P0)
- inc $I0
- branch loop
-end:
- end
-.end
-CODE
-Hello World!
+ output = <<'OUTPUT'
ed076287532e86365e841e92bfc50d8c
153163e20c7dd03b131fe2bf21927e1e
95b9b73c7a8abe6d5bf5ad8067a53cee
@@ -569,7 +432,20 @@
b63d8a186e272754b70953ddd441e9fd
84a112f819bf780dd268c68f21238374
eab26f6455a08779bcb43bc48c02c717
-OUT
+OUTPUT
+
+ $P1 = split "\n", output
+ loop:
+ if $I0 >= 200 goto end
+ $P0 = _md5sum($S0)
+ $S0 = _md5_hex($P0)
+ $S1 = shift $P1
+ is($S0, $S1, 'recursive md5 (1)')
+ inc $I0
+ branch loop
+ end:
+
+.end
=begin bash
@@ -587,28 +463,13 @@
=cut
-pir_output_is( <<'CODE', <<'OUT', "recursive md5sum (2)" );
-.sub _main
+.sub test_recursive_md5_2
load_bytecode "Digest/MD5.pbc"
-
+ .local string output
+ .local pmc output_array
$S0 = "Hello World!"
$I0 = 0
-
-loop:
- print $S0
- print "\n"
- if $I0 >= 200 goto end
- $S0 = clone $S0
- $S0 = concat $S0, $S0
- $P0 = _md5sum($S0)
- $S0 = _md5_hex($P0)
- inc $I0
- branch loop
-end:
- end
-.end
-CODE
-Hello World!
+ output = <<'OUTPUT'
ee41c968530f7715ab70805b341c3956
9548194ce84b2f7953386080da112c3a
9fb892cc0766429a1d8b0f752636c0fa
@@ -809,11 +670,26 @@
982d93d2437c46edbf99f542900231c0
8408bf5f0144309374e66278bec290b2
982e0fde28cd2f62ef8db2d8dfd0f0d7
-OUT
+OUTPUT
+
+ output_array = split "\n", output
+ loop:
+ if $I0 >= 200 goto end
+ $S0 = clone $S0
+ $S0 = concat $S0, $S0
+ $P0 = _md5sum($S0)
+ $S0 = _md5_hex($P0)
+ $S1 = shift output_array
+ is($S0, $S1, 'recursive md5 (2)')
+ inc $I0
+ branch loop
+ end:
+
+.end
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
-# vim: expandtab shiftwidth=4:
+# vim: expandtab shiftwidth=4 filetype=pir:
More information about the parrot-commits
mailing list