emacs/test/lisp/progmodes/cperl-mode-resources/cperl-bug-66145.pl
Harald Jörg fc1f6688a2 ; cperl-mode.el: Don't override fontificaton in comments.
* lisp/progmodes/cperl-mode.el (cperl-init-faces): Reorder the
matchers for fontification of array and hash elements and keys so
that they don't override comment and string fontification (Bug#66145).

* test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-66145):
New test for all combinations of sigils and brackets/braces to
verify that strings and comments are left untouched.  This test
also works for perl-mode which has always done it correctly.

* test/lisp/progmodes/cperl-mode-resources/cperl-bug-66145.pl: New
resource file for the above test.
2023-10-09 17:58:21 +02:00

62 lines
1.9 KiB
Perl

# The original code, from the bug report, with variables renamed
sub foo {
# Here we do something like
# this: $array_comment [ num_things ]->{key_comment}
}
# --------------------------------------------------
# Comments containing hash and array sigils
# This is an @array, and this is a %hash
# $array_comment[$index] = $hash_comment{key_comment}
# The last element has the index $#array_comment
# my @a_slice = @array_comment[1,2,3];
# my @h_slice = @hash_comment{qw(a b c)};
# my %a_set = %array_comment[1,2,3];
# my %h_set = %hash_comment{qw(a b c)};
# --------------------------------------------------
# in POD
=head1 NAME
cperl-bug-66145 - don't fontify arrays and hashes in POD
=head1 SYNOPSIS
$array_comment[$index] = $hash_comment{key_comment};
@array_comment = qw(in pod);
%hash_comment = key_comment => q(pod);
@array_comment = @array_comment[1,2,3];
@array_comment = @hash_comment{qw(a b c)};
%hash_comment = %array_comment[1,2,3];
%hash_comment = %hash_comment{qw(a b c)};
=cut
# --------------------------------------------------
# in strings
my @strings = (
q/$array_string[$index] = $hash_string{key_string};/,
q/my @array_string = qw(in unquoted string);/,
q/my %hash_string = (key_string => q(pod);)/,
q/@array_string = @array_string[1,2,3];/,
q/@array_string = @hash_string{qw(a b c)};/,
q/%hash_string = %array_string[1,2,3];/,
q/%hash_string = %hash_string{qw(a b c)};/,
);
# --------------------------------------------------
# in a HERE-document (perl-mode has an extra face for that)
my $here = <<DONE;
$array_here[$index_here] = $hash_here{key_here};
@array_here = qw(in a hrere-document);
%hash_here = key_here => q(pod);
@array_here = @array_here[1,2,3];
@array_here = @hash_here{qw(a b c)};
%hash_here = %array_here[1,2,3];
%hash_here = %hash_here{qw(a b c)};
DONE