This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: Make sure things are initialized
[perl5.git] / t / uni / labels.t
1 #!./perl
2
3 # Tests for labels in UTF-8
4
5 BEGIN {
6     chdir 't' if -d 't';
7     require './test.pl';
8     set_up_inc('../lib');
9     skip_all_without_unicode_tables();
10 }
11
12 use utf8;
13 use open qw( :utf8 :std );
14 use warnings;
15 use feature qw 'unicode_strings evalbytes';
16
17 use charnames qw( :full );
18
19 plan(10);
20
21 LABEL: {
22     pass("Sanity check, UTF-8 labels don't throw a syntax error.");
23 }
24
25
26 SKIP: {
27     skip_if_miniperl("no dynamic loading, no Encode", 2);
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);
40         evalbytes $prog;
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
58 my $d = 2;
59 LÁBEL: {
60     my $e = $@;
61     my $prog = "redo L\N{LATIN CAPITAL LETTER A WITH ACUTE}BEL";
62
63     if ($d == 1) {
64         is $e, '', "redo UTF8 works";
65         utf8::downgrade($prog);
66     }
67     if ($d--) {
68         use feature 'unicode_eval';
69         no warnings 'exiting';
70         eval $prog;
71     }
72 }
73
74 like $@, qr/Unrecognized character/, "redo to downgradeable labels";
75 is $d, 0, "Latin-1 labels are reachable";
76
77 {
78     no warnings;
79     goto ここ;
80     
81     if (undef) {
82         ここ: {
83             pass("goto UTF-8 LABEL works.");
84         }
85     }
86 }