This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
new perldelta
[perl5.git] / t / uni / labels.t
CommitLineData
5db1eb8d
BF
1#!./perl
2
3# Tests for labels in UTF-8
4
5BEGIN {
6 chdir 't' if -d 't';
5db1eb8d 7 require './test.pl';
43ece5b1 8 set_up_inc('../lib');
2b08d1e2 9 skip_all_without_unicode_tables();
5db1eb8d
BF
10}
11
12use utf8;
13use open qw( :utf8 :std );
14use warnings;
f232b41c 15use feature qw 'unicode_strings evalbytes';
5db1eb8d
BF
16
17use charnames qw( :full );
18
07f72646 19plan(10);
5db1eb8d
BF
20
21LABEL: {
22 pass("Sanity check, UTF-8 labels don't throw a syntax error.");
23}
24
25
26SKIP: {
3c5bc6de 27 skip_if_miniperl("no dynamic loading, no Encode", 2);
5db1eb8d
BF
28 no warnings 'exiting';
29 require Encode;
30
31 my $prog = 'last LOOP;';
32
33 LOOP: {
34 eval $prog;
35 }
36 is $@, '', "last with a UTF-8 label works,";
37
38 LOOP: {
39 Encode::_utf8_off($prog);
f232b41c 40 evalbytes $prog;
5db1eb8d
BF
41 like $@, qr/^Unrecognized character/, "..but turn off the UTF-8 flag and it explodes";
42 }
43}
44
45{
46 no warnings 'exiting';
47
48 eval "last E";
49 like $@, qr/Label not found for "last E" at/u, "last's error is UTF-8 clean";
50
51 eval "redo E";
52 like $@, qr/Label not found for "redo E" at/u, "redo's error is UTF-8 clean";
53
54 eval "next E";
55 like $@, qr/Label not found for "next E" at/u, "next's error is UTF-8 clean";
56}
57
07f72646 58my $d = 2;
5db1eb8d 59LÁBEL: {
07f72646 60 my $e = $@;
5db1eb8d
BF
61 my $prog = "redo L\N{LATIN CAPITAL LETTER A WITH ACUTE}BEL";
62
07f72646
BF
63 if ($d == 1) {
64 is $e, '', "redo UTF8 works";
5db1eb8d
BF
65 utf8::downgrade($prog);
66 }
67 if ($d--) {
dd53ca2f 68 use feature 'unicode_eval';
5db1eb8d
BF
69 no warnings 'exiting';
70 eval $prog;
71 }
72}
73
07f72646
BF
74like $@, qr/Unrecognized character/, "redo to downgradeable labels";
75is $d, 0, "Latin-1 labels are reachable";
5db1eb8d
BF
76
77{
78 no warnings;
79 goto ここ;
80
81 if (undef) {
82 ここ: {
83 pass("goto UTF-8 LABEL works.");
84 }
85 }
86}