Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Last active November 2, 2021 15:49
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 j1n3l0/1d794d8f8415f3f04d76d633234b722e to your computer and use it in GitHub Desktop.
Save j1n3l0/1d794d8f8415f3f04d76d633234b722e to your computer and use it in GitHub Desktop.
Use check_set to check a value is as expected and its type is also as expected
BEGIN {
package MyTypes;
use Type::Library -extends => ['Types::Standard'], -declare => qw< Error >;
use Type::Utils -all;
declare Error, as Dict [ error => Str ];
__PACKAGE__->meta->make_immutable();
}
use Test2::V0;
use Test::TypeTiny;
use MyTypes -types;
is( { error => 'some error' },
check_set(
{ error => 'some error' }, # check against an exact value
hash { field error => 'some error'; etc() }, # check against a hash builder
validator( sub { Error->check($_) } ), # check against predefined type
),
'should pass all expectations',
);
done_testing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment