summaryrefslogtreecommitdiff
path: root/ext/XS-APItest
diff options
context:
space:
mode:
authorHugo van der Sanden <hv@crypt.org>2022-02-26 14:50:23 +0000
committerKarl Williamson <khw@cpan.org>2022-03-04 10:31:41 -0700
commit46da8a0d99e5820fe6ceeeb483a44ebf547bbff0 (patch)
tree05d767ed7c2b22162c603804ca757927181167fc /ext/XS-APItest
parent6e5a616fb95344835944fb3cab56c5c69a3b9848 (diff)
downloadperl-46da8a0d99e5820fe6ceeeb483a44ebf547bbff0.tar.gz
gh19010: simplify and expand inf/nan tests
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.
Diffstat (limited to 'ext/XS-APItest')
-rw-r--r--ext/XS-APItest/t/grok.t66
1 files changed, 36 insertions, 30 deletions
diff --git a/ext/XS-APItest/t/grok.t b/ext/XS-APItest/t/grok.t
index 7347e4f1fe..617e8368da 100644
--- a/ext/XS-APItest/t/grok.t
+++ b/ext/XS-APItest/t/grok.t
@@ -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 ||