Skip to content

Commit

Permalink
Add some unit tests of __CLASS__ during field initialisers
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Aug 2, 2023
1 parent c4db344 commit 3c6718c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions t/class/field.t
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,15 @@ no warnings 'experimental::class';
'Values for goto inside do {} blocks in field initialisers'));
}

# field initialiser expressions permit a __CLASS__
{
class Test14 {
field $classname = __CLASS__;

method classname { return $classname }
}

is(Test14->new->classname, "Test14", '__CLASS__ in field initialisers');
}

done_testing;
11 changes: 11 additions & 0 deletions t/class/inherit.t
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,15 @@ no warnings 'experimental::class';
ok($obj isa Test4A, 'Unit class syntax allows :isa');
}

{
class Test5A {
field $classname = __CLASS__;
method classname { return $classname }
}

class Test5B :isa(Test5A) { }

is(Test5B->new->classname, "Test5B", '__CLASS__ yields correct class name for subclass');
}

done_testing;

0 comments on commit 3c6718c

Please sign in to comment.