File: 01struct.t

package info (click to toggle)
libobject-pad-classattr-struct-perl 0.06-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136 kB
  • sloc: perl: 110; makefile: 7; sh: 1
file content (35 lines) | stat: -rw-r--r-- 810 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use Object::Pad;
use Object::Pad::ClassAttr::Struct;

class Example :Struct {
   field $x;
   field $y;
   field $z = undef;
}

{
   my $obj = Example->new( x => "the x", y => "the y" );
   is( $obj->x, "the x", 'obj has ->x from constructor' );
   is( $obj->y, "the y", 'obj has ->y from constructor' );

   $obj->z = "the z";
   is( $obj->z, "the z", 'obj has ->z from mutator' );
}

{
   ok( !defined eval { Example->new( x => 0, y => 0, w => "no" ) },
      'Example constructor does not like w param' );
   my $e = $@;
   # Recent versions of Object::Pad added quotes around the argument names
   like( $e, qr/^Unrecognised parameters for Example constructor: '?w'? /,
      'exception from Example constructor param failure' );
}

done_testing;