Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Last active July 2, 2020 13:21
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/4b9ee1635a4b32f9d37fac1cb0f34f1a to your computer and use it in GitHub Desktop.
Save j1n3l0/4b9ee1635a4b32f9d37fac1cb0f34f1a to your computer and use it in GitHub Desktop.
use Test2::V0;
use Test::LectroTest::Compat;
use Test::LectroTest::Generator qw< :all >;
sub Positive_Int {
Gen { abs Int->generate(@_) }
}
holds(
Property {
##[ a <- Positive_Int, b <- Positive_Int ]##
my $c = sub { $_[0] + $_[1] }
->( $a, $b );
( $c >= $a ) && ( $c >= $b ); # NOTE: should return a boolean
},
name => 'sum of 2 positive integers is greater than or equal to either number',
);
sub Signature {
Gen {
{ hash => String( charset => 'a-z', length => 64 )->generate(@_),
time => String( charset => '0-9', length => 13 )->generate(@_),
};
};
}
my $thing_to_test = sub {
sprintf <<'XML', $_[0]->{hash}, $_[0]->{time};
<Signature>
<Hash>%s</Hash>
<Time>%s</Time>
</Signature>
XML
};
holds(
Property {
##[ signature <- Signature ]##
my $value = $thing_to_test->($signature);
( $value =~ qr/<Hash>[a-z]{64}<\/Hash>/ )
&& ( $value =~ qr/<Time>[0-9]{13}<\/Time>/ );
},
name => '$thing_to_test generates output containing <Hash/> and <Time/> elements',
);
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment