File: 80checks%2Bfield.t

package info (click to toggle)
libdata-checks-perl 0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 328 kB
  • sloc: ansic: 1,155; perl: 823; pascal: 12; sh: 6; makefile: 3
file content (36 lines) | stat: -rw-r--r-- 1,121 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
#!/usr/bin/perl

use v5.22;
use warnings;

use Test2::V0;

BEGIN {
   plan skip_all => "Data::Checks >= 0.03 is not available"
      unless eval { require Data::Checks;
                    Data::Checks->VERSION( '0.03' ) };
   plan skip_all => "Object::Pad::FieldAttr::Checked >= 0.10 is not available"
      unless eval { require Object::Pad::FieldAttr::Checked;
                    Object::Pad::FieldAttr::Checked->VERSION( '0.10' ) };

   Data::Checks->import(qw( Defined ));
   Object::Pad::FieldAttr::Checked->import;

   diag( "Data::Checks $Data::Checks::VERSION, " .
         "Object::Pad::FieldAttr::Checked $Object::Pad::FieldAttr::Checked::VERSION" );
}

# We know this must be available since Object::Pad::FieldAttr::Checked would
# depend on it
use Object::Pad;

class TestClass {
   field $x :param :reader :Checked(Defined);
}

is( TestClass->new( x => 123 )->x, 123, 'Field $x accepts defined argument' );
ok( dies { TestClass->new( x => undef ) }, 'rejects undefined argument' );
# Don't be overly sensitive on the format of the message, in case it changes.
# It's just for human interest

done_testing;