File: 02new_values.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 (32 lines) | stat: -rw-r--r-- 749 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
#!/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;
}

# Check that the ->new_values method works
{
   my $obj = Example->new_values( 10, 20, 30 );
   is( $obj->x, 10, 'obj has ->x from positional constructor' );
   is( $obj->y, 20, 'obj has ->y from positional constructor' );
   is( $obj->z, 30, 'obj has ->z from positional constructor' );
}

{
   ok( !defined eval { Example->new_values( 40 ) },
      'Positional constructor fails with insufficient values' );
   like( $@, qr/^Usage: Example->new_values\(\$x, \$y, \$z\) at /,
      'Exception message from failure of positional constructor' );
}

done_testing;