xref: /openbsd-src/gnu/usr.bin/perl/t/uni/package.t (revision e068048151d29f2562a32185e21a8ba885482260)
1898184e3Ssthen#!./perl
2898184e3Ssthen
3898184e3Ssthen# Checks if 'package' work as intended.
4898184e3Ssthen
5898184e3SsthenBEGIN {
6b8851fccSafresh1    chdir 't' if -d 't';
7898184e3Ssthen    require './test.pl';
8898184e3Ssthen}
9898184e3Ssthen
10898184e3Ssthenplan (tests => 18);
11898184e3Ssthen
12898184e3Ssthenuse utf8;
13898184e3Ssthenuse open qw( :utf8 :std );
14898184e3Ssthen
15898184e3Ssthenpackage Føø::Bær { }
16898184e3Ssthen
17898184e3Ssthenpackage クラス { }
18898184e3Ssthen
19898184e3Ssthenpackage ฟọ::バッズ { }
20898184e3Ssthen
21898184e3Ssthenok 1, "sanity check. If we got this far, UTF-8 in package names is legal.";
22898184e3Ssthen
23898184e3Ssthen#The next few come from comp/package.t
24898184e3Ssthen{
25898184e3Ssthen
26898184e3Ssthen    $ㄅĽufⳐ = 123;
27898184e3Ssthen
28898184e3Ssthen    package ꑭʑ;
29898184e3Ssthen
30898184e3Ssthen    sub ニュー {bless [];}
31898184e3Ssthen    $bar = 4;
32898184e3Ssthen    {
33898184e3Ssthen        package 압Ƈ;
34898184e3Ssthen        $ㄅĽufⳐ = 5;
35898184e3Ssthen    }
36898184e3Ssthen
37*e0680481Safresh1    {
38*e0680481Safresh1        no warnings qw(syntax deprecated);
39898184e3Ssthen        $압Ƈ'd읯ⱪ = 6;        #'
40*e0680481Safresh1    }
41898184e3Ssthen
42898184e3Ssthen    $ꑭʑ = 2;
43898184e3Ssthen
44898184e3Ssthen    $ꑭʑ = join(':', sort(keys %ꑭʑ::));
45898184e3Ssthen    $압Ƈ = join(':', sort(keys %압Ƈ::));
46898184e3Ssthen
47*e0680481Safresh1    ::is $ꑭʑ, 'BEGIN:bar:ニュー:ꑭʑ:압Ƈ', "comp/stash.t test 1";
48898184e3Ssthen    ::is $압Ƈ, "d읯ⱪ:ㄅĽuṞfⳐ", "comp/stash.t test 2";
49*e0680481Safresh1
50*e0680481Safresh1    {
51*e0680481Safresh1        no warnings qw(syntax deprecated);
52898184e3Ssthen        ::is $main'ㄅĽuṞfⳐ, 123, "comp/stash.t test 3";
53*e0680481Safresh1    }
54898184e3Ssthen
55898184e3Ssthen    package 압Ƈ;
56898184e3Ssthen
57898184e3Ssthen    ::is $ㄅĽuṞfⳐ, 5, "comp/stash.t test 4";
58898184e3Ssthen    eval '::is $ㄅĽufⳐ, 5, "comp/stash.t test 5";';
59898184e3Ssthen    eval 'package main; is $ㄅĽufⳐ, 123, "comp/stash.t test 6";';
60898184e3Ssthen    ::is $ㄅĽuṞfⳐ, 5, "comp/stash.t test 7";
61898184e3Ssthen
62898184e3Ssthen    #This is actually pretty bad, as caller() wasn't clean to begin with.
63898184e3Ssthen    package main;
64898184e3Ssthen    sub ㄘ { caller(0) }
65898184e3Ssthen
66898184e3Ssthen    sub ƒஓ {
67898184e3Ssthen    my $s = shift;
68898184e3Ssthen    if ($s) {
69898184e3Ssthen            packageQR;
70898184e3Ssthen            main::ㄘ();
71898184e3Ssthen    }
72898184e3Ssthen    }
73898184e3Ssthen
74898184e3Ssthen    is((ƒஓ(1))[0], 'ᛔQR', "comp/stash.t test 8");
75898184e3Ssthen
76898184e3Ssthen    my $Q = ꑭʑ->ニュー();
77898184e3Ssthen    undef %ꑭʑ::;
78898184e3Ssthen    eval { $a = *ꑭʑ::ニュー{PACKAGE}; };
79898184e3Ssthen    is $a, "__ANON__", "comp/stash.t test 9";
80898184e3Ssthen
81898184e3Ssthen    {
82898184e3Ssthen        local $@;
83898184e3Ssthen        eval { $Q->param; };
84898184e3Ssthen        like $@, qr/^Can't use anonymous symbol table for method lookup/, "comp/stash.t test 10";
85898184e3Ssthen    }
86898184e3Ssthen
87898184e3Ssthen    like "$Q", qr/^__ANON__=/, "comp/stash.t test 11";
88898184e3Ssthen
89898184e3Ssthen    is ref $Q, "__ANON__", "comp/stash.t test 12";
90898184e3Ssthen
91898184e3Ssthen    package bugⅲⅱⅴⅵⅱ { #not really latin, but bear with me, I'm not Damian.
92898184e3Ssthen        ::is( __PACKAGE__,   'bugⅲⅱⅴⅵⅱ', "comp/stash.t test 13");
93898184e3Ssthen        ::is( eval('__PACKAGE__'), 'bugⅲⅱⅴⅵⅱ', "comp/stash.t test 14");
94898184e3Ssthen    }
95898184e3Ssthen}
96898184e3Ssthen
97898184e3Ssthen#This comes from comp/package_block.t
98898184e3Ssthen{
99898184e3Ssthen    local $@;
100898184e3Ssthen    eval q[package ᕘ {];
101898184e3Ssthen    like $@, qr/\AMissing right curly /, "comp/package_block.t test";
102898184e3Ssthen}
103898184e3Ssthen
104898184e3Ssthen# perl #105922
105898184e3Ssthen
106898184e3Ssthen{
107898184e3Ssthen   my $latin_1 = "þackage";
108898184e3Ssthen   my $utf8    = "þackage";
109898184e3Ssthen   utf8::downgrade($latin_1);
110898184e3Ssthen   utf8::upgrade($utf8);
111898184e3Ssthen
112898184e3Ssthen   local $@;
113898184e3Ssthen   eval { $latin_1->can("yadda") };
114898184e3Ssthen   ok(!$@, "latin1->meth works");
115898184e3Ssthen
116898184e3Ssthen   local $@;
117898184e3Ssthen   eval { $utf8->can("yadda") };
118898184e3Ssthen   ok(!$@, "utf8->meth works");
119898184e3Ssthen}
120