File: 98-02-document-synopsis-adhoc.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 (55 lines) | stat: -rw-r--r-- 1,387 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
use utf8;
use strict;
use warnings;
use Test::More;

package T;

use Validation::Class;

package main;

my $data = {
    "id"      => "1234-ABC",
    "name"    => "Anita Campbell-Green",
    "title"   => "Designer",
    "company" => {
        "name"       => "House of de Vil",
        "supervisor" => {
            "name"   => "Cruella de Vil",
            "rating" => [
                {   "support"  => -9,
                    "guidance" => -9
                }
            ]
        },
        "tags" => [
            "evil",
            "cruelty",
            "dogs"
        ]
    },
};

my $schema = {
    'id'                        => { mixin => [':num'], max_length => 4 },
    'name'                      => { mixin => [':str'], min_length => 2 },
    'title'                     => { mixin => [':str'], min_length => 5 },
    'company.name'              => { mixin => [':str'], min_length => 2 },
    'company.tags.@'            => { mixin => [':str'], min_length => 2 },
    'company.super*.name'       => { mixin => [':str'], min_length => 2 },
    'company.super*.rating.@.*' => { mixin => [':str'], },
};

my $class;

eval { $class = T->new };

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

can_ok $class, 'validate_document';

ok $class->validate_document($schema => $data), "T (ad-hoc data) validated";
ok $data->{id} !~ /\D/, "document ID has been filtered";

done_testing;