#!perl # Copyright (C) 2001-2005, The Perl Foundation. # $Id: /local/t/compilers/pge/p6regex/context.t 12838 2006-05-30T14:19:10.150135Z coke $ use strict; use warnings; use lib qw( t . lib ../lib ../../lib ../../../lib ); use Test::More; use Parrot::Test; use Parrot::Test::PGE; =head1 NAME t/p6regex/context.t - PGE return value tests =head1 DESCRIPTION These tests are based on L, ver. 8, in the B<'Return values from matches'> section =head1 SYNOPSIS % prove t/p6regex/context.t =cut my $PRE = < 1)'); rulesub = p6rule('1abc') match = rulesub('1abc') $I0 = match print $I0 goto END CODE 1 OUT pir_output_is($PRE.<<'CODE'.$POST,< 12)'); rulesub = p6rule('(1)(2)(b)(c)') match = rulesub('12bc') $I0 = match print $I0 goto END CODE 12 OUT pir_output_is($PRE.<<'CODE'.$POST,< 0)'); rulesub = p6rule('0abc') match = rulesub('abc') $I0 = match print $I0 goto END CODE 0 OUT pir_output_is($PRE.<<'CODE'.$POST,< 0)'); rulesub = p6rule('xxx') match = rulesub('abc') $I0 = match print $I0 goto END CODE 0 OUT pir_output_is($PRE.<<'CODE'.$POST,< 0)'); rulesub = p6rule('a1bc') match = rulesub('a1bc') $I0 = match print $I0 goto END CODE 0 OUT pir_output_is($PRE.<<'CODE'.$POST,< full match)'); rulesub = p6rule('abc') match = rulesub('abc') .local string res, exp res = match exp = 'abc' eq exp, res, OK goto NOK CODE ok OUT pir_output_is($PRE.<<'CODE'.$POST,< full match)'); rulesub = p6rule('(a)(b)(c)') match = rulesub('abc') .local string res, exp res = match exp = 'abc' eq exp, res, OK goto NOK CODE ok OUT pir_output_is($PRE.<<'CODE'.$POST,< "")'); rulesub = p6rule('xxx') match = rulesub('abc') .local string res, exp res = match exp = '' eq exp, res, OK CODE ok OUT ## as array pir_output_is($PRE.<<'CODE'.$POST,< "cba")'); rulesub = p6rule('(a)(b)(c)') match = rulesub('abc') .local string res $P0 = match[2] res = $P0 print res $P0 = match[1] res = $P0 print res $P0 = match[0] res = $P0 print res goto END CODE cba OUT pir_output_is($PRE.<<'CODE'.$POST,< "cba")'); rulesub = p6rule('(a)(b)(c)') match = rulesub('abc') .local string res res = match[2] print res res = match[1] print res res = match[0] print res goto END CODE cba OUT ## TODO: more ## as hash pir_output_is($PRE.<<'CODE'.$POST,< "a")'); rulesub = p6rule('$:=(.)b$:=(c)') match = rulesub('abc') .local string res res = match['A'] print res res = match['C'] print res goto END CODE ac OUT pir_output_is($PRE.<<'CODE'.$POST,<:=(.)(b)$:=(c)') match = rulesub('abc') .local string res res = match['A'] print res $P0 = match[0] res = $P0 print res res = match['C'] print res goto END CODE abc OUT ## numbered captures treated as named pir_output_is($PRE.<<'CODE'.$POST,< $/[1])', todo => 'not yet implemented'); rulesub = p6rule('(a)(b)(c)') match = rulesub('abc') .local string res, exp $P0 = match[1] res = $P0 print res res = match['2'] print res goto END CODE bb OUT ## additional methods pir_output_is($PRE.<<'CODE'.$POST,< 20; }