Skip to content

Commit

Permalink
Streamline test generation / running of sprintf("s")
Browse files Browse the repository at this point in the history
To allow for easier addition of additional tests that may not actually
fit in the current construction.  Also generate the "#" cases, as they are
identical to the non-"#" cases.
  • Loading branch information
lizmat committed Apr 18, 2019
1 parent c690803 commit 2939371
Showing 1 changed file with 14 additions and 89 deletions.
103 changes: 14 additions & 89 deletions S32-str/sprintf-s.t
Expand Up @@ -30,22 +30,6 @@ my @info = ( # |-----------|-----------|--------------|
'-+0', '', "", "Foo", "🦋🦋🦋",
'-0 ', '', "", "Foo", "🦋🦋🦋",
'-+0 ', '', "", "Foo", "🦋🦋🦋",
'#', '', "", "Foo", "🦋🦋🦋",
'# ', '', "", "Foo", "🦋🦋🦋",
'#0', '', "", "Foo", "🦋🦋🦋",
'#0 ', '', "", "Foo", "🦋🦋🦋",
'#+', '', "", "Foo", "🦋🦋🦋",
'#+ ', '', "", "Foo", "🦋🦋🦋",
'#+0', '', "", "Foo", "🦋🦋🦋",
'#+0 ', '', "", "Foo", "🦋🦋🦋",
'#-', '', "", "Foo", "🦋🦋🦋",
'#-+', '', "", "Foo", "🦋🦋🦋",
'#- ', '', "", "Foo", "🦋🦋🦋",
'#-+ ', '', "", "Foo", "🦋🦋🦋",
'#-0', '', "", "Foo", "🦋🦋🦋",
'#-+0', '', "", "Foo", "🦋🦋🦋",
'#-0 ', '', "", "Foo", "🦋🦋🦋",
'#-+0 ', '', "", "Foo", "🦋🦋🦋",

# no size, precision 0
'', '.0', "", "", "",
Expand All @@ -64,22 +48,6 @@ my @info = ( # |-----------|-----------|--------------|
'-+0', '.0', "", "", "",
'-0 ', '.0', "", "", "",
'-+0 ', '.0', "", "", "",
'#', '.0', "", "", "",
'# ', '.0', "", "", "",
'#0', '.0', "", "", "",
'#0 ', '.0', "", "", "",
'#+', '.0', "", "", "",
'#+ ', '.0', "", "", "",
'#+0', '.0', "", "", "",
'#+0 ', '.0', "", "", "",
'#-', '.0', "", "", "",
'#-+', '.0', "", "", "",
'#- ', '.0', "", "", "",
'#-+ ', '.0', "", "", "",
'#-0', '.0', "", "", "",
'#-+0', '.0', "", "", "",
'#-0 ', '.0', "", "", "",
'#-+0 ', '.0', "", "", "",

# 2 positions, usually doesn't fit
'', 2, " ", "Foo", "🦋🦋🦋",
Expand All @@ -98,22 +66,6 @@ my @info = ( # |-----------|-----------|--------------|
'-+0', 2, " ", "Foo", "🦋🦋🦋",
'-0 ', 2, " ", "Foo", "🦋🦋🦋",
'-+0 ', 2, " ", "Foo", "🦋🦋🦋",
'#', 2, " ", "Foo", "🦋🦋🦋",
'# ', 2, " ", "Foo", "🦋🦋🦋",
'#0', 2, "00", "Foo", "🦋🦋🦋",
'#0 ', 2, "00", "Foo", "🦋🦋🦋",
'#+', 2, " ", "Foo", "🦋🦋🦋",
'#+ ', 2, " ", "Foo", "🦋🦋🦋",
'#+0', 2, "00", "Foo", "🦋🦋🦋",
'#+0 ', 2, "00", "Foo", "🦋🦋🦋",
'#-', 2, " ", "Foo", "🦋🦋🦋",
'#-+', 2, " ", "Foo", "🦋🦋🦋",
'#- ', 2, " ", "Foo", "🦋🦋🦋",
'#-+ ', 2, " ", "Foo", "🦋🦋🦋",
'#-0', 2, " ", "Foo", "🦋🦋🦋",
'#-+0', 2, " ", "Foo", "🦋🦋🦋",
'#-0 ', 2, " ", "Foo", "🦋🦋🦋",
'#-+0 ', 2, " ", "Foo", "🦋🦋🦋",

# 8 positions, should always fit
'', 8, " ", " Foo", " 🦋🦋🦋",
Expand All @@ -132,21 +84,6 @@ my @info = ( # |-----------|-----------|--------------|
'-+0', 8, " ", "Foo ", "🦋🦋🦋 ",
'-0 ', 8, " ", "Foo ", "🦋🦋🦋 ",
'-+0 ', 8, " ", "Foo ", "🦋🦋🦋 ",
'#', 8, " ", " Foo", " 🦋🦋🦋",
'#0', 8, "00000000", "00000Foo", "00000🦋🦋🦋",
'#0 ', 8, "00000000", "00000Foo", "00000🦋🦋🦋",
'#+', 8, " ", " Foo", " 🦋🦋🦋",
'#+ ', 8, " ", " Foo", " 🦋🦋🦋",
'#+0', 8, "00000000", "00000Foo", "00000🦋🦋🦋",
'#+0 ', 8, "00000000", "00000Foo", "00000🦋🦋🦋",
'#-', 8, " ", "Foo ", "🦋🦋🦋 ",
'#-+', 8, " ", "Foo ", "🦋🦋🦋 ",
'#- ', 8, " ", "Foo ", "🦋🦋🦋 ",
'#-+ ', 8, " ", "Foo ", "🦋🦋🦋 ",
'#-0', 8, " ", "Foo ", "🦋🦋🦋 ",
'#-+0', 8, " ", "Foo ", "🦋🦋🦋 ",
'#-0 ', 8, " ", "Foo ", "🦋🦋🦋 ",
'#-+0 ', 8, " ", "Foo ", "🦋🦋🦋 ",

# 8 positions with precision, precision fits sometimes
'', 8.2, " ", " Fo", " 🦋🦋",
Expand All @@ -165,41 +102,29 @@ my @info = ( # |-----------|-----------|--------------|
'-+0', 8.2, " ", "Fo ", "🦋🦋 ",
'-0 ', 8.2, " ", "Fo ", "🦋🦋 ",
'-+0 ', 8.2, " ", "Fo ", "🦋🦋 ",
'#', 8.2, " ", " Fo", " 🦋🦋",
'#0', 8.2, " ", " Fo", " 🦋🦋",
'#0 ', 8.2, " ", " Fo", " 🦋🦋",
'#+', 8.2, " ", " Fo", " 🦋🦋",
'#+ ', 8.2, " ", " Fo", " 🦋🦋",
'#+0', 8.2, " ", " Fo", " 🦋🦋",
'#+0 ', 8.2, " ", " Fo", " 🦋🦋",
'#-', 8.2, " ", "Fo ", "🦋🦋 ",
'#-+', 8.2, " ", "Fo ", "🦋🦋 ",
'#- ', 8.2, " ", "Fo ", "🦋🦋 ",
'#-+ ', 8.2, " ", "Fo ", "🦋🦋 ",
'#-0', 8.2, " ", "Fo ", "🦋🦋 ",
'#-+0', 8.2, " ", "Fo ", "🦋🦋 ",
'#-0 ', 8.2, " ", "Fo ", "🦋🦋 ",
'#-+0 ', 8.2, " ", "Fo ", "🦋🦋 ",

).map: -> $flags, $size, $r0, $r1, $r4 {
my @flat;
@flat.append('%' ~ $_ ~ $size ~ 's', $r0, $r1, $r4)
for $flags.comb.permutations>>.join;
@flat.append(
'%' ~ $_ ~ $size ~ 's',
($r0 => "", $r1 => "Foo", $r4 => "🦋🦋🦋")
) for $flags.comb.permutations>>.join;
@flat.append(
'%' ~ $_ ~ $size ~ 's',
($r0 => "", $r1 => "Foo", $r4 => "🦋🦋🦋")
) for "#$flags".comb.permutations>>.join;
|@flat
}

plan @info/4;
plan @info/2;

for @info -> $format, $r0, $r1, $r4 {
for @info -> $format, @tests {
subtest {
plan 3;
plan +@tests;

is sprintf($format, $v0), $r0,
"sprintf('$format',$v0) eq '$r0'";
is sprintf($format, $v1), $r1,
"sprintf('$format',$v1) eq '$r1'";
is sprintf($format, $v4), $r4,
"sprintf('$format',$v4) eq '$r4'";
is sprintf($format, .value), .key,
"sprintf('$format',{.value}) eq '{.key}'"
for @tests;
}, "Tested '$format'";
}

Expand Down

0 comments on commit 2939371

Please sign in to comment.