X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?p=subdirmk.git;a=blobdiff_plain;f=tests%2Ffilter%2Fextract-doctest;h=40cf4f576822f17cb1b750b691f44c9cc4b20e8a;hp=28dee5ec7a4942cfd7f31f306fbea6c1f3c907ea;hb=b870fbb3b70af8a37585f4ecedc7e0e574f772f1;hpb=8c6b02849c6918f1deac8e463b24335844d65b86 diff --git a/tests/filter/extract-doctest b/tests/filter/extract-doctest index 28dee5e..40cf4f5 100755 --- a/tests/filter/extract-doctest +++ b/tests/filter/extract-doctest @@ -56,8 +56,13 @@ while (<>) { $e->{OutTop} = $1 eq 'nothing' ? '' : $1; } elsif (# parse: expect other wordish things to be comments m{^(?!or\b)\w{2,} }) { + } elsif (m/^$/) { + } else { + confess "unk rhs $_ ?"; } $e->{CQ} = $in_changequote; + # adhoc: rely on this specific section title + $e->{DD} = $csection =~ m{^while dollar[- ]doubling}i; } else { confess "$_ ?"; } @@ -105,16 +110,16 @@ sub write_permode ($$$$$;$$) { $rubric =~ s/\&/AMP /g; $rubric =~ s/\$/DOLLAR /g; $rubric =~ s/NEWQUOTE/NEW_QUOTE /g; - my $f = $e->{In} =~ m/\n/ - ? "\n# %s:\n%s\n\n" - : "%-30s: %s.\n"; + my ($f,$prubric) = $rubric =~ m/^(.*)\n/ + ? ("\n# %s:\n%s\n\n", $1) + : ("%-30s: %s .\n", $rubric); my $o; $o = $e->{OutTop} if $dir_prefix eq ''; $o //= $e->{Out}; $o =~ s{/sub/dir}{} if $dir_prefix eq '' && !defined $e->{OutTop}; $o = $omap->($o, $e); - oi sprintf $f, $rubric, $e->{In}; - oo sprintf $f, $rubric, $o; + oi sprintf $f, $prubric, $e->{In}; + oo sprintf $f, $prubric, $o; } oi $end; oh "${senl}# ----- $what ends -----\n"; @@ -127,11 +132,30 @@ sub writeout ($) { oh "# doctest starts $dir_prefix\n"; write_permode($dir_prefix, '','','', 'normal', - sub { !$_[0]{CQ} } ); + sub { !$_[0]{DD} && !$_[0]{CQ} } ); + write_permode($dir_prefix, + '&$+', '&$-', "\n", + 'dollar doubling', + sub { + my ($e) = @_; + return 0 if $e->{CQ}; + return $e->{DD} || !grep { + # If there are two entries with the same In, + # use only the one from the `while dollar + # doubling' section. So entries there override + # entries in the rest o the file. + $_ ne $e && $_->{In} eq $e->{In} + } @exp; + }, + sub { + $_=$_[0]; + s/\$/\$\$/g unless $_[1]{DD}; + $_; + } ); write_permode($dir_prefix, - "&:changequote NEWQUOTE", - "NEWQUOTE:changequote &", - "\n", + "&:changequote NEWQUOTE\n", + "NEWQUOTE:changequote &\n", + "", 'changequote', sub { $_[0]{CQ} } ); oh "# doctest ends\n";