+{ # test 15
+ # text lost in ^<<< field with \r in value (WL)
+ my $txt = "line 1\rline 2";
+ format OUT15 =
+^<<<<<<<<<<<<<<<<<<
+$txt
+^<<<<<<<<<<<<<<<<<<
+$txt
+.
+ open(OUT15, '>Op_write.tmp') || die "Can't create Op_write.tmp";
+ write(OUT15);
+ close OUT15 or die "Could not close: $!";
+ my $res = `$CAT Op_write.tmp`;
+ print $res eq "line 1\nline 2\n" ? "ok 15\n" : "not ok 15\n";
+}
+
+{ # test 16: multiple use of a variable in same line with ^<
+ my $txt = "this_is_block_1 this_is_block_2 this_is_block_3 this_is_block_4";
+ format OUT16 =
+^<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<
+$txt, $txt
+^<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<
+$txt, $txt
+.
+ open(OUT16, '>Op_write.tmp') || die "Can't create Op_write.tmp";
+ write(OUT16);
+ close OUT16 or die "Could not close: $!";
+ my $res = `$CAT Op_write.tmp`;
+ print $res eq <<EOD ? "ok 16\n" : "not ok 16\n";
+this_is_block_1 this_is_block_2
+this_is_block_3 this_is_block_4
+EOD
+}
+
+{ # test 17: @* "should be on a line of its own", but it should work
+ # cleanly with literals before and after. (WL)
+
+ my $txt = "This is line 1.\nThis is the second line.\nThird and last.\n";
+ format OUT17 =
+Here we go: @* That's all, folks!
+ $txt
+.
+ open(OUT17, '>Op_write.tmp') || die "Can't create Op_write.tmp";
+ write(OUT17);
+ close OUT17 or die "Could not close: $!";
+ my $res = `$CAT Op_write.tmp`;
+ chomp( $txt );
+ my $exp = <<EOD;
+Here we go: $txt That's all, folks!
+EOD
+ print $res eq $exp ? "ok 17\n" : "not ok 17\n";
+}
+
+{ # test 18: @# and ~~ would cause runaway format, but we now
+ # catch this while compiling (WL)
+
+ format OUT18 =
+@######## ~~
+10
+.
+ open(OUT18, '>Op_write.tmp') || die "Can't create Op_write.tmp";
+ eval { write(OUT18); };
+ print $@ ? "ok 18\n" : "not ok 18\n";
+ close OUT18 or die "Could not close: $!";
+}
+
+{ # test 19: \0 in an evel'ed format, doesn't cause empty lines (WL)
+ my $v = 'gaga';
+ eval "format OUT19 = \n" .
+ '@<<<' . "\0\n" .
+ '$v' . "\n" .
+ '@<<<' . "\0\n" .
+ '$v' . "\n.\n";
+ open(OUT19, '>Op_write.tmp') || die "Can't create Op_write.tmp";
+ write(OUT19);
+ my $res = `$CAT Op_write.tmp`;
+ print $res eq <<EOD ? "ok 19\n" : "not ok 19\n";
+gaga\0
+gaga\0
+EOD
+}
+
+{ # test 20: hash accesses; single '}' must not terminate format '}' (WL)
+ my %h = ( xkey => 'xval', ykey => 'yval' );
+ format OUT20 =
+@>>>> @<<<< ~~
+each %h
+@>>>> @<<<<
+$h{xkey}, $h{ykey}
+@>>>> @<<<<
+{ $h{xkey}, $h{ykey}
+}
+}
+.
+ my $exp = '';
+ while( my( $k, $v ) = each( %h ) ){
+ $exp .= sprintf( "%5s %s\n", $k, $v );
+ }
+ $exp .= sprintf( "%5s %s\n", $h{xkey}, $h{ykey} );
+ $exp .= sprintf( "%5s %s\n", $h{xkey}, $h{ykey} );
+ $exp .= "}\n";
+ open(OUT20, '>Op_write.tmp') || die "Can't create Op_write.tmp";
+ write(OUT20);
+ my $res = `$CAT Op_write.tmp`;
+ print $res eq $exp ? "ok 20\n" : "not ok 20 res=[$res]exp=[$exp]\n";
+
+EOD
+}
+
+
+#####################
+## Section 2
+## numeric formatting
+#####################
+
+my $nt = $bas_tests;
+for my $tref ( @NumTests ){
+ my $writefmt = shift( @$tref );
+ my $printfmt = mkfmt( $writefmt );
+ my $blank_when_undef = substr( $writefmt, 0, 1 ) eq '^';
+ for my $val ( @$tref ){
+ my $writeres = swrite( $writefmt, $val );
+ my $printres;
+ if( $blank_when_undef && ! defined($val) ){
+ $printres = ' ' x length( $writefmt );
+ } else {
+ $printres = sprintf( $printfmt, $val || 0 );
+ if( length($printres) > length( $writefmt ) ){
+ $printres = '#' x length( $writefmt );
+ }
+ }
+ $nt++;
+
+ print $printres eq $writeres ? "ok $nt\n" : "not ok $nt\n";
+ }
+}
+
+
+#####################################
+## Section 3
+## Easiest to add new tests above here