# Test both parser implementations to ensure they work the same use strict; use Test; use YAML; use File::Spec; use blib; require Inline::C::ParseRecDescent; require Inline::C::ParseRegExp; # Do all the typemap foo that Inline::C does require Inline::C; use Config; my $typemap = File::Spec->catfile($Config::Config{installprivlib}, 'ExtUtils', 'typemap'); my $o = bless {}, 'Inline::C'; push @{$o->{ILSM}{MAKEFILE}{TYPEMAPS}}, $typemap if -f $typemap; $o->get_types; # Create new instances of each parser my $recdescent = Inline::C::ParseRecDescent->get_parser(); my $regexp = Inline::C::ParseRegExp->get_parser(); $recdescent->{data}{typeconv} = $o->{ILSM}{typeconv}; $regexp->{data}{typeconv} = $o->{ILSM}{typeconv}; my @test_objects = @{YAML::Load($Inline::cases)}; plan(tests => 2 * @test_objects); for my $case (@test_objects) { my $input = $case->{input}; my $expect = $case->{expect}; my @outputs; for ($recdescent, $regexp) { # Without a fresh copy of these objects, the same stuff is parsed over # and over. However, because Parse::RecDescent is sllloooww, we can't # just construct a new object over and over. Hence, new() 'em up top, # and then clone them here. my $parser = deep_clone($_); $parser->code($input); delete $parser->{data}{typeconv}; my $output = YAML::Dump($parser->{data}); $output =~ s/^---.*\n//; push @outputs, $output; } ok($outputs[0], $expect, "ParseRecDescent failed for:$input\n"); ok($outputs[1], $expect, "ParseRegExp failed for:$input\n"); } use Data::Dumper; sub deep_clone { my $VAR1; eval Dumper($_[0]); $VAR1 } BEGIN { ($Inline::cases, undef) = (<