#=============================================================================== # # DESCRIPTION: Test format codes # # AUTHOR: Aliaksandr P. Zahatski, #=============================================================================== package main; use strict; use warnings; use Data::Dumper; use v5.10; use Regexp::Grammars; use Perl6::Pod::Codeactions; use Perl6::Pod::Grammars; use Test::More tests => 16; # last test to print my %delim = ( '<' => '>', '«' => '»', '<<' => '>>' ); my %allow = ( '*' => 1 ); my $r = qr{ # \A \Z <[content]>+ .+? [ \t]* | | | | | | <.text> <%delim> (??{ quotemeta $delim{$ARG{ldelim}} }) (?! \s+) (?! \s+) (?: \| <[syns=(\S+)]>+ % ;)? (?! \s+) (?! \s+) # # #alternate presentation (?: \| )? #hack1: not work for #L< http://cpan.org > B L< haname | http:perl.html > # '' => 'L< http://cpan.org > B L< haname | http:perl.html >' # (?:)? #hack ? #scheme specifier (?: )? ? #for hack1 (?: \# )? #internal addresses <[entry=([^,\;]+?)]>* % (\s*,\s*) (?! \s+) # X ( (?{$MATCH{entry}=$MATCH{text}; $MATCH{form} = 1 }) | ? \| <[entries=X_code_entry]>* % (\s*\;\s*) (?{$MATCH{form} = 2}) ) <.hs> ? #scheme specifier (?: )? <.hs> <.hs> <[content]>*? <.hs> }xms; sub parse_para { my $src = shift; use Perl6::Pod::Utl; return Perl6::Pod::Utl::parse_para($src, reg=>$r); } my @t; my $STOP_TREE = 2; @t = ( ' sd C<<>ss» sB' ); @t=('D, and D'); @t=('C asds Bsad >'); my @grammars; #### test L<> is parse_para('L')->[0]->{scheme},'http:', 'L: scheme http://example.com'; #=pod my $t1 = parse_para('L')->[0]; #print Dumper $t1;exit; is $t1->{section}, 'test', 'L: section'; ok $t1->{is_external}, 'L: external'; $t1 = parse_para('L<#test>')->[0]; is $t1->{section}, 'test', 'L: only section'; $t1 = parse_para('L')->[0]; is $t1->{alt_text}, 'text', 'L: alternate text'; $t1 = parse_para('L')->[0]; is $t1->{scheme},'mailto:','L: mailto'; $t1 = parse_para('L')->[0]; is $t1->{scheme},'issn:','L: issn'; $t1 = parse_para('L')->[0]; is $t1->{scheme},'file:','L: file'; $t1 = parse_para('L B L<< haname | http:perl.html >>')->[0]; is $t1->{scheme},'file:','L: L<> L<|>'; $t1 = parse_para('L|http://example.com> test')->[0]; is $t1->{alt_text}, 'B','nested formatting codes'; $t1 = parse_para('X< array >')->[0]; is $t1->{text}, $t1->{entry}, 'X'; is $t1->{text}, 'array', 'check text X'; $t1 = parse_para('X< arrays | array1, array2; use array >')->[0]; is @{$t1->{entries}}, 2, "more than one entries"; is $t1->{text}, 'arrays', 'check text: X< arrays | array1, array2; use array >'; $t1 = parse_para('X<| array1, array2; use array >')->[0]; is $t1->{text},'', 'empty text'; $t1 = parse_para('P')->[0]; is $t1->{'scheme'},'http:', 'P: scheme'; #diag Dumper $t1; #diag Dumper $t1; #diag Dumper parse_para('L'); #diag Dumper parse_para('C«E»'); exit; #@t = (); @grammars = @t if scalar(@t); while ( my ( $src, $extree, $name ) = splice( @grammars, 0, 3 ) ) { $name //= $src; my $dump; use Perl6::Pod::Utl; my $res = Perl6::Pod::Utl::parse_para($src, reg=>$r); diag Dumper $res; exit; # use Perl6::Pod::Autoactions; # if ( $src =~ $r->with_actions( Perl6::Pod::Codeactions->new ) ) { if ( $src =~ $r ) { if ( $STOP_TREE == 2 ) { say Dumper( {%/}->{Text} ); exit; } # $dump = Perl6::Pod::To::Dump->new->visit( {%/}->{File} ); } else { fail($name); die "Can't parse: \n" . $src; } if ( $STOP_TREE == 1 ) { say Dumper($dump); exit; } is_deeply( $dump, $extree, $name ) || do { say "fail Deeeple" . Dumper( $dump, $extree, ); exit; }; }