Author: bernhard
Date: Tue Nov  8 13:27:24 2005
New Revision: 9852

Added:
   trunk/examples/pir/uniq.pir
      - copied, changed from r9849, trunk/examples/assembly/uniq.pasm
Removed:
   trunk/examples/assembly/uniq.pasm
Modified:
   trunk/MANIFEST
   trunk/t/examples/pir.t
Log:
Convert the example 'uniq.pasm' to PIR baby talk,
move it to examples/pir/uniq.pir and add a test.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Tue Nov  8 13:27:24 2005
@@ -458,7 +458,6 @@ examples/assembly/pmcmops.pasm          
 examples/assembly/queens.pasm                     [main]doc
 examples/assembly/queens_r.imc                    [main]doc
 examples/assembly/thr-primes.imc                  [main]doc
-examples/assembly/uniq.pasm                       [main]doc
 examples/benchmarks/addit.imc                     [main]doc
 examples/benchmarks/addit.pasm                    [main]doc
 examples/benchmarks/addit.pl                      [main]doc
@@ -608,6 +607,7 @@ examples/pir/mandel.pir                 
 examples/pir/readline.pir                         [main]doc
 examples/pir/substr.pir                           [main]doc
 examples/pir/sudoku.pir                           [main]doc
+examples/pir/uniq.pir                             [main]doc
 examples/pni/PQt.C                                [main]doc
 examples/pni/QtHelloWorld.pasm                    [main]doc
 examples/pni/ls.pir                               [main]doc

Copied: trunk/examples/pir/uniq.pir (from r9849, 
trunk/examples/assembly/uniq.pasm)
==============================================================================
--- trunk/examples/assembly/uniq.pasm   (original)
+++ trunk/examples/pir/uniq.pir Tue Nov  8 13:27:24 2005
@@ -3,11 +3,11 @@
 
 =head1 NAME
 
-examples/assembly/uniq.pasm - Remove duplicate lines from a sorted file
+examples/pir/uniq.pir - Remove duplicate lines from a sorted file
 
 =head1 SYNOPSIS
 
-    % ./parrot uniq.pasm -o uniq.pbc
+    % ./parrot uniq.pir -o uniq.pbc
     % ./parrot uniq.pbc data.txt
     % ./parrot uniq.pbc -c data.txt
 
@@ -35,10 +35,19 @@ Don't output lines that are repeated in 
 
 =back
 
+=head1 HISTORY
+
+By Leon Brocard <[EMAIL PROTECTED]>.
+
+Converted to PIR by Bernhard Schmalhofer.
+
 =cut
 
-  set I0, P5
-  shift S0, P5
+.sub "uniq" :main
+  .param pmc argv
+
+  set I0, argv
+  shift S0, argv
   ne I0, 1, SOURCE
   print "usage: parrot "
   print S0
@@ -47,21 +56,21 @@ Don't output lines that are repeated in 
 
 SOURCE:
   # do some simple option parsing
-  shift S0, P5
+  shift S0, argv
 
   ne S0, "-c", NOTC
   set I10, 1 # count mode
-  shift S0, P5
+  shift S0, argv
 
 NOTC:
   ne S0, "-d", NOTD
   set I11, 1 # duplicate mode
-  shift S0, P5
+  shift S0, argv
 
 NOTD:
   ne S0, "-u", GO
   set I12, 1 # unique mode
-  shift S0, P5
+  shift S0, argv
 
 GO:
   # S2 is the previous line
@@ -133,10 +142,5 @@ LOOP:
   if S1, SOURCE_LOOP
   close P1
 
-  end
-
-=head1 HISTORY
+.end
 
-By Leon Brocard <[EMAIL PROTECTED]>
-
-=cut

Modified: trunk/t/examples/pir.t
==============================================================================
--- trunk/t/examples/pir.t      (original)
+++ trunk/t/examples/pir.t      Tue Nov  8 13:27:24 2005
@@ -32,7 +32,7 @@ Bernhard Schmalhofer - <Bernhard.Schmalh
 =cut
 
 use strict;
-use Parrot::Test tests => 10;
+use Parrot::Test tests => 11;
 use Test::More;
 use Parrot::Config;
 
@@ -223,13 +223,29 @@ while ( my ( $example, $expected ) = eac
     my $readline_pir_fn = 
"examples$PConfig{slash}pir$PConfig{slash}readline.pir";
     my $readline_tmp_fn = "test_readline.tmp";
     open( my $tmp, '>', $readline_tmp_fn );
-    print $tmp "first line\n\nlast line\n";
+    print $tmp join( "\n", 'first line', '', 'last line' );
     close $tmp;
-    my $expected = << 'END_EXPECTED';
+    my $out = `$PARROT $readline_pir_fn < $readline_tmp_fn`;
+    is( $out, << 'END_EXPECTED', 'print until first empty line' );
 first line
 END_EXPECTED
-    my $out = `$PARROT $readline_pir_fn < $readline_tmp_fn`;
-    is( $out, $expected, 'print until first empty line' );
     unlink( $readline_tmp_fn );
 }
 
+# uniq.pir expects a file that it can uniquify 
+{
+    my $uniq_pir_fn = "examples$PConfig{slash}pir$PConfig{slash}uniq.pir";
+    my $uniq_tmp_fn = "test_uniq.tmp";
+    open( my $tmp, '>', $uniq_tmp_fn );
+    print $tmp join( "\n", qw( a a a b b c d d d ) );
+    close $tmp;
+    my $out = `$PARROT $uniq_pir_fn $uniq_tmp_fn`;
+    is( $out, << 'END_EXPECTED', 'print until first empty line' );
+a
+b
+c
+d
+END_EXPECTED
+    unlink( $uniq_tmp_fn );
+}
+

Reply via email to