Ovid has asked for the wisdom of the Perl Monks concerning the following question:
This has been X-Posted to the "Higher Order Perl" discussion mailing list.
As we're using Parser.pm at my company (with the proper copyright notice, I might add) and I've started writing tests for it. Things have gone well until I encountered a case with &concatenate which doesn't match my expectations. Are my expectations wrong or is this a bug?
Below is a minimal test case demonstrating the problem. This assumes Stream.pm and Parser.pm are in the same directory as this script:#!/usr/bin/perl use strict; use warnings; use lib '.'; use Stream qw/node list_to_stream/; use Parser ':all'; use Test::More 'no_plan'; my @tokens = ( node( OP => '+' ), node( VAR => 'x' ), node( VAL => 3 ) ); my $stream = list_to_stream(@tokens); my $parser = concatenate( lookfor('OP'), lookfor('VAR'), ); my ( $parsed, $remainder ) = $parser->($stream); is_deeply $parsed, [qw/+ x/], 'concatenate should return the parsed values'; is_deeply $remainder, [ VAL => 3 ], '... and the rest of the stream'; # the next test fails ... $parser = concatenate( lookfor('OP'), lookfor('VAR'), lookfor('VAL'), ); ( $parsed, $remainder ) = $parser->($stream); is_deeply $parsed, [qw/+ x 3/], 'concatenate should return the parsed values'; ok !defined $remainder, '... and the remaining stream should be empty';
When I try to concatenate just the first two tokens, everything is fine. However, the if I try and concatenate all of the tokens together, the parser fails to find a match.
I'm sure I can fix this, but I want to make sure this is really a bug and not me misunderstanding how this code is supposed to work. I seached the errata but couldn't find and example of this problem.
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing the HOP Parser
by Ovid (Cardinal) on Aug 24, 2005 at 02:16 UTC |