summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/t/uni/labels.t
blob: efae494fe252303a99cc3e3699acc83a1285ba74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!./perl

# Tests for labels in UTF-8

BEGIN {
    chdir 't' if -d 't';
    require './test.pl';
    set_up_inc('../lib');
    skip_all_without_unicode_tables();
}

use utf8;
use open qw( :utf8 :std );
use warnings;
use feature qw 'unicode_strings evalbytes';

use charnames qw( :full );

plan(10);

LABEL: {
    pass("Sanity check, UTF-8 labels don't throw a syntax error.");
}


SKIP: {
    skip_if_miniperl("no dynamic loading, no Encode", 2);
    no warnings 'exiting';
    require Encode;

    my $prog = 'last LOOP;';

    LOOP: {
        eval $prog;
    }
    is $@, '', "last with a UTF-8 label works,";

    LOOP: {
        Encode::_utf8_off($prog);
        evalbytes $prog;
        like $@, qr/^Unrecognized character/, "..but turn off the UTF-8 flag and it explodes";
    }
}

{
    no warnings 'exiting';

    eval "last ";
    like $@, qr/Label not found for "last " at/u, "last's error is UTF-8 clean";
    
    eval "redo E";
    like $@, qr/Label not found for "redo E" at/u, "redo's error is UTF-8 clean";
    
    eval "next ";
    like $@, qr/Label not found for "next " at/u, "next's error is UTF-8 clean";
}

my $d = 2;
LÁBEL: {
    my $e = $@;
    my $prog = "redo L\N{LATIN CAPITAL LETTER A WITH ACUTE}BEL";

    if ($d == 1) {
        is $e, '', "redo UTF8 works";
        utf8::downgrade($prog);
    }
    if ($d--) {
        use feature 'unicode_eval';
        no warnings 'exiting';
        eval $prog;
    }
}

like $@, qr/Unrecognized character/, "redo to downgradeable labels";
is $d, 0, "Latin-1 labels are reachable";

{
    no warnings;
    goto ここ;
    
    if (undef) {
        ここ: {
            pass("goto UTF-8 LABEL works.");
        }
    }
}