Help language development. Donate to The Perl Foundation

LIVR cpan:KOORCHIK last updated on 2017-12-17

t/00-simple.t
use lib 'lib';

use Test;
use LIVR;

subtest 'POSITIVE: required' => {
    my $validator = LIVR::Validator.new( livr-rules => {
        name  => ['required'],
        email => { 'required' => [] }
    });

    my $validated = $validator.validate({
        name      => 'koorchik',
        email     => '[email protected]',
        somefield => 'This field has no validation'
    });

    ok $validated, 'Should return true on success validation';
    is-deeply $validated, {name => 'koorchik', email => '[email protected]'}, 'should return cleaned object';
};

subtest 'NEGATIVE: required' => {
    my $validator = LIVR::Validator.new(livr-rules => {
        name  => ['required'],
        email => { 'required' => [] }
    });

    my $validated = $validator.validate({
        name => ''
    });

    ok !$validated, 'Should return false on failed validation';
    is $validator.errors<name>, 'REQUIRED', '"name" should has error REQUIRED';
    is $validator.errors<email>, 'REQUIRED', '"email" should has error REQUIRED';
};

done-testing;