Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parameterize sprintf testing of "c" format
Mostly intended to register the behaviour of the current sprintf implementation, which was not testing some combinations of flags and was not testing for special behaviours to unicode characters like 🦋
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use v6; | ||
|
||
#BEGIN %*ENV<PERL6_TEST_DIE_ON_FAIL> = True; | ||
use Test; | ||
|
||
# Test combinations of flags for "%c". The @info array is intialized with the | ||
# flags (as a string), the size/precision specification (either a string or a | ||
# number), and the expected strings for the values 0, 65 and 129419. The flags | ||
# values will be expanded to all possible permutations to ensure that the | ||
# order of the flags is irrelevant. Each flag permutation is combined with | ||
# the size/permutation value to create a proper format string. | ||
|
||
my ($v0, $vA, $vB) = | ||
0 , 65 , 129419 ; | ||
my @info = ( # |-----------|-----------|-----------| | ||
# no size or size explicitely 0 | ||
'', '', "\0", "A", "🦋", | ||
' ', '', "\0", "A", "🦋", | ||
'0', '', "\0", "A", "🦋", | ||
'0 ', '', "\0", "A", "🦋", | ||
'+', '', "\0", "A", "🦋", | ||
'+ ', '', "\0", "A", "🦋", | ||
'+0', '', "\0", "A", "🦋", | ||
'+0 ', '', "\0", "A", "🦋", | ||
'-', '', "\0", "A", "🦋", | ||
'-+', '', "\0", "A", "🦋", | ||
'- ', '', "\0", "A", "🦋", | ||
'-+ ', '', "\0", "A", "🦋", | ||
'-0', '', "\0", "A", "🦋", | ||
'-+0', '', "\0", "A", "🦋", | ||
'-0 ', '', "\0", "A", "🦋", | ||
'-+0 ', '', "\0", "A", "🦋", | ||
'#', '', "\0", "A", "🦋", | ||
'# ', '', "\0", "A", "🦋", | ||
'#0', '', "\0", "A", "🦋", | ||
'#0 ', '', "\0", "A", "🦋", | ||
'#+', '', "\0", "A", "🦋", | ||
'#+ ', '', "\0", "A", "🦋", | ||
'#+0', '', "\0", "A", "🦋", | ||
'#+0 ', '', "\0", "A", "🦋", | ||
'#-', '', "\0", "A", "🦋", | ||
'#-+', '', "\0", "A", "🦋", | ||
'#- ', '', "\0", "A", "🦋", | ||
'#-+ ', '', "\0", "A", "🦋", | ||
'#-0', '', "\0", "A", "🦋", | ||
'#-+0', '', "\0", "A", "🦋", | ||
'#-0 ', '', "\0", "A", "🦋", | ||
'#-+0 ', '', "\0", "A", "🦋", | ||
|
||
# size that fits | ||
'', 3, " \0", " A", " 🦋", | ||
' ', 3, " \0", " A", " 🦋", | ||
'0', 3, "00\0", "00A", "00🦋", | ||
'0 ', 3, "00\0", "00A", "00🦋", | ||
'+', 3, " \0", " A", " 🦋", | ||
'+ ', 3, " \0", " A", " 🦋", | ||
'+0', 3, "00\0", "00A", "00🦋", | ||
'+0 ', 3, "00\0", "00A", "00🦋", | ||
'-', 3, "\0 ", "A ", "🦋 ", | ||
'-+', 3, "\0 ", "A ", "🦋 ", | ||
'- ', 3, "\0 ", "A ", "🦋 ", | ||
'-+ ', 3, "\0 ", "A ", "🦋 ", | ||
'-0', 3, "\0 ", "A ", "🦋 ", | ||
'-+0', 3, "\0 ", "A ", "🦋 ", | ||
'-0 ', 3, "\0 ", "A ", "🦋 ", | ||
'-+0 ', 3, "\0 ", "A ", "🦋 ", | ||
'#', 3, " \0", " A", " 🦋", | ||
'# ', 3, " \0", " A", " 🦋", | ||
'#0', 3, "00\0", "00A", "00🦋", | ||
'#0 ', 3, "00\0", "00A", "00🦋", | ||
'#+', 3, " \0", " A", " 🦋", | ||
'#+ ', 3, " \0", " A", " 🦋", | ||
'#+0', 3, "00\0", "00A", "00🦋", | ||
'#+0 ', 3, "00\0", "00A", "00🦋", | ||
'#-', 3, "\0 ", "A ", "🦋 ", | ||
'#-+', 3, "\0 ", "A ", "🦋 ", | ||
'#- ', 3, "\0 ", "A ", "🦋 ", | ||
'#-+ ', 3, "\0 ", "A ", "🦋 ", | ||
'#-0', 3, "\0 ", "A ", "🦋 ", | ||
'#-+0', 3, "\0 ", "A ", "🦋 ", | ||
'#-0 ', 3, "\0 ", "A ", "🦋 ", | ||
'#-+0 ', 3, "\0 ", "A ", "🦋 ", | ||
|
||
).map: -> $flags, $size, $r0, $rA, $rB { | ||
my @flat; | ||
@flat.append('%' ~ $_ ~ $size ~ 'c', $r0, $rA, $rB) | ||
for $flags.comb.permutations>>.join; | ||
|@flat | ||
} | ||
|
||
plan @info/4; | ||
|
||
for @info -> $format, $r0, $rA, $rB { | ||
subtest { | ||
plan 3; | ||
|
||
is sprintf($format, $v0), $r0, | ||
"sprintf('$format',$v0) eq '$r0'"; | ||
is sprintf($format, $vA), $rA, | ||
"sprintf('$format',$vA) eq '$rA'"; | ||
is sprintf($format, $vB), $rB, | ||
"sprintf('$format',$vB) eq '$rB'"; | ||
|
||
}, "Tested '$format'"; | ||
} | ||
|
||
# vim: ft=perl6 | ||
|
||
=finish |