File: 35my-class.t

package info (click to toggle)
libobject-pad-perl 0.823-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 944 kB
  • sloc: ansic: 3,404; perl: 3,372; pascal: 28; makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use v5.18;
use warnings;

use Test2::V0;

use Object::Pad 0.800 ':experimental(lexical_class)';

{
   my class Point {
      field $x :param :reader;
      field $y :param :reader;

      method m
      {
         # Attempt to trigger RT168139
         my $ten = 10;
         return $ten;
      }
   }

   my $p = Point->new( x => 20, y => 40 );
   ok( defined $p, 'Lexical class Point can ->new' );
   is( $p->x, 20, 'Lexical class instances have methods' );
   is( $p->m, 10, 'Lexical class methods work properly' );

   ok( !defined &Point::new, 'Point:: is not a package in the symbol table' );

   ok( $p->isa( Point ), '->isa method works with lexical name as bareword' );

   if( $^V ge v5.32 ) {
      eval <<'EOPERL' or die $@;
         use feature 'isa';
         ok( $p isa Point, 'isa operator works with lexical class' );
         1;
EOPERL
   }
}

{
   # A second lexical class of the same lexical name in its own scope should
   # be distinct
   my class Point {
      field $z :param :reader;
   }

   my $p = Point->new( z => 60 );
   is( $p->z, 60, 'Second lexical class of the same name in its own scope works' );
   ok( !$p->can( "x" ), 'Second lexical class is distinct from the first' );
}

done_testing;