}
use strict;
-plan( tests => 111 );
+plan( tests => 121 );
run_tests() unless caller;
is (rindex($text, $search_octets), -1);
}
-foreach my $utf8 ('', ', utf-8') {
- foreach my $arraybase (0, 1, -1, -2) {
- my $expect_pos = 2 + $arraybase;
-
- my $prog = "no warnings 'deprecated';\n";
- $prog .= "\$[ = $arraybase; \$big = \"N\\xabN\\xab\"; ";
- $prog .= '$big .= chr 256; chop $big; ' if $utf8;
- $prog .= 'print rindex $big, "N", 2 + $[';
-
- fresh_perl_is($prog, $expect_pos, {}, "\$[ = $arraybase$utf8");
- }
-}
-
SKIP: {
skip "UTF-EBCDIC is limited to 0x7fffffff", 3 if ord("A") == 193;
}
}
+{
+ # RT#75898
+ is(eval { utf8::upgrade($_ = " "); index $_, " ", 72 }, -1,
+ 'UTF-8 cache handles offset beyond the end of the string');
+ $_ = "\x{100}BC";
+ is(index($_, "C", 4), -1,
+ 'UTF-8 cache handles offset beyond the end of the string');
}
+
+# RT #89218
+use constant {PVBM => 'galumphing', PVBM2 => 'bang'};
+
+sub index_it {
+ is(index('galumphing', PVBM), 0,
+ "index isn't confused by format compilation");
+}
+
+index_it();
+is($^A, '', '$^A is empty');
+formline PVBM;
+is($^A, 'galumphing', "formline isn't confused by index compilation");
+index_it();
+
+$^A = '';
+# must not do index here before formline.
+is($^A, '', '$^A is empty');
+formline PVBM2;
+is($^A, 'bang', "formline isn't confused by index compilation");
+is(index('bang', PVBM2), 0, "index isn't confused by format compilation");
+
+{
+ use constant perl => "rules";
+ is(index("perl rules", perl), 5, 'first index of a constant works');
+ is(index("rules 1 & 2", perl), 0, 'second index of the same constant works');
+}
+
+# PVBM compilation should not flatten ref constants
+use constant riffraff => \our $referent;
+index "foo", riffraff;
+is ref riffraff, 'SCALAR', 'index does not flatten ref constants';
+
+package o { use overload '""' => sub { "foo" } }
+bless \our $referent, o::;
+is index("foo", riffraff), 0,
+ 'index respects changes in ref stringification';
+
+use constant quire => ${qr/(?{})/}; # A REGEXP, not a reference to one
+index "foo", quire;
+eval ' "" =~ quire ';
+is $@, "", 'regexp constants containing code blocks are not flattened';
+
+use constant bang => $! = 8;
+index "foo", bang;
+cmp_ok bang, '==', 8, 'dualvar constants are not flattened';
+
+use constant u => undef;
+{
+ my $w;
+ local $SIG{__WARN__} = sub { $w .= shift };
+ eval '
+ use warnings;
+ sub { () = index "foo", u; }
+ ';
+ is $w, undef, 'no warnings from compiling index($foo, undef_constant)';
+}
+is u, undef, 'undef constant is still undef';
+
+is index('the main road', __PACKAGE__), 4,
+ '[perl #119169] __PACKAGE__ as 2nd argument';
+
+} # end of sub run_tests