1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/Arequire './test.pl';
1N/Aplan(tests => 33);
1N/A
1N/A# compile time
1N/A
1N/Ais('-' x 5, '-----', 'compile time x');
1N/Ais('-' x 1, '-', ' x 1');
1N/Ais('-' x 0, '', ' x 0');
1N/Ais('-' x -1, '', ' x -1');
1N/Ais('-' x undef, '', ' x undef');
1N/A
1N/Ais('ab' x 3, 'ababab', ' more than one char');
1N/A
1N/A# run time
1N/A
1N/A$a = '-';
1N/Ais($a x 5, '-----', 'run time x');
1N/Ais($a x 1, '-', ' x 1');
1N/Ais($a x 0, '', ' x 0');
1N/Ais($a x -3, '', ' x -3');
1N/Ais($a x undef, '', ' x undef');
1N/A
1N/A$a = 'ab';
1N/Ais($a x 3, 'ababab', ' more than one char');
1N/A$a = 'ab';
1N/Ais($a x 0, '', ' more than one char');
1N/A$a = 'ab';
1N/Ais($a x -12, '', ' more than one char');
1N/A
1N/A$a = 'xyz';
1N/A$a x= 2;
1N/Ais($a, 'xyzxyz', 'x=2');
1N/A$a x= 1;
1N/Ais($a, 'xyzxyz', 'x=1');
1N/A$a x= 0;
1N/Ais($a, '', 'x=0');
1N/A
1N/A@x = (1,2,3);
1N/A
1N/Ais(join('', @x x 4), '3333', '@x x Y');
1N/Ais(join('', (@x) x 4), '123123123123', '(@x) x Y');
1N/Ais(join('', (@x,()) x 4), '123123123123', '(@x,()) x Y');
1N/Ais(join('', (@x,1) x 4), '1231123112311231', '(@x,1) x Y');
1N/Ais(join(':', () x 4), '', '() x Y');
1N/Ais(join(':', (9) x 4), '9:9:9:9', '(X) x Y');
1N/Ais(join(':', (9,9) x 4), '9:9:9:9:9:9:9:9', '(X,X) x Y');
1N/Ais(join('', (split(//,"123")) x 2), '123123', 'split and x');
1N/A
1N/Ais(join('', @x x -12), '', '@x x -12');
1N/Ais(join('', (@x) x -14), '', '(@x) x -14');
1N/A
1N/A
1N/A# This test is actually testing for Digital C compiler optimizer bug,
1N/A# present in Dec C versions 5.* and 6.0 (used in Digital UNIX and VMS),
1N/A# found in December 1998. The bug was reported to Digital^WCompaq as
1N/A# DECC 2745 (21-Dec-1998)
1N/A# GEM_BUGS 7619 (23-Dec-1998)
1N/A# As of April 1999 the bug has been fixed in Tru64 UNIX 5.0 and is planned
1N/A# to be fixed also in 4.0G.
1N/A#
1N/A# The bug was as follows: broken code was produced for util.c:repeatcpy()
1N/A# (a utility function for the 'x' operator) in the case *all* these
1N/A# four conditions held:
1N/A#
1N/A# (1) len == 1
1N/A# (2) "from" had the 8th bit on in its single character
1N/A# (3) count > 7 (the 'x' count > 16)
1N/A# (4) the highest optimization level was used in compilation
1N/A# (which is the default when compiling Perl)
1N/A#
1N/A# The bug looked like this (. being the eight-bit character and ? being \xff):
1N/A#
1N/A# 16 ................
1N/A# 17 .........???????.
1N/A# 18 .........???????..
1N/A# 19 .........???????...
1N/A# 20 .........???????....
1N/A# 21 .........???????.....
1N/A# 22 .........???????......
1N/A# 23 .........???????.......
1N/A# 24 .........???????.???????
1N/A# 25 .........???????.???????.
1N/A#
1N/A# The bug was triggered in the "if (len == 1)" branch. The fix
1N/A# was to introduce a new temporary variable. In diff -u format:
1N/A#
1N/A# register char *frombase = from;
1N/A#
1N/A# if (len == 1) {
1N/A#- todo = *from;
1N/A#+ register char c = *from;
1N/A# while (count-- > 0)
1N/A#- *to++ = todo;
1N/A#+ *to++ = c;
1N/A# return;
1N/A# }
1N/A#
1N/A# The bug could also be (obscurely) avoided by changing "from" to
1N/A# be an unsigned char pointer.
1N/A#
1N/A# This obscure bug was not found by the then test suite but instead
1N/A# by Mark.Martinec@nsc.ijs.si while trying to install Digest-MD5-2.00.
1N/A#
1N/A# jhi@iki.fi
1N/A#
1N/Ais("\xdd" x 24, "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", 'Dec C bug');
1N/A
1N/A
1N/A# When we use a list repeat in a scalar context, it behaves like
1N/A# a scalar repeat. Make sure that works properly, and doesn't leave
1N/A# extraneous values on the stack.
1N/A# -- robin@kitsite.com
1N/A
1N/Amy ($x, $y) = scalar ((1,2)x2);
1N/Ais($x, "22", 'list repeat in scalar context');
1N/Ais($y, undef, ' no extra values on stack');
1N/A
1N/A# Make sure the stack doesn't get truncated too much - the left
1N/A# operand of the eq binop needs to remain!
1N/Ais(77, scalar ((1,7)x2), 'stack truncation');
1N/A
1N/A
1N/A# perlbug 20011113.110 works in 5.6.1, broken in 5.7.2
1N/A{
1N/A my $x= [("foo") x 2];
1N/A is( join('', @$x), 'foofoo', 'list repeat in anon array ref broken [ID 20011113.110]' );
1N/A}
1N/A
1N/A# [ID 20010809.028] x operator not copying elements in 'for' list?
1N/A{
1N/A local $TODO = "x operator not copying elements in 'for' list? [ID 20010809.028]";
1N/A my $x = 'abcd';
1N/A my $y = '';
1N/A for (($x =~ /./g) x 2) {
1N/A $y .= chop;
1N/A }
1N/A is($y, 'abcdabcd');
1N/A}
1N/A