Author: bernhard
Date: Wed Oct 12 15:15:37 2005
New Revision: 9473
Added:
trunk/examples/pir/pcre.pir
- copied, changed from r9469, trunk/examples/assembly/pcre.imc
Removed:
trunk/examples/assembly/pcre.imc
Modified:
trunk/t/examples/pir.t
Log:
Move examples/assembly/pcre.imc to examples/pir/pcre.pir.
Detabify it and add a simple test.
Copied: trunk/examples/pir/pcre.pir (from r9469,
trunk/examples/assembly/pcre.imc)
==============================================================================
--- trunk/examples/assembly/pcre.imc (original)
+++ trunk/examples/pir/pcre.pir Wed Oct 12 15:15:37 2005
@@ -1,17 +1,17 @@
-# Copyright (C) 2001-2003 The Perl Foundation. All rights reserved.
+# Copyright (C) 2001-2005 The Perl Foundation. All rights reserved.
# $Id$
=head1 NAME
-examples/assembly/pcre.imc - perl-compatible regular expressions
+examples/pir/pcre.imc - Perl compatible regular expressions
=head1 SYNOPSIS
- % ./parrot examples/assembly/pcre.imc string pattern
+ % ./parrot examples/pir/pcre.pir string pattern
=head1 DESCRIPTION
-Experimental string matching with PCRE (L<http://www.pcre.org/>).
+Experimental string matching with PCRE, L<http://www.pcre.org/>.
Note that PCRE must be installed for this to work.
=head1 AUTHORS
@@ -26,55 +26,55 @@ E<lt>jerry dot gay at gmail dot com<gt>
.sub main :main
- .param pmc argv
+ .param pmc argv
- .local int argc
- argc= argv
- if argc != 3 goto USAGE
-
- .local pmc func
- .local pmc lib
-
- func= find_global 'PCRE', 'init'
- lib= func()
-
- .local string s
- s= argv[1]
- .local string pat
- pat= argv[2]
-
- print s
- print " =~ /"
- print pat
- print "/\n"
-
- .local pmc regex
- .local string error
- .local int errptr
-
- func= find_global 'PCRE', 'compile'
- ( regex, error, errptr )= func( pat, 0 )
-
- .local int is_regex_defined
- is_regex_defined= defined regex
- unless is_regex_defined goto MATCH_ERR
-
- .local int ok
- .local pmc result
-
- func= find_global 'PCRE', 'match'
- ( ok, result )= func( regex, s, 0, 0 )
-
- if ok < 0 goto NOMATCH
- print ok
- print " match(es):\n"
+ .local int argc
+ argc= argv
+ if argc != 3 goto USAGE
+
+ .local pmc func
+ .local pmc lib
+
+ func= find_global 'PCRE', 'init'
+ lib= func()
+
+ .local string s
+ s= argv[1]
+ .local string pat
+ pat= argv[2]
+
+ print s
+ print " =~ /"
+ print pat
+ print "/\n"
+
+ .local pmc regex
+ .local string error
+ .local int errptr
+
+ func= find_global 'PCRE', 'compile'
+ ( regex, error, errptr )= func( pat, 0 )
+
+ .local int is_regex_defined
+ is_regex_defined= defined regex
+ unless is_regex_defined goto MATCH_ERR
+
+ .local int ok
+ .local pmc result
+
+ func= find_global 'PCRE', 'match'
+ ( ok, result )= func( regex, s, 0, 0 )
+
+ if ok < 0 goto NOMATCH
+ print ok
+ print " match(es):\n"
.local int i
i= 0
.local string match
LP:
- func= find_global 'PCRE', 'dollar'
- match= func( s, ok, result, i )
+ func= find_global 'PCRE', 'dollar'
+ match= func( s, ok, result, i )
print match
print "\n"
inc i
@@ -83,16 +83,16 @@ LP:
NOMATCH:
print "no match\n"
- end
+ end
MATCH_ERR:
print "error in regex: "
print "at: '"
- .local int pat_errloc
+ .local int pat_errloc
length pat_errloc, pat
pat_errloc = pat_errloc - errptr
- .local string pattern_error
+ .local string pattern_error
substr pattern_error, pat, errptr, pat_errloc
print pattern_error
print "'\n"
@@ -101,7 +101,7 @@ MATCH_ERR:
USAGE:
.local string prog
prog= argv[0]
- print 'usage: '
+ print 'usage: '
print prog
print " string pattern\n"
exit 1
Modified: trunk/t/examples/pir.t
==============================================================================
--- trunk/t/examples/pir.t (original)
+++ trunk/t/examples/pir.t Wed Oct 12 15:15:37 2005
@@ -8,9 +8,9 @@ t/examples/pir.t - Test examples in F<ex
=head1 SYNOPSIS
- % perl -Ilib t/examples/pir.t
+ % perl -Ilib t/examples/pir.t
- % perl t/harness t/examples/pir.t
+ % perl t/harness t/examples/pir.t
=head1 DESCRIPTION
@@ -19,15 +19,20 @@ Test the examples in F<examples/pir>.
=head1 TODO
Check on remaining examples.
+Perhaps use Parrot::Test::run_command().
=head1 SEE ALSO
F<t/examples/pasm.t>
+=head1 AUTHOR
+
+Bernhard Schmalhofer - <[EMAIL PROTECTED]>
+
=cut
use strict;
-use Parrot::Test tests => 3;
+use Parrot::Test tests => 4;
use Test::More;
use Parrot::Config;
@@ -121,10 +126,20 @@ while ( my ( $example, $expected ) = eac
}
}
-
# For testing md5sum.pir we need to pass a filename
{
my $md5sum_fn = "examples$PConfig{slash}pir$PConfig{slash}md5sum.pir";
my $sum = `$PARROT $md5sum_fn $md5sum_fn`;
is( $sum, "0141db367bd8265f37926c16ccf5113a\t$md5sum_fn\n", $md5sum_fn );
}
+
+# Testing pcre.imc with a simple pattern
+{
+ my $pcre_fn = "examples$PConfig{slash}pir$PConfig{slash}pcre.pir";
+ my $test_out = `$PARROT $pcre_fn asdf as`;
+ is( $test_out, << 'END_EXPECTED', $pcre_fn );
+asdf =~ /as/
+1 match(es):
+as
+END_EXPECTED
+}