my $bas_tests = 20;
# number of tests in section 3
-my $bug_tests = 4 + 3 * 3 * 5 * 2 * 3 + 2 + 6 + 2 + 1 + 1;
+my $bug_tests = 4 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3;
# number of tests in section 4
my $hmb_tests = 35;
"$base\nMoo!\n",) {
foreach (['^*', qr/(.+)/], ['@*', qr/(.*?)$/s]) {
my ($format, $re) = @$_;
+ $format = "1^*2 3${format}4";
foreach my $class ('', 'Count') {
- my $name = "$first, $second $format $class";
+ my $name = qq{swrite("$format", "$first", "$second") class="$class"};
$name =~ s/\n/\\n/g;
+ $name =~ s{(.)}{
+ ord($1) > 126 ? sprintf("\\x{%x}",ord($1)) : $1
+ }ge;
$first =~ /(.+)/ or die $first;
my $expect = "1${1}2";
my $copy1 = $first;
my $copy2;
tie $copy2, $class, $second;
- is swrite("1^*2 3${format}4", $copy1, $copy2), $expect, $name;
+ is swrite("$format", $copy1, $copy2), $expect, $name;
my $obj = tied $copy2;
is $obj->[1], 1, 'value read exactly once';
} else {
my ($copy1, $copy2) = ($first, $second);
- is swrite("1^*2 3${format}4", $copy1, $copy2), $expect, $name;
+ is swrite("$format", $copy1, $copy2), $expect, $name;
}
}
}
.
-# [ID 20020227.005] format bug with undefined _TOP
+# RT #8698 format bug with undefined _TOP
open STDOUT_DUP, ">&STDOUT";
my $oldfh = select STDOUT_DUP;
local $~ = "Comment";
write;
curr_test($test + 1);
- {
- local $::TODO = '[ID 20020227.005] format bug with undefined _TOP';
- is $-, 9;
- }
+ is $-, 9;
is $^, "STDOUT_DUP_TOP";
}
select $oldfh;
$^A ='';
::is $format, $orig, "RT91032: don't overwrite orig format string";
+ # check that ~ and ~~ are displayed correctly as whitespace,
+ # under the influence of various different types of border
+
+ for my $n (1,2) {
+ for my $lhs (' ', 'Y', '^<<<', '^|||', '^>>>') {
+ for my $rhs ('', ' ', 'Z', '^<<<', '^|||', '^>>>') {
+ my $fmt = "^<B$lhs" . ('~' x $n) . "$rhs\n";
+ my $sfmt = ($fmt =~ s/~/ /gr);
+ my ($a, $bc, $stop);
+ ($a, $bc, $stop) = ('a', 'bc', 's');
+ # $stop is to stop '~~' deleting the whole line
+ formline $sfmt, $stop, $a, $bc;
+ my $exp = $^A;
+ $^A = '';
+ ($a, $bc, $stop) = ('a', 'bc', 's');
+ formline $fmt, $stop, $a, $bc;
+ my $got = $^A;
+ $^A = '';
+ $fmt =~ s/\n/\\n/;
+ ::is($got, $exp, "chop munging: [$fmt]");
+ }
+ }
+ }
+}
+
+# check that '~ (delete current line if empty) works when
+# the target gets upgraded to uft8 (and re-allocated) midstream.
+
+{
+ my $format = "\x{100}@~\n"; # format is utf8
+ # this target is not utf8, but will expand (and get reallocated)
+ # when upgraded to utf8.
+ my $orig = "\x80\x81\x82";
+ local $^A = $orig;
+ my $empty = "";
+ formline $format, $empty;
+ is $^A , $orig, "~ and realloc";
+
+ # check similarly that trailing blank removal works ok
+
+ $format = "@<\n\x{100}"; # format is utf8
+ chop $format;
+ $orig = " ";
+ $^A = $orig;
+ formline $format, " ";
+ is $^A, "$orig\n", "end-of-line blanks and realloc";
+
+ # and check this doesn't overflow the buffer
+
+ local $^A = '';
+ $format = "@* @####\n";
+ $orig = "x" x 100 . "\n";
+ formline $format, $orig, 12345;
+ is $^A, ("x" x 100) . " 12345\n", "\@* doesn't overflow";
+
+ # make sure it can cope with formats > 64k
+
+ $format = 'x' x 65537;
+ $^A = '';
+ formline $format;
+ # don't use 'is' here, as the diag output will be too long!
+ ok $^A eq $format, ">64K";
}
is $buf, "ok $test\n", "write to duplicated format";
}
+format caret_A_test_TOP =
+T
+.
+
+format caret_A_test =
+L1
+L2
+L3
+L4
+.
+
+SKIP: {
+ skip_if_miniperl('miniperl does not support scalario');
+ my $buf = "";
+ open my $fh, ">", \$buf;
+ my $old_fh = select $fh;
+ local $^ = "caret_A_test_TOP";
+ local $~ = "caret_A_test";
+ local $= = 3;
+ local $^A = "A1\nA2\nA3\nA4\n";
+ write;
+ select $old_fh;
+ close $fh;
+ is $buf, "T\nA1\nA2\n\fT\nA3\nA4\n\fT\nL1\nL2\n\fT\nL3\nL4\n",
+ "assign to ^A sets FmLINES";
+}
+
fresh_perl_like(<<'EOP', qr/^Format STDOUT redefined at/, {stderr => 1}, '#64562 - Segmentation fault with redefined formats and warnings');
#!./perl