Skip to content

Instantly share code, notes, and snippets.

@kfly8
Created June 7, 2018 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfly8/0cca4c6f145fd58ee50467a0643fa497 to your computer and use it in GitHub Desktop.
Save kfly8/0cca4c6f145fd58ee50467a0643fa497 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use utf8;
use Data::Validator;
use Types::Standard qw(Int);
use DDP;
sub strict_seq {
my $rule = Data::Validator->new(
key1 => Int,
key2 => Int,
)->with(qw/StrictSequenced/);
my $args = $rule->validate(@_);
}
sub smart_seq {
my $rule = Data::Validator->new(
key1 => Int,
key2 => Int,
)->with(qw/SmartSequenced/);
my $args = $rule->validate(@_);
}
sub seq {
my $rule = Data::Validator->new(
key1 => Int,
key2 => Int,
)->with(qw/Sequenced/);
my $args = $rule->validate(@_);
}
use Test::More;
use Test::Exception;
subtest 'strict sequenced' => sub {
lives_ok { strict_seq(1, 2) };
dies_ok { strict_seq(1, key2 => 2) };
dies_ok { strict_seq(1, {key2 => 2}) };
dies_ok { strict_seq(key1 => 1, 2) };
dies_ok { strict_seq(key1 => 1, key2 => 2) };
};
subtest 'smart sequenced' => sub {
lives_ok { smart_seq(1, 2) };
dies_ok { smart_seq(1, key2 => 2) };
lives_ok { smart_seq(1, {key2 => 2}) };
dies_ok { smart_seq(key1 => 1, 2) };
dies_ok { smart_seq(key1 => 1, key2 => 2) };
};
subtest 'sequenced' => sub {
lives_ok { seq(1, 2) };
dies_ok { seq(1, key2 => 2) };
lives_ok { seq(1, {key2 => 2}) };
dies_ok { seq(key1 => 1, 2) };
dies_ok { seq(key1 => 1, key2 => 2) };
};
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment