Skip to content

Commit

Permalink
gh19010: simplify and expand inf/nan tests
Browse files Browse the repository at this point in the history
We know how grok results should vary with and without PERL_SCAN_TRAILING
both for inputs with trailing garbage and those without, so abstract
that out and test both cases for each input.
  • Loading branch information
hvds committed Feb 26, 2022
1 parent c5a8cf5 commit 294a724
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions ext/XS-APItest/t/grok.t
Expand Up @@ -68,36 +68,42 @@ foreach my $leader ('', ' ', ' ') {
}

# format tests
my @groks =
(
# input, in flags, out uv, out flags
[ "1", 0, 1, IS_NUMBER_IN_UV ],
[ "1x", 0, undef, 0 ],
[ "1x", PERL_SCAN_TRAILING, 1, IS_NUMBER_IN_UV | IS_NUMBER_TRAILING ],
[ "3.1", 0, 3, IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT ],
[ "3.1a", 0, undef, 0 ],
[ "3.1a", PERL_SCAN_TRAILING, 3,
IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT | IS_NUMBER_TRAILING ],
[ "3e5", 0, undef, IS_NUMBER_NOT_INT ],
[ "3e", 0, undef, 0 ],
[ "3e", PERL_SCAN_TRAILING, 3, IS_NUMBER_IN_UV | IS_NUMBER_TRAILING ],
[ "3e+", 0, undef, 0 ],
[ "3e+", PERL_SCAN_TRAILING, 3, IS_NUMBER_IN_UV | IS_NUMBER_TRAILING ],
[ "Inf", 0, undef,
IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT ],
[ "In", 0, undef, 0 ],
[ "Infin",0, undef, 0 ],
[ "Infin",PERL_SCAN_TRAILING, undef,
IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT | IS_NUMBER_TRAILING ],
[ "nan", 0, undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
# even without PERL_SCAN_TRAILING nan can have specific weird stuff trailing
[ "nanq", 0, undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
[ "nan(123)", 0, undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
# but not just anything
[ "nanx", 0, undef, 0 ],
[ "nanx", PERL_SCAN_TRAILING, undef,
IS_NUMBER_NAN | IS_NUMBER_NOT_INT | IS_NUMBER_TRAILING ],
);
my @groks = (
# input, in flags, out uv, out flags
(map {
# Expect the same answer with or without SCAN_TRAILING
[ $_->[0], 0, $_->[1], $_->[2] ],
[ $_->[0], PERL_SCAN_TRAILING, $_->[1], $_->[2] ],
} (
[ "1", 1, IS_NUMBER_IN_UV ],
[ "3.1", 3, IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT ],
[ "3e5", undef, IS_NUMBER_NOT_INT ],
[ "Inf", undef, IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT ],
[ "nan", undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
[ "nanq", undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
[ "nan(123)", undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
# trailing whitespace is ok though
[ "1 ", 1, IS_NUMBER_IN_UV ],
[ "nan(123 ) ", undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
)),
(map {
# Trailing stuff should cause failure unless SCAN_TRAILING
[ $_->[0], 0, undef, 0 ],
[ $_->[0], PERL_SCAN_TRAILING, $_->[1], $_->[2] | IS_NUMBER_TRAILING ],
} (
[ "1x", 1, IS_NUMBER_IN_UV ],
[ "3.1a", 3, IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT ],
[ "3e", 3, IS_NUMBER_IN_UV ],
[ "3e+", 3, IS_NUMBER_IN_UV ],
[ "Infin", undef, IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT ],
[ "nanx", undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
[ "nan(123 x)", undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
[ "nan(123) x", undef, IS_NUMBER_NAN | IS_NUMBER_NOT_INT ],
# TODO: this should probably be in the preceding section, parsed
# as invalid with or without SCAN_TRAILING. See GH #19464.
[ "In", undef, 0 ],
)),
);

my $non_ieee_fp = ($Config{doublekind} == 9 ||
$Config{doublekind} == 10 ||
Expand Down

0 comments on commit 294a724

Please sign in to comment.