Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge cases of weird-looking interger-ish strings. #104

Open
gugod opened this issue Sep 5, 2019 · 0 comments
Open

Edge cases of weird-looking interger-ish strings. #104

gugod opened this issue Sep 5, 2019 · 0 comments

Comments

@gugod
Copy link

gugod commented Sep 5, 2019

This is related to #103, but a bit more cases. Considering the following test program, running with perl 5.28.1, Mouse v2.5.9. The test program take each strings from @ARGV as $x, and "wash" it with "int($x)" -- which leaves some side-effect inside $x. Then see if it passes Int type constraint.

# x.pl
use v5.18;
use warnings;
use Mouse::Util::TypeConstraints;

my $Int = find_type_constraint 'Int';

for my $x (@ARGV) {
    { no warnings; int($x); };

    if ($Int->check($x)) {
        say " Int\t$x";
    } else {
        say "!Int\t$x";
    }
}

Here's the output when using Mouse::XS

> perl x.pl 1 '-1' '-0' ' 1 ' '  -1 ' 0 00 010 18446744073709551615 1.0 0.1 1.2.3 0.0 0.1.0 0b00 0e 0e0 0e1 1e0 '0 but true' '1 foobar'

 Int	1
 Int	-1
 Int	-0
 Int	 1
 Int	  -1
 Int	0
 Int	00
 Int	010
 Int	18446744073709551615
!Int	1.0
!Int	0.1
!Int	1.2.3
!Int	0.0
!Int	0.1.0
!Int	0b00
!Int	0e
!Int	0e0
!Int	0e1
!Int	1e0
 Int	0 but true
!Int	1 foobar

The output when using Mouse::PurePerl

> MOUSE_PUREPERL=1 perl x.pl 1 '-1' '-0' ' 1 ' '  -1 ' 0 00 010 18446744073709551615 1.0 0.1 1.2.3 0.0 0.1.0 0b00 0e 0e0 0e1 1e0 '0 but true' '1 foobar'

 Int	1
 Int	-1
 Int	-0
!Int	 1
!Int	  -1
 Int	0
 Int	00
 Int	010
 Int	18446744073709551615
!Int	1.0
!Int	0.1
!Int	1.2.3
!Int	0.0
!Int	0.1.0
!Int	0b00
!Int	0e
!Int	0e0
!Int	0e1
!Int	1e0
!Int	0 but true
!Int	1 foobar

Trivial values are consistent, values with leading/trailing spaces and a special value "0 but true" are controversial.

IMHO, the result from Mouse::PurePerl looks intuitively correct and we should change Mouse::XS to match that result -- but I also pondering the counter-argument here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant