xref: /openbsd-src/gnu/usr.bin/perl/t/class/utf8.t (revision 5486feefcc8cb79b19e014ab332cc5dfd05b3b33)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require './test.pl';
6    set_up_inc('../lib');
7    require Config;
8}
9
10use v5.36;
11use utf8;
12use feature 'class';
13no warnings 'experimental::class';
14
15# A bunch of test cases with non-ASCII, non-Latin1. Esperanto is good for that
16# as the accented characters are not in Latin1.
17
18STDOUT->binmode( ":encoding(UTF-8)" );
19
20my $manĝis;
21
22class Sandviĉon {
23   method manĝu { $manĝis++ }
24
25   field $tranĉaĵoj :param :reader = undef;
26}
27
28# class name
29{
30   my $s = Sandviĉon->new;
31   isa_ok( $s, "Sandviĉon", '$s' );
32}
33
34# methods
35{
36   my $s = Sandviĉon->new;
37   $s->manĝu;
38   ok( $manĝis, 'UTF-8 method name works' );
39}
40
41# field params + accessors default names
42{
43   my $s = Sandviĉon->new( tranĉaĵoj => 3 );
44   is( $s->tranĉaĵoj, 3, 'Can obtain value from field via accessor' );
45}
46
47class Sandwich {
48   field $slices :param(tranĉaĵoj) :reader(tranĉaĵoj) = undef;
49}
50
51{
52   my $s = Sandwich->new( tranĉaĵoj => 5 );
53   is( $s->tranĉaĵoj, 5, 'Can obtain value from field via accessor with overridden name' );
54}
55
56done_testing;
57