Skip to content

Commit

Permalink
expload the test cases for Int
Browse files Browse the repository at this point in the history
... with different kinds of ways to initialize a scalar varible with
"number" inside.
  • Loading branch information
gugod committed Sep 4, 2019
1 parent c25a065 commit d312930
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions t/101_issues/Int.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,37 @@
use strict;
use warnings;
use Test::More;
use Devel::Peek qw<Dump>;
use Mouse::Util::TypeConstraints;

my $Int = find_type_constraint 'Int';

my $num = 3.14;
subtest "Non-Int from numerical literal: my \$num = 3.14", sub {
my $num = 3.14;
ok !$Int->check($num), "\$num is not Int";
{ no warnings; int($num) };
ok !$Int->check($num), "\$num is still not Int";
};

ok !$Int->check($num), "\$num (== 3.14) is not Int";
subtest "Non-Int from string literal: my \$num = \"3.14\"", sub {
my $num = "3.14";
ok !$Int->check($num), "\$num is not Int";
{ no warnings; int($num) };
ok !$Int->check($num), "\$num is still not Int";
};

{ no warnings; int($num) };
subtest "Int from string literal: my \$num = \"3\"", sub {
my $num = "3";
ok $Int->check($num), "\$num is Int";
{ no warnings; int($num) };
ok $Int->check($num), "\$num is still Int";
};

ok !$Int->check($num), "\$num (== 3.14) is still not Int";
subtest "Int from integer literal: my \$num = 3", sub {
my $num = 3;
ok $Int->check($num), "\$num is Int";
{ no warnings; int($num) };
ok $Int->check($num), "\$num is still Int";
};

done_testing;

0 comments on commit d312930

Please sign in to comment.