/
sprintf-c.t
78 lines (68 loc) 路 3.05 KB
/
sprintf-c.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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.
# 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", "馃",
# 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 ", "馃 ",
'#-+0 ', 3, "\0 ", "A ", "馃 ",
).map: -> $flags, $size, $r0, $rA, $rB {
my @flat;
@flat.append(
'%' ~ $_ ~ $size ~ 'c',
($r0 => 0, $rA => 65, $rB => 129419)
) for $flags.comb.permutations>>.join;
@flat.append(
'%' ~ $_ ~ $size ~ 'c',
($r0 => 0, $rA => 65, $rB => 129419)
) for "#$flags".comb.permutations>>.join;
|@flat
}
plan @info/2;
for @info -> $format, @tests {
subtest {
plan +@tests;
is-deeply sprintf($format, |.value), .key,
qq/sprintf("$format",{.value.list.join(",")}) eq '{.key}'/
for @tests;
}, "Tested '$format'";
}
# vim: ft=perl6