Blame t/self-check.t

Packit 29583e
## no critic (Moose::RequireCleanNamespace)
Packit 29583e
use strict;
Packit 29583e
use warnings;
Packit 29583e
Packit 29583e
use Test2::V0;
Packit 29583e
use Test2::Plugin::NoWarnings;
Packit 29583e
Packit 29583e
use Params::ValidationCompiler qw( validation_for );
Packit 29583e
use Specio::Library::Builtins;
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies { validation_for() },
Packit 29583e
    qr/\QYou must provide a "params" parameter when creating a parameter validator\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called without parameters'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies { validation_for( params => 42 ) },
Packit 29583e
    qr/\QThe "params" parameter when creating a parameter validator must be a hashref or arrayref, you passed a scalar\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called with params as a scalar'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies { validation_for( params => undef ) },
Packit 29583e
    qr/\QThe "params" parameter when creating a parameter validator must be a hashref or arrayref, you passed an undef\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called params as an undef'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies { validation_for( params => \42 ) },
Packit 29583e
    qr/\QThe "params" parameter when creating a parameter validator must be a hashref or arrayref, you passed a scalarref\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called params as a scalarref'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies { validation_for( params => { a => {} }, foo => 1, bar => 2 ) },
Packit 29583e
    qr/\QYou passed unknown parameters when creating a parameter validator: [bar foo]\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called with extra unknown parameters'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies { validation_for( params => { a => {} }, name => undef, ) },
Packit 29583e
    qr/\QThe "name" parameter when creating a parameter validator must be a scalar, you passed an undef\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called with name as an undef'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies { validation_for( params => { a => {} }, name => [], ) },
Packit 29583e
    qr/\QThe "name" parameter when creating a parameter validator must be a scalar, you passed a arrayref\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called with name as an arrayref'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies {
Packit 29583e
        validation_for(
Packit 29583e
            params        => [ a => 1 ],
Packit 29583e
            named_to_list => 1,
Packit 29583e
            slurpy        => 1,
Packit 29583e
        );
Packit 29583e
    },
Packit 29583e
    qr/\QYou cannot use "named_to_list" and "slurpy" together\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called with named_to_list and slurpy'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies {
Packit 29583e
        validation_for(
Packit 29583e
            params        => [ a => { isa => 1, typo => 2 } ],
Packit 29583e
            named_to_list => 1,
Packit 29583e
        );
Packit 29583e
    },
Packit 29583e
    qr/\QSpecification contains unknown keys: [isa typo]\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called with named_to_list and an invalid spec keys'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies {
Packit 29583e
        validation_for(
Packit 29583e
            params => [ { isa => 1, } ],
Packit 29583e
        );
Packit 29583e
    },
Packit 29583e
    qr/\QSpecification contains unknown keys: [isa]\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called with an arrayref params and an invalid spec keys'
Packit 29583e
);
Packit 29583e
Packit 29583e
like(
Packit 29583e
    dies {
Packit 29583e
        validation_for(
Packit 29583e
            params => { a => { isa => 1, typo => 2 } },
Packit 29583e
        );
Packit 29583e
    },
Packit 29583e
    qr/\QSpecification contains unknown keys: [isa typo]\E.+at t.self-check\.t line \d+/,
Packit 29583e
    'got expected error message when validation_for is called with an hashref params and an invalid spec keys'
Packit 29583e
);
Packit 29583e
like(
Packit 29583e
    dies {
Packit 29583e
        validation_for(
Packit 29583e
            params => { foo => t('Int') },
Packit 29583e
        );
Packit 29583e
    },
Packit 29583e
    qr/\QSpecifications must be a scalar or hashref, but received a Specio::Constraint::Simple/,
Packit 29583e
    'got expected error message when validation_for is called with a spec that is a type instead of a hashref'
Packit 29583e
);
Packit 29583e
Packit 29583e
done_testing();