File: 05-method-syntax.t

package info (click to toggle)
libvalidation-class-perl 7.900057-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,616 kB
  • sloc: perl: 21,493; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,518 bytes parent folder | download | duplicates (5)
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
54
55
56
57
58
59
60
61
62
63
64
use FindBin;
use Test::More;

use utf8;
use strict;
use warnings;

{

    package TestClass::MethodCalling;
    use Validation::Class;

    field constraint => {required => 1};

    method check_a => {input => ['constraint']};
    sub _check_a {'check_a OK'}

    method a_check => {input => ['constraint']};
    sub _process_a_check {'check_a OK'}

    package main;

    my $class = "TestClass::MethodCalling";
    my $self  = $class->new;

    ok $class eq ref $self, "$class instantiated";

    $self->constraint('h@ck');

    ok 'check_a OK' eq $self->check_a,
      "$class check_a method spec'd and validated";

    for (1..5) {
        ok 'check_a OK' eq $self->a_check,
          "$_: $class a_check method spec'd and validated";
        ok 1 == $self->validate_method('a_check'),
          "$_: $class a_check method validated but NOT executed";
        ok 'check_a OK' eq $self->a_check,
          "$_: $class a_check method spec'd and validated (again)";
    }

    $self->constraint(undef);

    ok !defined  $self->a_check,
      "$class a_check method failed to validate";
    
    $self->constraint('stuff');

    ok 'check_a OK' eq $self->a_check,
        "$class a_check method spec'd and validated";

    $self->constraint(undef);

    ok 0 == $self->validate_method('a_check'),
      "$class a_check method does NOT validate and is NOT executed";

    $self->constraint('stuff');

    ok 'check_a OK' eq $self->a_check,
      "$class a_check method spec'd and validated (again)";

}

done_testing;